diff --git a/html/admin/js/collections/arangoCollections.js b/html/admin/js/collections/arangoCollections.js
index b5b4dccce6..5c8d353776 100644
--- a/html/admin/js/collections/arangoCollections.js
+++ b/html/admin/js/collections/arangoCollections.js
@@ -11,11 +11,9 @@ window.arangoCollections = Backbone.Collection.extend({
includeDocument: true,
includeEdge: true,
includeLoaded: true,
- includeUnloaded: true
- },
-
- comparator : function(model) {
- return model.get('name').toLowerCase();
+ includeUnloaded: true,
+ sortBy: 'name',
+ sortOrder: 1
},
translateStatus : function (status) {
@@ -82,17 +80,28 @@ window.arangoCollections = Backbone.Collection.extend({
getFiltered : function (options) {
var result = [ ];
+ var searchPhrases = [ ];
- var searchPhrase = '';
if (options.searchPhrase !== null) {
- searchPhrase = options.searchPhrase.toLowerCase();
+ var searchPhrase = options.searchPhrase.toLowerCase();
+ // kick out whitespace
+ searchPhrase = searchPhrase.replace(/\s+/g, ' ').replace(/(^\s+|\s+$)/g, '');
+ searchPhrases = searchPhrase.split(' ');
}
this.models.forEach(function (model) {
- if (searchPhrase !== '' && model.get('name').toLowerCase().indexOf(searchPhrase) === -1) {
- // search phrase entered but current collection does not match?
- return;
+ // search for name(s) entered
+ if (searchPhrases.length > 0) {
+ var lowerName = model.get('name').toLowerCase(), i;
+ // all phrases must match!
+ for (i = 0; i < searchPhrases.length; ++i) {
+ if (lowerName.indexOf(searchPhrases[i]) === -1) {
+ // search phrase entered but current collection does not match?
+ return;
+ }
+ }
}
+
if (options.includeSystem === false && model.get('isSystem')) {
// system collection?
return;
@@ -113,6 +122,24 @@ window.arangoCollections = Backbone.Collection.extend({
result.push(model);
});
+ result.sort(function (l, r) {
+ var lValue, rValue;
+ if (options.sortBy === 'type') {
+ // we'll use first type, then name as the sort criteria
+ // this is because when sorting by type, we need a 2nd criterion (type is not unique)
+ lValue = l.get('type') + ' ' + l.get('name').toLowerCase();
+ rValue = r.get('type') + ' ' + r.get('name').toLowerCase();
+ }
+ else {
+ lValue = l.get('name').toLowerCase();
+ rValue = r.get('name').toLowerCase();
+ }
+ if (lValue != rValue) {
+ return options.sortOrder * (lValue < rValue ? -1 : 1);
+ }
+ return 0;
+ });
+
return result;
},
diff --git a/html/admin/js/templates/collectionsView.ejs b/html/admin/js/templates/collectionsView.ejs
index cf17a56567..c708cc3679 100644
--- a/html/admin/js/templates/collectionsView.ejs
+++ b/html/admin/js/templates/collectionsView.ejs
@@ -15,6 +15,10 @@
+
+
+
+
diff --git a/html/admin/js/views/collectionsView.js b/html/admin/js/views/collectionsView.js
index d5f455dda2..8f05959847 100644
--- a/html/admin/js/views/collectionsView.js
+++ b/html/admin/js/views/collectionsView.js
@@ -37,7 +37,10 @@ var collectionsView = Backbone.View.extend({
"click #checkLoaded" : "checkLoaded",
"click #checkUnloaded" : "checkUnloaded",
"click #checkDocument" : "checkDocument",
- "click #checkEdge" : "checkEdge"
+ "click #checkEdge" : "checkEdge",
+ "click #sortName" : "sortName",
+ "click #sortType" : "sortType",
+ "click #sortOrder" : "sortOrder"
},
checkSystem: function () {
@@ -90,6 +93,36 @@ var collectionsView = Backbone.View.extend({
this.render();
}
},
+ sortName: function () {
+ var searchOptions = this.collection.searchOptions;
+ var oldValue = searchOptions.sortBy;
+
+ searchOptions.sortBy = (($('#sortName').is(":checked") === true) ? 'name' : 'type');
+
+ if (oldValue != searchOptions.sortBy) {
+ this.render();
+ }
+ },
+ sortType: function () {
+ var searchOptions = this.collection.searchOptions;
+ var oldValue = searchOptions.sortBy;
+
+ searchOptions.sortBy = (($('#sortType').is(":checked") === true) ? 'type' : 'name');
+
+ if (oldValue != searchOptions.sortBy) {
+ this.render();
+ }
+ },
+ sortOrder: function () {
+ var searchOptions = this.collection.searchOptions;
+ var oldValue = searchOptions.sortOrder;
+
+ searchOptions.sortOrder = (($('#sortOrder').is(":checked") === true) ? -1 : 1);
+
+ if (oldValue != searchOptions.sortOrder) {
+ this.render();
+ }
+ },
setFilterValues: function () {
var searchOptions = this.collection.searchOptions;
@@ -98,11 +131,14 @@ var collectionsView = Backbone.View.extend({
$('#checkSystem').attr('checked', searchOptions.includeSystem);
$('#checkEdge').attr('checked', searchOptions.includeEdge);
$('#checkDocument').attr('checked', searchOptions.includeDocument);
+ $('#sortName').attr('checked', searchOptions.sortBy !== 'type');
+ $('#sortType').attr('checked', searchOptions.sortBy === 'type');
+ $('#sortOrder').attr('checked', searchOptions.sortOrder !== 1);
},
search: function () {
var searchOptions = this.collection.searchOptions;
- var searchPhrase = $('#searchInput').val().replace(/(^\s+|\s+$)/g, '');
+ var searchPhrase = $('#searchInput').val();
if (searchPhrase === searchOptions.searchPhrase) {
return;
diff --git a/html/admin/js/views/documentsView.js b/html/admin/js/views/documentsView.js
index 98711593b8..4fcca05953 100644
--- a/html/admin/js/views/documentsView.js
+++ b/html/admin/js/views/documentsView.js
@@ -46,7 +46,7 @@ var documentsView = Backbone.View.extend({
prevCollection : function () {
if (this.collectionContext.prev !== null) {
$('#collectionPrev').parent().removeClass('disabledPag');
- window.App.navigate(this.buildCollectionLink(this.collectionContext.prev));
+ window.App.navigate(this.buildCollectionLink(this.collectionContext.prev), { trigger: true });
}
else {
$('#collectionPrev').parent().addClass('disabledPag');
@@ -56,7 +56,7 @@ var documentsView = Backbone.View.extend({
nextCollection : function () {
if (this.collectionContext.next !== null) {
$('#collectionNext').parent().removeClass('disabledPag');
- window.App.navigate(this.buildCollectionLink(this.collectionContext.next));
+ window.App.navigate(this.buildCollectionLink(this.collectionContext.next), { trigger: true });
}
else {
$('#collectionNext').parent().addClass('disabledPag');