From 66e426c9904b7ccb73fbf87a62b55feae6a672e6 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 20 May 2015 13:43:20 +0200 Subject: Sort apps by level, then by name Also properly initialize the level to 0 when no level was returned --- settings/js/apps.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'settings/js/apps.js') diff --git a/settings/js/apps.js b/settings/js/apps.js index 58a0a31ccd8..731a107fb14 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -86,17 +86,25 @@ OC.Settings.Apps = OC.Settings.Apps || { }), { type:'GET', success: function (apps) { - OC.Settings.Apps.State.apps = _.indexBy(apps.apps, 'id'); + var appList = _.map(_.indexBy(apps.apps, 'id'), function(app) { + // default values for missing fields + return _.extend({level: 0}, app); + }); + OC.Settings.Apps.State.apps = appList; var source = $("#app-template").html(); var template = Handlebars.compile(source); - if (apps.apps.length) { - apps.apps.sort(function(a,b) { - return b.level - a.level; + if (appList.length) { + appList.sort(function(a,b) { + var levelDiff = b.level - a.level; + if (levelDiff === 0) { + return OC.Util.naturalSortCompare(a.name, b.name); + } + return levelDiff; }); var firstExperimental = false; - _.each(apps.apps, function(app) { + _.each(appList, function(app) { if(app.level === 0 && firstExperimental === false) { firstExperimental = true; OC.Settings.Apps.renderApp(app, template, null, true); -- cgit v1.2.3