diff options
author | Marcel Klehr <mklehr@gmx.net> | 2013-03-25 23:09:03 +0100 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2013-03-25 23:09:03 +0100 |
commit | 773293991b2ad4877d2c360cef59ccc4cd7562f5 (patch) | |
tree | f50cc017a919dd49f0e95715c9252919292132b8 /src/node/hooks/express/adminplugins.js | |
parent | 1ebbcd2f30895e4e0ec54a49c2e49905ab52f626 (diff) | |
download | etherpad-lite-773293991b2ad4877d2c360cef59ccc4cd7562f5.zip |
admin/plugins: Allow people to sort search results
Diffstat (limited to 'src/node/hooks/express/adminplugins.js')
-rw-r--r-- | src/node/hooks/express/adminplugins.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/node/hooks/express/adminplugins.js b/src/node/hooks/express/adminplugins.js index 6b7c01e0..70ace317 100644 --- a/src/node/hooks/express/adminplugins.js +++ b/src/node/hooks/express/adminplugins.js @@ -70,10 +70,11 @@ exports.socketio = function (hook_name, args, cb) { results = {} } var res = Object.keys(results) - .slice(query.offset, query.offset+query.length) .map(function(pluginName) { return results[pluginName] }); + res = sortPluginList(res, query.sortBy, query.sortDir) + .slice(query.offset, query.offset+query.limit); socket.emit("results:search", {results: res, query: query}); }); }); @@ -91,3 +92,14 @@ exports.socketio = function (hook_name, args, cb) { }); }); } + +function sortPluginList(plugins, property, /*ASC?*/dir) { + return plugins.sort(function(a, b) { + if (a[property] < b[property]) + return dir? -1 : 1; + if (a[property] > b[property]) + return dir? 1 : -1; + // a must be equal to b + return 0; + }) +}
\ No newline at end of file |