mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
admin/plugins: Allow people to sort search results
This commit is contained in:
parent
1ebbcd2f30
commit
773293991b
4 changed files with 84 additions and 15 deletions
|
@ -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;
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue