Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/259988

Change subject: Maintain the list order irrespective of when the list added
......................................................................

Maintain the list order irrespective of when the list added

Lists get added in random order to the suggestion list. Instead
of appending in the order it arrives, make sure they are sorted
as per the defined sorting order.

Change-Id: I601200ad22d861fcbaf78d3752f421341afbf7f0
---
M modules/dashboard/ext.cx.suggestionlist.js
1 file changed, 18 insertions(+), 16 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/88/259988/1

diff --git a/modules/dashboard/ext.cx.suggestionlist.js 
b/modules/dashboard/ext.cx.suggestionlist.js
index 090867f..25b7da6 100644
--- a/modules/dashboard/ext.cx.suggestionlist.js
+++ b/modules/dashboard/ext.cx.suggestionlist.js
@@ -18,7 +18,15 @@
                        TYPE_FAVORITE: 3,
                        TYPE_CATEGORY: 4,
                        TYPE_PERSONALIZED: 5
-               };
+               },
+               listOrder = {};
+
+       listOrder[ listTypes.TYPE_FAVORITE ] = 0;
+       listOrder[ listTypes.TYPE_DISCARDED ] = 1;
+       listOrder[ listTypes.TYPE_PERSONALIZED ] = 2;
+       listOrder[ listTypes.TYPE_CATEGORY ] = 3;
+       listOrder[ listTypes.TYPE_FEATURED ] = 4;
+       listOrder[ listTypes.TYPE_DEFAULT ] = 5;
 
        /**
         * CXSuggestionList
@@ -351,6 +359,7 @@
         */
        CXSuggestionList.prototype.insertSuggestionList = function ( listId, 
suggestions ) {
                var i, list, $suggestion, $listHeading,
+                       self = this,
                        $suggestions = [];
 
                if ( !suggestions || !suggestions.length ) {
@@ -374,6 +383,9 @@
                        } else {
                                this.$publicCollectionContainer.show();
                                this.$publicCollection.append( list.$list );
+                               this.$publicCollection.find( 
'.cx-suggestionlist' ).sort( function ( a, b ) {
+                                       return listCompare( self.lists[ 
a.dataset.listid ], self.lists[ b.dataset.listid ] );
+                               } ).appendTo( this.$publicCollection );
                        }
                } else {
                        // The list might be hidden if it became empty due to 
item removals.
@@ -759,23 +771,13 @@
         * @return {number[]} Orderded list ids.
         */
        CXSuggestionList.prototype.sortLists = function ( lists ) {
-               var order, ids;
-
-               order = {};
-               order[ listTypes.TYPE_FAVORITE ] = 0;
-               order[ listTypes.TYPE_DISCARDED ] = 1;
-               order[ listTypes.TYPE_PERSONALIZED ] = 2;
-               order[ listTypes.TYPE_CATEGORY ] = 3;
-               order[ listTypes.TYPE_FEATURED ] = 4;
-               order[ listTypes.TYPE_DEFAULT ] = 5;
-
-               ids = Object.keys( lists ).sort( function ( a, b ) {
-                       return order[ lists[ a ].type ] - order[ lists[ b 
].type ];
-               } );
-
-               return ids;
+               return Object.keys( lists ).sort( listCompare );
        };
 
+       function listCompare( listA, listB ) {
+               return listOrder[ listA.type ] > listOrder[ listB.type ];
+       }
+
        /**
         * Make the list expandable and collapsable.
         *

-- 
To view, visit https://gerrit.wikimedia.org/r/259988
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I601200ad22d861fcbaf78d3752f421341afbf7f0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to