Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • keilo 568 posts 1023 karma points
    Aug 31, 2014 @ 16:59
    keilo
    0

    How to Auto-Sort by Article's publishDate

    I have tried to add a new dropdown field to the Auto-Sort data-type (publishDate), where publishDate being the property of the umbNewsItem (where actual publication date is captured).

    Upon publish, thought it would make more sense to use provided Article publishDate to do the sorting.

    With the added dropdown property, on publish, the following line throws error in uNewsManager.cs which i assume having issue getting the umbNewsItem non-default property value 'publishDate' via (OrderBy(x => GetPropValue) ? Is there a way to add support for non-standard node property value (i.e. publisDate) ?

    IComparable GetPropValue(object src, string propName)

            {

                return (IComparable)src.GetType().GetProperty(propName).GetValue(src, null);

            }

    errror is: 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. 

    at EventhandlingCocktail.App_Code.uNewsManager.GetPropValue(Object src, String propName) in d:\WWWroot\umbraco\App_Code\uNewsManager.cs:line 117
       at EventhandlingCocktail.App_Code.uNewsManager.<>c__DisplayClass4.<ContentService_Saved>b__1(IContent x) in d:\WWWroot\umbraco\App_Code\uNewsManager.cs:line 49
       at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
       at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
       at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
       at EventhandlingCocktail.App_Code.uNewsManager.ContentService_Saved(IContentService sender, SaveEventArgs`1 e) in d:\WWWroot\umbraco\App_Code\uNewsManager.cs:line 56
       at Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender, TEventArgs e)
       at Umbraco.Core.Services.ContentService.SaveAndPublishDo(IContent content, Int32 userId, Boolean raiseEvents)
       at Umbraco.Web.Editors.ContentController.PostSave(ContentItemSave contentItem)
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
  • Sören Deger 733 posts 2844 karma points c-trib
    Sep 01, 2014 @ 08:59
    Sören Deger
    100

    Hi Keilo,

    I have update the package to version 1.1. Now auto sort supports custom properties.

     

    Sören

  • keilo 568 posts 1023 karma points
    Sep 01, 2014 @ 09:19
    keilo
    0

    Thats great! This will make it extremely agile.

    One question Soren: if I have a newoverview (category) with hundreds of newsitem as sub-pages, if i go to newsoverview enable AutoSort and change the sort to publishDate (added to sort data-type) and select desc - after right-clicking the newsoverview (category) node and select Publish all and subpages it goes through lengthy publish but the sort order is not changed.

    Is this because Publish .. and its sub-pages within Umbraco does not fire the proper event in the code? As the number of articles are in hundreds I didnt attempt to go to each and click Save&Publish individually.

    Is there something Im missing, or interpreting the event handler wrongly?

    cheers!

  • Sören Deger 733 posts 2844 karma points c-trib
    Sep 01, 2014 @ 09:47
    Sören Deger
    1

    Hi Keilo,

    the event is not fired if you select "Publish all". But if you Save & Publish one news node, all nodes in this category are sorted automatically. You don't need save all nodes individually.

    Sören

    P.S. if the auto sort works with custom properties now, please mark my first answer above to solved ;-)

  • keilo 568 posts 1023 karma points
    Sep 01, 2014 @ 09:54
    keilo
    0

    Hi Soren

    First of all auto sort works beatifully with version 1.1. Million thanks!

    I did not pay attention to the fact that when you save "one" article under newsoverview(category) the soring algorithm kicks-in for all entries under that category.

    This is great! And definitely a big plus. 

    Now I have to figure out how to better organize the list under each category (to move them into Archive somehow) so the list does not exceed 50-100 as Save&Publish on individual page takes considerable amount of time (now I learned it does its re-calculating all nodes sort under its' category, so the speed hit comes from there).

    Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft