1
0
Fork 0

filter widget with logical operators

This commit is contained in:
Thomas Richter 2013-07-19 14:23:48 +02:00
parent 9e26687baa
commit 0d3a66704f
3 changed files with 40 additions and 33 deletions

View File

@ -101,30 +101,15 @@ window.arangoDocuments = Backbone.Collection.extend({
}); });
}, },
/*
POST /_api/cursor
{
"query": "FOR u in mycollection FILTER @name1, @name2 return u",
"count": false,
"bindVars": {
"name1": xy,
"name2": xy
}
}
*/
getFilteredDocuments: function (colid, currpage, filter) { getFilteredDocuments: function (colid, currpage, filter) {
var self = this; var self = this;
this.collectionID = colid; this.collectionID = colid;
this.currentPage = currpage; this.currentPage = currpage;
var filterstring; var filterstring;
console.log(filter);
if(filter.length === 0){ if(filter.length === 0){
filterstring =""; filterstring ="";
} else { } else {
filterstring = ' FILTER' + filter.toString(); filterstring = ' FILTER' + filter.join('');
} }
var query = var query =
'{"query":"FOR u in ' + this.collectionID + filterstring + ' RETURN u"}'; '{"query":"FOR u in ' + this.collectionID + filterstring + ' RETURN u"}';
@ -141,14 +126,14 @@ window.arangoDocuments = Backbone.Collection.extend({
console.log(data.result.length); console.log(data.result.length);
self.documentsCount = data.result.length; self.documentsCount = data.result.length;
self.totalPages = Math.ceil(self.documentsCount / self.documentsPerPage); self.totalPages = Math.ceil(self.documentsCount / self.documentsPerPage);
if (isNaN(this.currentPage) || this.currentPage === undefined || this.currentPage < 1) { if (isNaN(this.currentPage) || this.currentPage === undefined || this.currentPage < 1) {
this.currentPage = 1; this.currentPage = 1;
} }
if (this.totalPages === 0) { if (this.totalPages === 0) {
this.totalPages = 1; this.totalPages = 1;
} }
this.offset = (this.currentPage - 1) * this.documentsPerPage; this.offset = (this.currentPage - 1) * this.documentsPerPage;
if (self.documentsCount !== 0) { if (self.documentsCount !== 0) {
$.each(data.result, function(k, v) { $.each(data.result, function(k, v) {
window.arangoDocumentsStore.add({ window.arangoDocumentsStore.add({
@ -165,10 +150,12 @@ window.arangoDocuments = Backbone.Collection.extend({
else { else {
window.documentsView.initTable(); window.documentsView.initTable();
window.documentsView.drawTable(); window.documentsView.drawTable();
window.documentsView.renderPagination(self.totalPages);
} }
}, },
error: function(data) { error: function(data) {
"use strict"; "use strict";
console.error(data);
} }
}); });
}, },

View File

@ -13,19 +13,14 @@
</ul> </ul>
<div id="filterHeader" style="display:none"> <div id="filterHeader" style="display:none">
<div id="queryline"> <div class="queryline">
<label for="attribute_name">attribute name:</label><input id="attribute_name" type="text"> <input id="attribute_name" type="text" placeholder="Attribute name"><select name="operator" id="operator">
<select name="operator" id="operator">
<option value=" == ">==</option> <option value=" == ">==</option>
<option value=" != ">!=</option> <option value=" != ">!=</option>
<option value=" > ">&lt;</option> <option value=" > ">&lt;</option>
<option value=" < ">&gt;</option> <option value=" < ">&gt;</option>
</select> </select><input id="attribute_value" type="text" placeholder="Attribute value">
<label for="attribute_value">attribute value:</label><input id="attribute_value" type="text">
<a id="addFilterItem"><i class="icon icon-white icon-plus"></i></a> <a id="addFilterItem"><i class="icon icon-white icon-plus"></i></a>
<a id="femoveFilterItem"><i class="icon icon-white icon-minus"></i></a>
</div>
<div id="sendFilter">
<button id="filterSend">Filter</button> <button id="filterSend">Filter</button>
</div> </div>
</div> </div>

View File

@ -23,7 +23,7 @@ var documentsView = Backbone.View.extend({
"click #collectionNext" : "nextCollection", "click #collectionNext" : "nextCollection",
"click #filterCollection" : "filterCollection", "click #filterCollection" : "filterCollection",
"click #filterSend" : "sendFilter", "click #filterSend" : "sendFilter",
"click #queryline #addFilterItem": "addFilterItem", "click #addFilterItem" : "addFilterItem",
"click #confirmCreateEdge" : "addEdge", "click #confirmCreateEdge" : "addEdge",
"click #documentsTableID tr" : "clicked", "click #documentsTableID tr" : "clicked",
"click #deleteDoc" : "remove", "click #deleteDoc" : "remove",
@ -81,11 +81,19 @@ var documentsView = Backbone.View.extend({
filterCollection : function () { filterCollection : function () {
$('#filterHeader').slideToggle("slow"); $('#filterHeader').slideToggle("slow");
this.filter = [];
}, },
sendFilter : function () { sendFilter : function () {
this.filter = []; this.filter = [];
console.log("hallo" + this.filter); var filterlength = $('.queryline').length;
var i;
for(i=1;i<filterlength;i++){
if($('#attribute_name'+i).val()!=''){
this.filter.push(" u."+ $('#attribute_name'+i).val() + $('#operator'+i).val()+ "'" +
$('#attribute_value'+i).val() + "'" + $('#logicaloperator'+i).val());
}
}
if($('#attribute_name').val()!==''){ if($('#attribute_name').val()!==''){
this.filter.push(" u." + $('#attribute_name').val() + $('#operator').val()+ "'" + this.filter.push(" u." + $('#attribute_name').val() + $('#operator').val()+ "'" +
$('#attribute_value').val() + "' "); $('#attribute_value').val() + "' ");
@ -98,6 +106,23 @@ var documentsView = Backbone.View.extend({
addFilterItem : function () { addFilterItem : function () {
"use strict"; "use strict";
// adds a line to the filter widget // adds a line to the filter widget
var num = this.filter.length + 1;
$('#filterHeader').prepend(' <div class="queryline">'+
'<input id="attribute_name'+ num +'" type="text" placeholder="Attribute name">'+
'<select name="operator" id="operator'+ num +'">'+
' <option value=" == ">==</option>'+
' <option value=" != ">!=</option>'+
' <option value=" > ">&lt;</option>'+
' <option value=" < ">&gt;</option>'+
'</select>'+
'<input id="attribute_value' + num + '" type="text" placeholder="Attribute value">'+
'<select name="logicaloperator" id="logicaloperator'+ num +'">'+
' <option value=" && ">and</option>'+
' <option value=" || ">or</option>'+
'</select>'+
' <a id="femoveFilterItem" data="' + num + '"><i class="icon icon-white icon-minus"></i></a>'+
' </div>');
}, },
removeFilterItem : function (delline) { removeFilterItem : function (delline) {