mirror of https://gitee.com/bigwinds/arangodb
added sort-bey feature for filtering documents of a collection
This commit is contained in:
parent
750c87ed38
commit
8aafb99c5f
|
@ -8,6 +8,8 @@
|
|||
|
||||
filters: [],
|
||||
|
||||
sortAttribute: "_key",
|
||||
|
||||
url: '/_api/documents',
|
||||
model: window.arangoDocumentModel,
|
||||
|
||||
|
@ -33,6 +35,14 @@
|
|||
this.loadTotal();
|
||||
},
|
||||
|
||||
setSort: function(key) {
|
||||
this.sortAttribute = key;
|
||||
},
|
||||
|
||||
getSort: function() {
|
||||
return this.sortAttribute;
|
||||
},
|
||||
|
||||
addFilter: function(attr, op, val) {
|
||||
this.filters.push({
|
||||
attr: attr,
|
||||
|
@ -83,9 +93,11 @@
|
|||
query = "FOR x in @@collection";
|
||||
query += this.setFiltersForQuery(bindVars);
|
||||
// Sort result, only useful for a small number of docs
|
||||
if (this.getTotal() < 10000) {
|
||||
query += " SORT TO_NUMBER(x._key) == 0 ? x._key : TO_NUMBER(x._key)";
|
||||
if (this.getTotal() < 12000) {
|
||||
query += " SORT TO_NUMBER(x." + this.getSort() + ") == 0 ? x."
|
||||
+ this.getSort() + " : TO_NUMBER(x." + this.getSort() + ")";
|
||||
}
|
||||
|
||||
if (bindVars.count !== 'all') {
|
||||
query += " LIMIT @offset, @count RETURN x";
|
||||
}
|
||||
|
|
|
@ -51,9 +51,11 @@
|
|||
<option value=">">></option>
|
||||
<option value=">=">>=</option>
|
||||
</select><input id="attribute_value0" type="text" placeholder="Attribute value" class="filterValue">
|
||||
<a id="addFilterItem" class="add-filter-item"><i class="icon-plus arangoicon"></i></a>
|
||||
<button id="resetView" class="button-warning btn-old-padding">Reset</button>
|
||||
<button id="filterSend" class="button-success btn-old-padding">Filter</button>
|
||||
<a id="addFilterItem" class="add-filter-item"><i class="icon-plus arangoicon"></i></a>
|
||||
<button id="resetView" class="button-warning btn-old-padding">Reset</button>
|
||||
<button id="filterSend" class="button-success btn-old-padding">Filter</button>
|
||||
<input type="text" id="docsSort" placeholder="_key" style="float: right"></input>
|
||||
<div class="textDiv" style="float: right">Sort by:</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -87,7 +87,8 @@
|
|||
"click #documentsToolbar ul" : "resetIndexForms",
|
||||
"click #indexHeader #addIndex" : "toggleNewIndexView",
|
||||
"click #indexHeader #cancelIndex" : "toggleNewIndexView",
|
||||
"change #documentSize" : "setPagesize"
|
||||
"change #documentSize" : "setPagesize",
|
||||
"change #docsSort" : "setSorting"
|
||||
},
|
||||
|
||||
showSpinner: function() {
|
||||
|
@ -112,7 +113,20 @@
|
|||
this.collection.getDocuments(this.getDocsCallback.bind(this));
|
||||
},
|
||||
|
||||
setSorting: function() {
|
||||
var sortAttribute = $('#docsSort').val();
|
||||
|
||||
if (sortAttribute === '' || sortAttribute === undefined || sortAttribute === null) {
|
||||
sortAttribute = '_key';
|
||||
}
|
||||
|
||||
this.collection.setSort(sortAttribute);
|
||||
},
|
||||
|
||||
returnPressedHandler: function(event) {
|
||||
if (event.keyCode === 13 && $(event.target).is($('#docsSort'))) {
|
||||
this.collection.getDocuments(this.getDocsCallback.bind(this));
|
||||
}
|
||||
if (event.keyCode === 13) {
|
||||
if ($("#confirmDeleteBtn").attr("disabled") === false) {
|
||||
this.confirmDelete();
|
||||
|
@ -334,6 +348,7 @@
|
|||
var self = this, counter = 0;
|
||||
|
||||
this.filterId = 0;
|
||||
$('#docsSort').val(this.collection.getSort());
|
||||
_.each(this.restoredFilters, function (f) {
|
||||
//change html here and restore filters
|
||||
if (counter !== 0) {
|
||||
|
@ -767,6 +782,7 @@
|
|||
else {
|
||||
if (this.lastCollectionName !== undefined) {
|
||||
this.collection.resetFilter();
|
||||
this.collection.setSort('_key');
|
||||
this.restoredFilters = [];
|
||||
this.activeFilter = false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue