From fed6d0a64e8567c65fa5285bce76d42d1e3d7d56 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 28 Mar 2013 20:20:19 +0100 Subject: [PATCH 1/3] allow using multiple searchwords --- .../admin/js/collections/arangoCollections.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/html/admin/js/collections/arangoCollections.js b/html/admin/js/collections/arangoCollections.js index b5b4dccce6..a6c166cb4e 100644 --- a/html/admin/js/collections/arangoCollections.js +++ b/html/admin/js/collections/arangoCollections.js @@ -82,17 +82,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; From 8e14661404c8e4f5ecf3f8a6b691c99d8eebd943 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 28 Mar 2013 20:41:57 +0100 Subject: [PATCH 2/3] added sorting options for collections view in web interface --- .../admin/js/collections/arangoCollections.js | 24 ++++++++--- html/admin/js/templates/collectionsView.ejs | 4 ++ html/admin/js/views/collectionsView.js | 40 ++++++++++++++++++- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/html/admin/js/collections/arangoCollections.js b/html/admin/js/collections/arangoCollections.js index a6c166cb4e..bcfbeba78b 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) { @@ -124,6 +122,22 @@ window.arangoCollections = Backbone.Collection.extend({ result.push(model); }); + result.sort(function (l, r) { + var lValue, rValue; + if (options.sortBy === 'type') { + lValue = l.get('type'); + rValue = r.get('type'); + } + 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; From 096e41ad0f6ddb0c193d474719c44bfd9e048204 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 28 Mar 2013 20:58:34 +0100 Subject: [PATCH 3/3] fixed cross-collection navigation --- html/admin/js/collections/arangoCollections.js | 6 ++++-- html/admin/js/views/documentsView.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/html/admin/js/collections/arangoCollections.js b/html/admin/js/collections/arangoCollections.js index bcfbeba78b..5c8d353776 100644 --- a/html/admin/js/collections/arangoCollections.js +++ b/html/admin/js/collections/arangoCollections.js @@ -125,8 +125,10 @@ window.arangoCollections = Backbone.Collection.extend({ result.sort(function (l, r) { var lValue, rValue; if (options.sortBy === 'type') { - lValue = l.get('type'); - rValue = r.get('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(); 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');