diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-02 18:22:50 +0100 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-02 18:22:50 +0100 |
commit | f22bc3fd885b28be74266c2c48bcc84a3a7ede26 (patch) | |
tree | eb51f4323c11f8b3e5bb1a755cb7b4f2bc973616 /devtools/server/actors/storage.js | |
parent | 166fb9f2893dcfb3375aa3227d116fb0ce2c6d42 (diff) | |
download | UXP-f22bc3fd885b28be74266c2c48bcc84a3a7ede26.tar UXP-f22bc3fd885b28be74266c2c48bcc84a3a7ede26.tar.gz UXP-f22bc3fd885b28be74266c2c48bcc84a3a7ede26.tar.lz UXP-f22bc3fd885b28be74266c2c48bcc84a3a7ede26.tar.xz UXP-f22bc3fd885b28be74266c2c48bcc84a3a7ede26.zip |
moebius#342: Columns are not sorted correctly (Natural Sort algorithm)
Issue #31
https://github.com/MoonchildProductions/moebius/pull/342
Diffstat (limited to 'devtools/server/actors/storage.js')
-rw-r--r-- | devtools/server/actors/storage.js | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js index 620a9acb9..015d849ee 100644 --- a/devtools/server/actors/storage.js +++ b/devtools/server/actors/storage.js @@ -17,6 +17,9 @@ const { Task } = require("devtools/shared/task"); const DEFAULT_VALUE = "value"; +loader.lazyRequireGetter(this, "naturalSortCaseInsensitive", + "devtools/client/shared/natural-sort", true); + // GUID to be used as a separator in compound keys. This must match the same // constant in devtools/client/storage/ui.js, // devtools/client/storage/test/head.js and @@ -326,15 +329,20 @@ StorageActors.defaults = function (typeName, observationTopic) { toReturn.data.push(...values); } } + toReturn.total = this.getObjectsSize(host, names, options); + if (offset > toReturn.total) { // In this case, toReturn.data is an empty array. toReturn.offset = toReturn.total; toReturn.data = []; } else { - toReturn.data = toReturn.data.sort((a, b) => { - return a[sortOn] - b[sortOn]; - }).slice(offset, offset + size).map(a => this.toStoreObject(a)); + // We need to use natural sort before slicing. + let sorted = toReturn.data.sort((a, b) => { + return naturalSortCaseInsensitive(a[sortOn], b[sortOn]); + }); + let sliced = sorted.slice(offset, offset + size); + toReturn.data = sliced.map(a => this.toStoreObject(a)); } } else { let obj = yield this.getValuesForHost(host, undefined, undefined, @@ -344,15 +352,18 @@ StorageActors.defaults = function (typeName, observationTopic) { } toReturn.total = obj.length; + if (offset > toReturn.total) { // In this case, toReturn.data is an empty array. toReturn.offset = offset = toReturn.total; toReturn.data = []; } else { - toReturn.data = obj.sort((a, b) => { - return a[sortOn] - b[sortOn]; - }).slice(offset, offset + size) - .map(object => this.toStoreObject(object)); + // We need to use natural sort before slicing. + let sorted = obj.sort((a, b) => { + return naturalSortCaseInsensitive(a[sortOn], b[sortOn]); + }); + let sliced = sorted.slice(offset, offset + size); + toReturn.data = sliced.map(object => this.toStoreObject(object)); } } |