1
0
Fork 0

added sort-bey feature for filtering documents of a collection

This commit is contained in:
Heiko Kernbach 2014-08-21 14:19:57 +02:00
parent 750c87ed38
commit 8aafb99c5f
3 changed files with 36 additions and 6 deletions

View File

@ -8,6 +8,8 @@
filters: [], filters: [],
sortAttribute: "_key",
url: '/_api/documents', url: '/_api/documents',
model: window.arangoDocumentModel, model: window.arangoDocumentModel,
@ -33,6 +35,14 @@
this.loadTotal(); this.loadTotal();
}, },
setSort: function(key) {
this.sortAttribute = key;
},
getSort: function() {
return this.sortAttribute;
},
addFilter: function(attr, op, val) { addFilter: function(attr, op, val) {
this.filters.push({ this.filters.push({
attr: attr, attr: attr,
@ -83,9 +93,11 @@
query = "FOR x in @@collection"; query = "FOR x in @@collection";
query += this.setFiltersForQuery(bindVars); query += this.setFiltersForQuery(bindVars);
// Sort result, only useful for a small number of docs // Sort result, only useful for a small number of docs
if (this.getTotal() < 10000) { if (this.getTotal() < 12000) {
query += " SORT TO_NUMBER(x._key) == 0 ? x._key : TO_NUMBER(x._key)"; query += " SORT TO_NUMBER(x." + this.getSort() + ") == 0 ? x."
+ this.getSort() + " : TO_NUMBER(x." + this.getSort() + ")";
} }
if (bindVars.count !== 'all') { if (bindVars.count !== 'all') {
query += " LIMIT @offset, @count RETURN x"; query += " LIMIT @offset, @count RETURN x";
} }

View File

@ -51,9 +51,11 @@
<option value="&gt;">&gt;</option> <option value="&gt;">&gt;</option>
<option value="&gt;=">&gt;=</option> <option value="&gt;=">&gt;=</option>
</select><input id="attribute_value0" type="text" placeholder="Attribute value" class="filterValue"> </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> <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="resetView" class="button-warning btn-old-padding">Reset</button>
<button id="filterSend" class="button-success btn-old-padding">Filter</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>
</div> </div>

View File

@ -87,7 +87,8 @@
"click #documentsToolbar ul" : "resetIndexForms", "click #documentsToolbar ul" : "resetIndexForms",
"click #indexHeader #addIndex" : "toggleNewIndexView", "click #indexHeader #addIndex" : "toggleNewIndexView",
"click #indexHeader #cancelIndex" : "toggleNewIndexView", "click #indexHeader #cancelIndex" : "toggleNewIndexView",
"change #documentSize" : "setPagesize" "change #documentSize" : "setPagesize",
"change #docsSort" : "setSorting"
}, },
showSpinner: function() { showSpinner: function() {
@ -112,7 +113,20 @@
this.collection.getDocuments(this.getDocsCallback.bind(this)); 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) { returnPressedHandler: function(event) {
if (event.keyCode === 13 && $(event.target).is($('#docsSort'))) {
this.collection.getDocuments(this.getDocsCallback.bind(this));
}
if (event.keyCode === 13) { if (event.keyCode === 13) {
if ($("#confirmDeleteBtn").attr("disabled") === false) { if ($("#confirmDeleteBtn").attr("disabled") === false) {
this.confirmDelete(); this.confirmDelete();
@ -334,6 +348,7 @@
var self = this, counter = 0; var self = this, counter = 0;
this.filterId = 0; this.filterId = 0;
$('#docsSort').val(this.collection.getSort());
_.each(this.restoredFilters, function (f) { _.each(this.restoredFilters, function (f) {
//change html here and restore filters //change html here and restore filters
if (counter !== 0) { if (counter !== 0) {
@ -767,6 +782,7 @@
else { else {
if (this.lastCollectionName !== undefined) { if (this.lastCollectionName !== undefined) {
this.collection.resetFilter(); this.collection.resetFilter();
this.collection.setSort('_key');
this.restoredFilters = []; this.restoredFilters = [];
this.activeFilter = false; this.activeFilter = false;
} }