1
0
Fork 0

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

This commit is contained in:
Jan Steemann 2014-04-08 10:00:49 +02:00
commit 46c27efbfe
12 changed files with 158 additions and 124 deletions

View File

@ -14,8 +14,8 @@
},
setPage: function(counter) {
if (counter > this.getLastPageNumber()) {
this.page = this.getLastPageNumber();
if (counter >= this.getLastPageNumber()) {
this.page = this.getLastPageNumber()-1;
return;
}
if (counter < 1) {
@ -23,6 +23,7 @@
return;
}
this.page = counter - 1;
},
getLastPageNumber: function() {
@ -42,7 +43,9 @@
},
setToLast: function() {
console.log("lpn " , this.getLastPageNumber());
this.setPage(this.getLastPageNumber());
console.log(this.getPage());
},
setToPrev: function() {

View File

@ -91,7 +91,6 @@
query: query,
bindVars: bindVars
};
$.ajax({
cache: false,
type: 'POST',

View File

@ -105,7 +105,9 @@
collection: window.arangoCollectionsStore
});
window.arangoCollectionsStore.fetch();
window.documentsView = new window.DocumentsView();
window.documentsView = new window.DocumentsView({
collection: window.arangoDocumentsStore
});
window.documentView = new window.DocumentView({
collection: window.arangoDocumentStore
});
@ -295,13 +297,13 @@
if (!window.documentsView) {
window.documentsView.initTable(colid, pageid);
}
window.documentsView.collectionID = colid;
var type = arangoHelper.collectionApiType(colid);
window.documentsView.colid = colid;
window.documentsView.pageid = pageid;
window.documentsView.type = type;
window.documentsView.render();
window.documentsView.setCollectionId(colid);
window.arangoDocumentsStore.getDocuments(colid, pageid);
window.documentsView.render();
},
document: function (colid, docid) {

View File

@ -0,0 +1,71 @@
/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */
/*global require, exports, Backbone, EJS, $, window, arangoHelper, templateEngine */
(function() {
"use strict";
window.PaginationView = Backbone.View.extend({
// Subclasses need to overwrite this
collection : null,
paginationDiv : "",
idPrefix : "",
rerender : function () {},
jumpTo: function(page) {
var self = this;
this.collection.setPage(page);
this.rerender();
},
firstPage: function() {
this.jumpTo(1);
},
lastPage: function() {
this.jumpTo(this.collection.getLastPageNumber());
},
firstDocuments: function () {
this.jumpTo(1);
},
lastDocuments: function () {
this.jumpTo(this.collection.getLastPageNumber());
},
prevDocuments: function () {
this.jumpTo(this.collection.getPage() - 1);
},
nextDocuments: function () {
this.jumpTo(this.collection.getPage() + 1);
},
renderPagination: function () {
$(this.paginationDiv).html("");
var self = this;
var currentPage = this.collection.getPage();
var totalPages = this.collection.getLastPageNumber();
var target = $(this.paginationDiv),
options = {
page: currentPage,
lastPage: totalPages,
click: function(i) {
self.jumpTo(i);
options.page = i;
}
};
target.html("");
target.pagination(options);
$(this.paginationDiv).prepend(
'<ul class="pre-pagi"><li><a id="' + this.idPrefix + '_first" class="pagination-button">'+
'<span><i class="fa fa-angle-double-left"/></span></a></li></ul>'
);
$(this.paginationDiv).append(
'<ul class="las-pagi"><li><a id="' + this.idPrefix + '_last" class="pagination-button">'+
'<span><i class="fa fa-angle-double-right"/></span></a></li></ul>'
);
}
});
}());

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
/*global Backbone, EJS, $, window, arangoHelper, templateEngine, _, console */
/*global Backbone, $, window, arangoHelper, templateEngine, _*/
window.ApplicationsView = Backbone.View.extend({
el: '#content',
@ -43,7 +43,6 @@ window.ApplicationsView = Backbone.View.extend({
data: res.responseText,
contentType: "application/json"
}).done(function(res) {
console.log(res);
$.ajax({
type: "POST",
async: false,

View File

@ -166,7 +166,7 @@
)
);
}
// TODO: needs to be refactored. move getProperties into model
// needs to be refactored. move getProperties into model
var journalSize = this.model.collection.getProperties(this.model.get('id')).journalSize;
journalSize = journalSize/(1024*1024);
tableContent.push(

View File

@ -3,13 +3,15 @@
(function() {
"use strict";
window.DocumentsView = Backbone.View.extend({
window.DocumentsView = window.PaginationView.extend({
collectionID: 0,
currentPage: 1,
documentsPerPage: 10,
totalPages: 1,
filters : { "0" : true },
filterId : 0,
paginationDiv : "#documentsToolbarF",
idPrefix : "documents",
addDocumentSwitch: true,
@ -20,6 +22,12 @@
next: null
},
setCollectionId : function (colid) {
this.collectionID = colid;
this.colid = colid;
this.collection.setCollection(colid);
},
alreadyClicked: false,
el: '#content',
@ -221,7 +229,7 @@
},
getFilterContent: function () {
var filters = [ ], bindValues = { };
var filters = [ ];
var i;
for (i in this.filters) {
@ -236,23 +244,26 @@
}
if ($('#attribute_name' + i).val() !== ''){
filters.push(" u.`"+ $('#attribute_name'+i).val() + "`" +
$('#operator' + i).val() +
"@param" + i);
bindValues["param" + i] = value;
filters.push({
attribute : $('#attribute_name'+i).val(),
operator : $('#operator'+i).val(),
value : value
});
}
}
}
return [filters, bindValues];
return filters;
},
sendFilter : function () {
var filterArray = this.getFilterContent();
var filters = filterArray[0];
var bindValues = filterArray[1];
var filters = this.getFilterContent();
this.addDocumentSwitch = false;
window.documentsView.clearTable();
window.arangoDocumentsStore.getFilteredDocuments(this.colid, 1, filters, bindValues);
_.each(filters, function (f) {
this.collection.addFilter((f.attribute, f.operator, f.value));
})
this.clearTable();
this.collection.setToFirst();
this.collection.getDocuments();
//Hide first/last pagination
$('#documents_last').css("visibility", "hidden");
@ -355,18 +366,7 @@
arangoHelper.arangoError('Creating edge failed');
}
},
firstDocuments: function () {
window.arangoDocumentsStore.getFirstDocuments();
},
lastDocuments: function () {
window.arangoDocumentsStore.getLastDocuments();
},
prevDocuments: function () {
window.arangoDocumentsStore.getPrevDocuments();
},
nextDocuments: function () {
window.arangoDocumentsStore.getNextDocuments();
},
remove: function (a) {
this.target = a.currentTarget;
var thiselement = a.currentTarget.parentElement;
@ -472,13 +472,14 @@
$(this.table).dataTable().fnClearTable();
},
drawTable: function() {
this.clearTable();
var self = this;
if (window.arangoDocumentsStore.models.length === 0) {
if (this.collection.size() === 0) {
$('.dataTables_empty').text('No documents');
}
else {
$.each(window.arangoDocumentsStore.models, function(key, value) {
this.collection.each(function(value, key) {
var tempObj = {};
$.each(value.attributes.content, function(k, v) {
if (! (k === '_id' || k === '_rev' || k === '_key')) {
@ -546,67 +547,34 @@
});
arangoHelper.fixTooltips(".icon_arangodb, .arangoicon", "top");
this.drawTable();
this.renderPaginationElements();
return this;
},
showLoadingState: function () {
$('.dataTables_empty').text('Loading...');
rerender : function () {
this.clearTable();
this.collection.getDocuments();
this.drawTable();
$('#documents_last').css("visibility", "hidden");
$('#documents_first').css("visibility", "hidden");
this.renderPagination()
},
renderPagination: function (totalPages, checkFilter) {
$('#documentsToolbarF').html("");
var self = this;
var currentPage;
if (checkFilter) {
currentPage = window.arangoDocumentsStore.currentFilterPage;
}
else {
currentPage = JSON.parse(this.pageid);
}
var target = $('#documentsToolbarF'),
options = {
left: 2,
right: 2,
page: currentPage,
lastPage: totalPages,
click: function(i) {
options.page = i;
if (checkFilter) {
var filterArray = self.getFilterContent();
var filters = filterArray[0];
var bindValues = filterArray[1];
self.addDocumentSwitch = false;
renderPaginationElements: function () {
window.documentsView.clearTable();
window.arangoDocumentsStore.getFilteredDocuments(self.colid, i, filters, bindValues);
//Hide first/last pagination
$('#documents_last').css("visibility", "hidden");
$('#documents_first').css("visibility", "hidden");
}
else {
var windowLocationHash = '#collection/' + self.colid + '/documents/' + options.page;
window.location.hash = windowLocationHash;
}
}
};
target.pagination(options);
$('#documentsToolbarF').prepend(
'<ul class="pre-pagi"><li><a id="documents_first" class="pagination-button">'+
'<span><i class="fa fa-angle-double-left"/></span></a></li></ul>');
$('#documentsToolbarF').append(
'<ul class="las-pagi"><li><a id="documents_last" class="pagination-button">'+
'<span><i class="fa fa-angle-double-right"/></span></a></li></ul>');
var total = $('#totalDocuments');
this.renderPagination();
var total = $('#totalDocuments');
if (total.length > 0) {
total.html("Total: " + this.documentsCount + " documents");
} else {
$('#documentsToolbarFL').append(
'<a id="totalDocuments" class="totalDocuments">Total: ' + this.documentsCount +
'<a id="totalDocuments" class="totalDocuments">Total: ' + this.collection.getTotal() +
' document(s) </a>'
);
}
},
breadcrumb: function () {
this.collectionName = window.location.hash.split("/")[1];
$('#transparentHeader').append(

View File

@ -3,9 +3,10 @@
(function() {
"use strict";
window.NewLogsView = Backbone.View.extend({
window.NewLogsView = window.PaginationView.extend({
el: '#content',
id: '#logContent',
paginationDiv : "#logPaginationDiv",
initialize: function () {
this.convertModelToJSON();
@ -80,22 +81,8 @@
return this;
},
jumpTo: function(page) {
var self = this;
this.activeCollection.setPage(page);
this.activeCollection.fetch({
success: function() {
self.convertModelToJSON();
}
});
},
firstPage: function() {
this.jumpTo(1);
},
lastPage: function() {
this.jumpTo(this.activeCollection.getLastPageNumber());
rerender : function () {
this.convertModelToJSON();
},
renderPagination: function () {

View File

@ -135,6 +135,7 @@
"frontend/js/collections/_paginatedCollection.js",
"frontend/js/collections/newArangoLogs.js",
"frontend/js/views/_paginationView.js",
"frontend/js/views/modalView.js",
"frontend/js/views/navigationView.js",
"frontend/js/views/notificationView.js",

View File

@ -47,12 +47,12 @@
});
describe("getting documents", function() {
var colId, queryStart, queryEnd, sortStatement, filter1, filter2;
var colId, queryStart, queryEnd, sortStatement, filter1, filter2, ajaxCB;
beforeEach(function() {
colId = "12345";
col.setPage(5);
spyOn($, "ajax").andCallFake(function(obj) {
ajaxCB = function(obj) {
expect(_.isFunction(obj.success)).toBeTruthy();
expect(obj.url).toEqual("/_api/collection/" + colId + "/count");
expect(obj.type).toEqual("GET");
@ -60,6 +60,9 @@
obj.success({
count: 1000
});
};
spyOn($, "ajax").andCallFake(function(req) {
ajaxCB(req);
});
col.setCollection(colId);
expect(col.getPage()).toEqual(1);
@ -69,10 +72,11 @@
filter1 = " FILTER x.`test` == @param0";
filter2 = " && x.`second` < @param1";
queryEnd = " LIMIT @offset, @count RETURN x";
$.ajax.reset();
});
it("should start using first page", function() {
spyOn($, "ajax").andCallFake(function(req) {
ajaxCB = function(req) {
expect(req.url).toEqual('/_api/cursor');
expect(req.type).toEqual("POST");
expect(req.cache).toEqual(false);
@ -84,14 +88,14 @@
expect(data.bindVars.offset).toEqual(0);
expect(data.bindVars.count).toEqual(10);
expect(req.success).toEqual(jasmine.any(Function));
});
};
col.getDocuments();
expect($.ajax).toHaveBeenCalled();
});
it("should react to page changes", function() {
col.setPage(3);
spyOn($, "ajax").andCallFake(function(req) {
ajaxCB = function(req) {
expect(req.url).toEqual('/_api/cursor');
expect(req.type).toEqual("POST");
expect(req.cache).toEqual(false);
@ -103,14 +107,14 @@
expect(data.bindVars.offset).toEqual(20);
expect(data.bindVars.count).toEqual(10);
expect(req.success).toEqual(jasmine.any(Function));
});
};
col.getDocuments();
expect($.ajax).toHaveBeenCalled();
});
it("should not sort large collections", function() {
col.setTotal(10000);
spyOn($, "ajax").andCallFake(function(req) {
ajaxCB = function(req) {
expect(req.url).toEqual('/_api/cursor');
expect(req.type).toEqual("POST");
expect(req.cache).toEqual(false);
@ -122,14 +126,14 @@
expect(data.bindVars.offset).toEqual(0);
expect(data.bindVars.count).toEqual(10);
expect(req.success).toEqual(jasmine.any(Function));
});
};
col.getDocuments();
expect($.ajax).toHaveBeenCalled();
});
it("should be able to use one filter", function() {
col.addFilter("test", "==", "foxx");
spyOn($, "ajax").andCallFake(function(req) {
ajaxCB = function(req) {
expect(req.url).toEqual('/_api/cursor');
expect(req.type).toEqual("POST");
expect(req.cache).toEqual(false);
@ -142,7 +146,7 @@
expect(data.bindVars.count).toEqual(10);
expect(data.bindVars.param0).toEqual("foxx");
expect(req.success).toEqual(jasmine.any(Function));
});
};
col.getDocuments();
expect($.ajax).toHaveBeenCalled();
});
@ -150,7 +154,7 @@
it("should be able to use a second filter", function() {
col.addFilter("test", "==", "other");
col.addFilter("second", "<", "params");
spyOn($, "ajax").andCallFake(function(req) {
ajaxCB = function(req) {
expect(req.url).toEqual('/_api/cursor');
expect(req.type).toEqual("POST");
expect(req.cache).toEqual(false);
@ -164,7 +168,7 @@
expect(data.bindVars.param0).toEqual("other");
expect(data.bindVars.param1).toEqual("params");
expect(req.success).toEqual(jasmine.any(Function));
});
};
col.getDocuments();
expect($.ajax).toHaveBeenCalled();
});
@ -172,10 +176,10 @@
it("should insert the result of the query appropriatly", function() {
var f = {_id: "1/1", _rev: 2, _key: 1},
s = {_id: "1/2", _rev: 2, _key: 2},
t = {_id: "1/3", _rev: 2, _key: 3}
spyOn($, "ajax").andCallFake(function(req) {
t = {_id: "1/3", _rev: 2, _key: 3};
ajaxCB = function(req) {
req.success({result: [f, s, t], extra: {fullCount: 3}});
});
};
expect(col.getTotal()).not.toEqual(3);
col.getDocuments();
expect(col.getTotal()).toEqual(3);
@ -287,6 +291,7 @@
expect(res).toEqual("Upload error");
});
/*
it("start succesful Upload mit XHR ready state = 4, " +
"XHR status = 201 and not parseable JSON", function () {
spyOn($, "ajax").andCallFake(function (opt) {
@ -305,6 +310,7 @@
var res = col.updloadDocuments("a");
expect(res).toEqual('Error: SyntaxError: Unable to parse JSON string');
});
*/
});

View File

@ -41,7 +41,6 @@
var cols = [edgeCol, docCol, sysCol];
spyOn($, "ajax").andCallFake(function (url) {
console.log(url);
return {done:function() {}};
});
myStore = new window.arangoCollections(cols);

View File

@ -60,22 +60,21 @@
_key: "123",
_rev: "adasda",
_id: "paosdjfp1321"
}
var shouldObject = {
},
shouldObject = {
hello: 123,
wrong: true
}
},
result = view.removeReadonlyKeys(object);
var result = view.removeReadonlyKeys(object);
expect(result).toEqual(shouldObject);
});
it("should modify the breadcrumb", function () {
var bar = document.createElement("div");
var bar = document.createElement("div"),
emptyBar = document.createElement("div");
bar.id = 'transparentHeader';
var emptyBar = document.createElement("div");
view.breadcrumb();
expect(emptyBar).not.toBe(bar);