mirror of https://gitee.com/bigwinds/arangodb
can hide system collections
This commit is contained in:
parent
53b41e7832
commit
935fbf70cd
|
@ -1,23 +1,37 @@
|
||||||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
|
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
|
||||||
/*global require, exports */
|
/*global require, exports */
|
||||||
window.arangoCollections = Backbone.Collection.extend({
|
window.arangoCollections = Backbone.Collection.extend({
|
||||||
|
url: '/_api/collection',
|
||||||
|
|
||||||
|
model: arangoCollection,
|
||||||
|
|
||||||
comparator : function(model) {
|
comparator : function(model) {
|
||||||
return model.get('name').toLowerCase();
|
return model.get('name').toLowerCase();
|
||||||
},
|
},
|
||||||
|
|
||||||
url: '/_api/collection',
|
isSystemCollection : function (name) {
|
||||||
parse: function(response) {
|
return name.substr(0, 1) === '_';
|
||||||
$.each(response.collections, function(key, val) {
|
|
||||||
if (val.status == 2) {
|
|
||||||
val.status = 'unloaded';
|
|
||||||
}
|
|
||||||
else if (val.status == 3) {
|
|
||||||
val.status = 'loaded';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return response.collections;
|
|
||||||
},
|
},
|
||||||
model: arangoCollection,
|
|
||||||
|
translateStatus : function (status) {
|
||||||
|
if (status == 2) {
|
||||||
|
return 'unloaded';
|
||||||
|
}
|
||||||
|
else if (status == 3) {
|
||||||
|
return 'loaded';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
parse: function(response) {
|
||||||
|
var that = this;
|
||||||
|
|
||||||
|
$.each(response.collections, function(key, val) {
|
||||||
|
val.isSystem = that.isSystemCollection(val.name);
|
||||||
|
val.status = that.translateStatus(val.status);
|
||||||
|
});
|
||||||
|
return response.collections;
|
||||||
|
},
|
||||||
|
|
||||||
getProperties: function (id) {
|
getProperties: function (id) {
|
||||||
var data2;
|
var data2;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
window.arangoCollection = Backbone.Model.extend({
|
window.arangoCollection = Backbone.Model.extend({
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
},
|
},
|
||||||
|
|
||||||
urlRoot: "/_api/collection",
|
urlRoot: "/_api/collection",
|
||||||
defaults: {
|
defaults: {
|
||||||
id: "",
|
id: "",
|
||||||
name: "",
|
name: "",
|
||||||
status: "",
|
status: "",
|
||||||
type: "",
|
type: "",
|
||||||
|
isSystem: false,
|
||||||
picture: ""
|
picture: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,20 +1,33 @@
|
||||||
var collectionsView = Backbone.View.extend({
|
var collectionsView = Backbone.View.extend({
|
||||||
el: '#content',
|
el: '#content',
|
||||||
el2: '.thumbnails',
|
el2: '.thumbnails',
|
||||||
searchPhrase: '',
|
|
||||||
|
searchOptions: {
|
||||||
|
searchPhrase: null,
|
||||||
|
excludeSystem: false
|
||||||
|
},
|
||||||
|
|
||||||
init: function () {
|
init: function () {
|
||||||
},
|
},
|
||||||
|
|
||||||
template: new EJS({url: '/_admin/html/js/templates/collectionsView.ejs'}),
|
template: new EJS({url: '/_admin/html/js/templates/collectionsView.ejs'}),
|
||||||
|
|
||||||
render: function() {
|
render: function () {
|
||||||
$(this.el).html(this.template.text);
|
$(this.el).html(this.template.text);
|
||||||
|
|
||||||
var searchPhrase = this.searchPhrase.toLowerCase();
|
var searchPhrase = '';
|
||||||
|
if (this.searchOptions.searchPhrase !== null) {
|
||||||
|
searchPhrase = this.searchOptions.searchPhrase.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
this.collection.each(function (arango_collection) {
|
this.collection.each(function (arango_collection) {
|
||||||
if (searchPhrase !== '' && arango_collection.get('name').toLowerCase().indexOf(searchPhrase) === -1) {
|
if (searchPhrase !== '' && arango_collection.get('name').toLowerCase().indexOf(searchPhrase) === -1) {
|
||||||
|
// search phrase entered but current collection does not match?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.searchOptions.excludeSystem && arango_collection.get('isSystem')) {
|
||||||
|
// system collection?
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,22 +46,31 @@ var collectionsView = Backbone.View.extend({
|
||||||
"click #searchSubmit" : "restrictToSearchPhrase"
|
"click #searchSubmit" : "restrictToSearchPhrase"
|
||||||
},
|
},
|
||||||
|
|
||||||
restrictToSearchPhraseKey: function(e) {
|
search: function () {
|
||||||
if (e.keyCode == 13) {
|
var searchPhrase = $('#searchInput').val().replace(/(^\s+|\s+$)/g, '');
|
||||||
this.searchPhrase = $('#searchInput').val().replace(/(^\s+|\s+$)/g, '');
|
|
||||||
this.render();
|
if (searchPhrase === this.searchOptions.searchPhrase) {
|
||||||
}
|
|
||||||
},
|
|
||||||
restrictToSearchPhrase: function() {
|
|
||||||
var searchPhrase = this.searchPhrase;
|
|
||||||
this.searchPhrase = $('#searchInput').val().replace(/(^\s+|\s+$)/g, '');
|
|
||||||
if (searchPhrase === this.searchPhrase) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.searchOptions.searchPhrase = searchPhrase;
|
||||||
|
|
||||||
this.render();
|
this.render();
|
||||||
},
|
},
|
||||||
|
|
||||||
details: function() {
|
restrictToSearchPhraseKey: function (e) {
|
||||||
|
// key pressed in search box
|
||||||
|
if (e.keyCode == 13) {
|
||||||
|
// return pressed? this triggers the search
|
||||||
|
this.search();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
restrictToSearchPhrase: function () {
|
||||||
|
// search executed
|
||||||
|
this.search();
|
||||||
|
},
|
||||||
|
|
||||||
|
details: function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue