1
0
Fork 0

Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel

This commit is contained in:
Frank Celler 2013-03-28 21:47:14 +01:00
commit e7b38fdf82
4 changed files with 81 additions and 14 deletions

View File

@ -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;
},

View File

@ -15,6 +15,10 @@
<li class="nav-header">Status</li>
<li><a href="#"><label class="checkbox"><input type="checkbox" id="checkLoaded">Loaded</label></a></li>
<li><a href="#"><label class="checkbox"><input type="checkbox" id="checkUnloaded">Unloaded</label></a></li>
<li class="nav-header">Sorting</li>
<li><a href="#"><label class="radio"><input type="radio" id="sortName">Sort by name</label></a></li>
<li><a href="#"><label class="radio"><input type="radio" id="sortType">Sort by type</label></a></li>
<li><a href="#"><label class="checkbox"><input type="checkbox" id="sortOrder">Sort descending</label></a></li>
</ul>
</div>
<!-- /btn-group -->

View File

@ -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;

View File

@ -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');