CoreMedia / content-sync-example

Other
2 stars 4 forks source link

Make selection tree sort folder and content items alphabetically by default #2

Open blackappsolutions opened 3 years ago

blackappsolutions commented 3 years ago

Make selection tree sort folder and content items alphabetically by default

blackappsolutions commented 3 years ago

@nchieffo has a fix for this in place and is preparing a pull request

nchieffo commented 3 years ago

I actually was able to order only the left part of the tree, not the right part, and I'm not sure I followed the correct approach (I tired to attache a Sorter to the ext.js store but I was not successful)

diff --git a/studio-client/src/main/joo/com/coremedia/blueprint/contentsync/studio/tree/ContentSyncIngestTreeModel.as b/studio-client/src/main/joo/com/coremedia/blueprint/contentsync/studio/tree/ContentSyncIngestTreeModel.as
index 754ec14..dbe976e 100644
--- a/studio-client/src/main/joo/com/coremedia/blueprint/contentsync/studio/tree/ContentSyncIngestTreeModel.as
+++ b/studio-client/src/main/joo/com/coremedia/blueprint/contentsync/studio/tree/ContentSyncIngestTreeModel.as
@@ -71,7 +71,15 @@ public class ContentSyncIngestTreeModel implements CompoundChildTreeModel, LazyL
     var iconCls:Object = {};
     var leafs:Object = {};

-    children.forEach(function (it:*):void {
+    children.sort(function(a, b) {
+      if (a.type === 'Folder' && b.type !== 'Folder') {
+        return -1;
+      } else if (a.type !== 'Folder' && b.type === 'Folder') {
+        return 1;
+      } else {
+        return a.name.toUpperCase().localeCompare(b.name.toUpperCase());
+      }
+    }).forEach(function (it:*):void {
       var typeId:String = it.id.toString();
       var typeName:String = it.name;