This post was imported from FARMCode.org which has been discontinued. These posts now exist here as an archive. They may contain broken links and images.
After sorting 150 nodes manually in the Umbraco backend I thought to myself that it can’t be too hard to write some kind of automatic sorting dialog. First I thought about adding some options to the existing sort dialog, which would swirl the child nodes in the list around to the editors content, yet that seemed like too much effort to just sort the nodes, the editor would still have the option to do some manual ordering using the built-in Umbraco sort after the automatic sort. The next idea was to add another option to the context menu, then ideally open up a sub menu so you could just go ‘Auto sort –> descending’ and it would go off. Apart from the fact that it would be quite a bit of work to get that sub menu working (I recently read somewhere that it’s probably coming in version 5 Smile, looking forward already) it had a couple of additional downfalls: the sort might be triggered by accident and it would be quite difficult to get additional options in there, e.g. the field you want to sort by. That pretty much left the option to give Auto Sort it’s very own popup window.

The options I ended up with in the end are the following:

  • The field to sort the nodes by. Currently supported are
    • node name
    • id
    • creation date
    • note type alias and
    • custom fields (you have to provide the alias of your custom property);
    additionally for content nodes there are also
    • update date
    • release date
    • expiry date and
    • creator name
    to choose from. (default: node name)
  • Sort either ascending or descending (default: ascending)
  • Include grand children in the sort or not. Including grand children will sort ALL children and grand children by the field you have selected recursively. (default: exclude grand children)
  • Include all unpublished nodes in the sort, or choose to exclude them. (default: include)
  • If you exclude unpublished nodes from the sort you will need to provide the location of the unpublished nodes, either at the top of the list or at the bottom (default: top)

Once the first sort using node name was working it was a nearly a breeze to make the additional options work as well. Some issues occurred with regards to the differences between content and media nodes, but nothing that a couple of if-else statements couldn’t handle. Here are some screen shots:

 

 

The trickier bit was then to add support for multiple languages. The respective keys had to be added to the specific language xml files in /umbraco/config/lang. The Package Actions Contrib package by Richard Soeteman (essential for each Umbraco package builder) contains the fantastic AddLanguageFileKey action by Chris Houston, which would have done the deed yet would also have been a bit cumbersome since I had to add like 20 keys for each language, and also I wanted to add my own area in the language files. So I extended the custom package action to take a list of key-value-pairs and the name for a new are to create the section in the specified language file [note to self: send the code to Richard Soeteman so he can add it to the contrib package]. At the time of writing there are only 2 languages missing thanks to the community, which is absolutely awesome, I’ll include them shortly in the package. Credit goes to the following translators:

  • kows for the Dutch version
  • Patrik Wibron for the Swedish version
  • Mike for the French version
  • Morten Balle for the Dansk version
  • ricardo for Italiano and Spanish (double high five!)
  • Korean version anyone?
  • Norwegian maybe?

I hope you enjoy the package and that it makes your life even easier than developing web sites with Umbraco already is. Skål!