Skip to content

Commit 6936318

Browse files
committed
Sort group items on load.
This only affects groups that are populated by loading, such as the CKAN, WMS, and WFS groups.
1 parent 210fa90 commit 6936318

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

LICENSE.md

+27
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,33 @@ https://github.com/humangeo/leaflet-tilefilter
213213
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
214214
215215

216+
### javascript-natural-sort
217+
218+
https://www.npmjs.org/package/javascript-natural-sort
219+
220+
> The MIT License (MIT)
221+
222+
> Copyright (c) Jim Palmer, Kyle Housley
223+
224+
> Permission is hereby granted, free of charge, to any person obtaining a copy
225+
> of this software and associated documentation files (the "Software"), to deal
226+
> in the Software without restriction, including without limitation the rights
227+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
228+
> copies of the Software, and to permit persons to whom the Software is
229+
> furnished to do so, subject to the following conditions:
230+
>
231+
> The above copyright notice and this permission notice shall be included in
232+
> all copies or substantial portions of the Software.
233+
>
234+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
235+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
236+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
237+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
238+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
239+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
240+
> THE SOFTWARE.
241+
242+
216243
Tests
217244
=====
218245

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"cors": "~2.5.0",
88
"express": "^4.4.3",
99
"formidable": "~1.0.15",
10+
"javascript-natural-sort": "^0.7.1",
1011
"mongoose": "^3.8.18",
1112
"ogr2ogr": "~0.4.1",
1213
"proj4": "~2.2.1",

src/ViewModels/CatalogGroupViewModel.js

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ var inherit = require('../Core/inherit');
1818
var raiseErrorOnRejectedPromise = require('./raiseErrorOnRejectedPromise');
1919
var runLater = require('../Core/runLater');
2020

21+
var naturalSort = require('javascript-natural-sort');
22+
2123
/**
2224
* A group of data items and other groups in the {@link CatalogViewModel}. A group can contain
2325
* {@link CatalogMemberViewModel|CatalogMemberViewModels} or other
@@ -265,6 +267,7 @@ CatalogGroupViewModel.prototype.load = function() {
265267

266268
return that._load();
267269
}).then(function() {
270+
that.sortItems();
268271
that._loadingPromise = undefined;
269272
that.isLoading = false;
270273
}).otherwise(function(e) {
@@ -343,4 +346,25 @@ CatalogGroupViewModel.prototype.findFirstItemByName = function(name) {
343346
return undefined;
344347
};
345348

349+
/**
350+
* Sorts the items in this group.
351+
*
352+
* @param {Boolean} [sortRecursively=false] true to sort the items in sub-groups as well; false to sort only the items in this group.
353+
*/
354+
CatalogGroupViewModel.prototype.sortItems = function(sortRecursively) {
355+
naturalSort.insensitive = true;
356+
this.items.sort(function(a, b) {
357+
return naturalSort(a.name, b.name);
358+
});
359+
360+
if (defaultValue(sortRecursively, false)) {
361+
for (var i = 0; i < this.items.length; ++i) {
362+
var item = this.items[i];
363+
if (defined(item.sortItems)) {
364+
item.sortItems(sortRecursively);
365+
}
366+
}
367+
}
368+
};
369+
346370
module.exports = CatalogGroupViewModel;

src/ViewModels/raiseErrorOnRejectedPromise.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ var raiseErrorOnRejectedPromise = function(application, promise) {
1919
} else {
2020
application.error.raiseEvent(new ViewModelError({
2121
sender: undefined,
22-
title: 'An unknown error occurred',
22+
title: 'An error occurred',
2323
message: '\
24-
<p>National Map experienced an unknown error. Please report this by emailing <a href="mailto:nationalmap@lists.nicta.com.au">nationalmap@lists.nicta.com.au</a>. \
24+
<p>National Map experienced an error. Please report this by emailing <a href="mailto:nationalmap@lists.nicta.com.au">nationalmap@lists.nicta.com.au</a>. \
2525
Details of the error are below.</p>\
2626
<p><pre>' + e.toString() + '</pre></p>'
2727
}));

0 commit comments

Comments
 (0)