[Pkg-owncloud-commits] [owncloud] 90/457: Sort apps by level, then by name
David Prévot
taffit at moszumanska.debian.org
Sun Jun 28 20:05:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch stable8
in repository owncloud.
commit 66e426c9904b7ccb73fbf87a62b55feae6a672e6
Author: Vincent Petry <pvince81 at owncloud.com>
Date: Wed May 20 13:43:20 2015 +0200
Sort apps by level, then by name
Also properly initialize the level to 0 when no level was returned
---
settings/js/apps.js | 18 +++++++++++++-----
settings/tests/js/appsSpec.js | 18 ++++++++++++++----
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/settings/js/apps.js b/settings/js/apps.js
index 58a0a31..731a107 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);
diff --git a/settings/tests/js/appsSpec.js b/settings/tests/js/appsSpec.js
index 311fade..60e3692 100644
--- a/settings/tests/js/appsSpec.js
+++ b/settings/tests/js/appsSpec.js
@@ -130,14 +130,26 @@ describe('OC.Settings.Apps tests', function() {
apps: [
{
id: 'foo',
+ name: 'Foo app',
level: 0
},
{
id: 'alpha',
+ name: 'Alpha app',
level: 300
},
{
+ id: 'nolevel',
+ name: 'No level'
+ },
+ {
+ id: 'zork',
+ name: 'Some famous adventure game',
+ level: 200
+ },
+ {
id: 'delta',
+ name: 'Mathematical symbol',
level: 200
}
]
@@ -145,10 +157,8 @@ describe('OC.Settings.Apps tests', function() {
);
var results = getResultsFromDom();
- expect(results.length).toEqual(3);
- expect(results[0]).toEqual('alpha');
- expect(results[1]).toEqual('delta');
- expect(results[2]).toEqual('foo');
+ expect(results.length).toEqual(5);
+ expect(results).toEqual(['alpha', 'delta', 'zork', 'foo', 'nolevel']);
});
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list