Sort apps by level, then by name
Also properly initialize the level to 0 when no level was returned
This commit is contained in:
parent
3a4568313f
commit
66e426c990
|
@ -86,17 +86,25 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
||||||
}), {
|
}), {
|
||||||
type:'GET',
|
type:'GET',
|
||||||
success: function (apps) {
|
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 source = $("#app-template").html();
|
||||||
var template = Handlebars.compile(source);
|
var template = Handlebars.compile(source);
|
||||||
|
|
||||||
if (apps.apps.length) {
|
if (appList.length) {
|
||||||
apps.apps.sort(function(a,b) {
|
appList.sort(function(a,b) {
|
||||||
return b.level - a.level;
|
var levelDiff = b.level - a.level;
|
||||||
|
if (levelDiff === 0) {
|
||||||
|
return OC.Util.naturalSortCompare(a.name, b.name);
|
||||||
|
}
|
||||||
|
return levelDiff;
|
||||||
});
|
});
|
||||||
|
|
||||||
var firstExperimental = false;
|
var firstExperimental = false;
|
||||||
_.each(apps.apps, function(app) {
|
_.each(appList, function(app) {
|
||||||
if(app.level === 0 && firstExperimental === false) {
|
if(app.level === 0 && firstExperimental === false) {
|
||||||
firstExperimental = true;
|
firstExperimental = true;
|
||||||
OC.Settings.Apps.renderApp(app, template, null, true);
|
OC.Settings.Apps.renderApp(app, template, null, true);
|
||||||
|
|
|
@ -130,14 +130,26 @@ describe('OC.Settings.Apps tests', function() {
|
||||||
apps: [
|
apps: [
|
||||||
{
|
{
|
||||||
id: 'foo',
|
id: 'foo',
|
||||||
|
name: 'Foo app',
|
||||||
level: 0
|
level: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'alpha',
|
id: 'alpha',
|
||||||
|
name: 'Alpha app',
|
||||||
level: 300
|
level: 300
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'nolevel',
|
||||||
|
name: 'No level'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'zork',
|
||||||
|
name: 'Some famous adventure game',
|
||||||
|
level: 200
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'delta',
|
id: 'delta',
|
||||||
|
name: 'Mathematical symbol',
|
||||||
level: 200
|
level: 200
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -145,10 +157,8 @@ describe('OC.Settings.Apps tests', function() {
|
||||||
);
|
);
|
||||||
|
|
||||||
var results = getResultsFromDom();
|
var results = getResultsFromDom();
|
||||||
expect(results.length).toEqual(3);
|
expect(results.length).toEqual(5);
|
||||||
expect(results[0]).toEqual('alpha');
|
expect(results).toEqual(['alpha', 'delta', 'zork', 'foo', 'nolevel']);
|
||||||
expect(results[1]).toEqual('delta');
|
|
||||||
expect(results[2]).toEqual('foo');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue