1
0
Fork 0

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

This commit is contained in:
Jan Steemann 2014-03-25 18:21:42 +01:00
commit 1ce382ffb3
22 changed files with 837 additions and 44 deletions

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true, newcap: true */
/*global window, $, Backbone, document, arangoCollection,arangoHelper, arangoDatabase, btoa, _*/
/*global window, $, Backbone, document, arangoCollectionModel,arangoHelper, arangoDatabase, btoa, _*/
(function() {
"use strict";

View File

@ -1,12 +1,12 @@
/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true, stupid: true*/
/*global require, exports, Backbone, window, arangoCollection, $, arangoHelper, data */
/*global require, exports, Backbone, window, arangoCollectionModel, $, arangoHelper, data */
(function() {
"use strict";
window.arangoCollections = Backbone.Collection.extend({
url: '/_api/collection',
model: arangoCollection,
model: arangoCollectionModel,
searchOptions : {
searchPhrase: null,

View File

@ -6,7 +6,7 @@
window.ArangoDatabase = Backbone.Collection.extend({
model: window.Database,
model: window.DatabaseModel,
comparator: function(item) { return item.get('name').toLowerCase(); },

View File

@ -1,7 +1,7 @@
/*jslint indent: 2, nomen: true, maxlen: 120, vars: true, white: true, plusplus: true */
/*global require, window, Backbone */
window.arangoCollection = Backbone.Model.extend({
window.arangoCollectionModel = Backbone.Model.extend({
initialize: function () {
'use strict';
},

View File

@ -1,7 +1,7 @@
/*jslint indent: 2, nomen: true, maxlen: 120, vars: true, white: true, plusplus: true */
/*global require, window, Backbone */
window.Database = Backbone.Model.extend({
window.DatabaseModel = Backbone.Model.extend({
idAttribute: "name",

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true, newcap: true */
/*global window, $, Backbone, document, arangoCollection,arangoHelper,dashboardView,arangoDatabase*/
/*global window, $, Backbone, document, arangoCollectionModel,arangoHelper,dashboardView,arangoDatabase*/
(function() {
"use strict";

View File

@ -90,7 +90,7 @@
"frontend/js/graphViewer/ui/graphViewerPreview.js",
"frontend/js/models/currentDatabase.js",
"frontend/js/models/arangoCollection.js",
"frontend/js/models/arangoCollectionModel.js",
"frontend/js/models/arangoDatabase.js",
"frontend/js/models/arangoDocument.js",
"frontend/js/models/arangoLog.js",
@ -200,11 +200,13 @@
"test/specs/models/currentDatabaseSpec.js",
"test/specs/models/graphSpec.js",
"test/specs/models/arangoCollectionSpec.js",
"test/specs/models/arangoCollectionModelSpec.js",
"test/specs/models/arangoDatabaseSpec.js",
"test/specs/models/arangoDocumentSpec.js",
"test/specs/models/arangoLogModelSpec.js",
"test/specs/models/arangoStatisticsDescriptionSpec.js",
"test/specs/models/arangoStatisticsSpec.js",
"test/specs/models/foxxSpec.js",
"test/specs/collections/clusterServersSpec.js",
"test/specs/collections/clusterDatabasesSpec.js",
@ -212,6 +214,8 @@
"test/specs/collections/clusterShardsSpec.js",
"test/specs/collections/arangoCollectionsSpec.js",
"test/specs/collections/arangoDatabaseSpec.js",
"test/specs/collections/arangoDocumentSpec.js",
"test/specs/collections/arangoDocumentsSpec.js",
"test/specs/views/editListEntryViewSpec.js",

View File

@ -47,13 +47,13 @@
it("should getPosition for loaded documents sorted by type", function() {
col.models = [
new window.arangoCollection({isSystem : true, name: "Heinz Herbert"}),
new window.arangoCollection({type : 'edge', name: "Heinz Herbert"}),
new window.arangoCollection({type: 'document', name: "Heinz Herbert Gustav"}),
new window.arangoCollection({type: 'document', name: "Heinz Herbert"}),
new window.arangoCollection({status: 'loaded', name: "Heinz Herbert Karl"}),
new window.arangoCollection({status: 'unloaded', name: "Heinz Herbert"}),
new window.arangoCollection({name: "Heinbert"})
new window.arangoCollectionModel({isSystem : true, name: "Heinz Herbert"}),
new window.arangoCollectionModel({type : 'edge', name: "Heinz Herbert"}),
new window.arangoCollectionModel({type: 'document', name: "Heinz Herbert Gustav"}),
new window.arangoCollectionModel({type: 'document', name: "Heinz Herbert"}),
new window.arangoCollectionModel({status: 'loaded', name: "Heinz Herbert Karl"}),
new window.arangoCollectionModel({status: 'unloaded', name: "Heinz Herbert"}),
new window.arangoCollectionModel({name: "Heinbert"})
];
col.searchOptions = {
searchPhrase: "Heinz Herbert",
@ -73,13 +73,13 @@
it("should getPosition for unloaded edges documents sorted by type", function() {
col.models = [
new window.arangoCollection({isSystem : true, name: "Heinz Herbert"}),
new window.arangoCollection({type : 'edge', name: "Heinz Herbert"}),
new window.arangoCollection({type: 'document', name: "Heinz Herbert Gustav"}),
new window.arangoCollection({type: 'document', name: "Heinz Herbert"}),
new window.arangoCollection({status: 'loaded', name: "Heinz Herbert Karl"}),
new window.arangoCollection({status: 'unloaded', name: "Heinz Herbert"}),
new window.arangoCollection({name: "Heinbert"})
new window.arangoCollectionModel({isSystem : true, name: "Heinz Herbert"}),
new window.arangoCollectionModel({type : 'edge', name: "Heinz Herbert"}),
new window.arangoCollectionModel({type: 'document', name: "Heinz Herbert Gustav"}),
new window.arangoCollectionModel({type: 'document', name: "Heinz Herbert"}),
new window.arangoCollectionModel({status: 'loaded', name: "Heinz Herbert Karl"}),
new window.arangoCollectionModel({status: 'unloaded', name: "Heinz Herbert"}),
new window.arangoCollectionModel({name: "Heinbert"})
];
col.searchOptions = {
searchPhrase: "Heinz Herbert",

View File

@ -0,0 +1,370 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global $*/
(function() {
"use strict";
describe("arangoDocument", function() {
var col;
beforeEach(function() {
col = new window.arangoDocument();
window.arangoDocumentStore = col;
});
it("should deleteEdge and succeed", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge/" + colid + "/" + docid);
expect(opt.type).toEqual("DELETE");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
opt.success();
});
var result = col.deleteEdge(colid, docid);
expect(result).toEqual(true);
});
it("should deleteEdge and fail", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge/" + colid + "/" + docid);
expect(opt.type).toEqual("DELETE");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
opt.error();
});
var result = col.deleteEdge(colid, docid);
expect(result).toEqual(false);
});
it("should deleteEdge and throw exception", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andThrow(XMLHttpRequestException);
var result = col.deleteEdge(colid, docid);
expect(result).toEqual(false);
});
it("should deleteDocument and succeed", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document/" + colid + "/" + docid);
expect(opt.type).toEqual("DELETE");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
opt.success();
});
var result = col.deleteDocument(colid, docid);
expect(result).toEqual(true);
});
it("should deleteDocument and fail", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document/" + colid + "/" + docid);
expect(opt.type).toEqual("DELETE");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
opt.error();
});
var result = col.deleteDocument(colid, docid);
expect(result).toEqual(false);
});
it("should deleteDocument and throw exception", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andThrow(XMLHttpRequestException);
var result = col.deleteDocument(colid, docid);
expect(result).toEqual(false);
});
it("should createTypeEdge and succeed", function() {
var collectionID = 1;
var from = 2;
var to = 3;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge?collection=" + collectionID + "&from=" + from + "&to=" + to);
expect(opt.type).toEqual("POST");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({}));
expect(opt.async).toEqual(false);
opt.success({_id : 100});
});
var result = col.createTypeEdge(collectionID, from, to);
expect(result).toEqual(100);
});
it("should createTypeEdge and fail", function() {
var collectionID = 1;
var from = 2;
var to = 3;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge?collection=" + collectionID + "&from=" + from + "&to=" + to);
expect(opt.type).toEqual("POST");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({}));
expect(opt.async).toEqual(false);
opt.error({});
});
var result = col.createTypeEdge(collectionID, from, to);
expect(result).toEqual(false);
});
it("should createTypeDocument and succeed", function() {
var collectionID = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document?collection=" + collectionID);
expect(opt.type).toEqual("POST");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({}));
expect(opt.async).toEqual(false);
opt.success({_id : 100});
});
var result = col.createTypeDocument(collectionID);
expect(result).toEqual(100);
});
it("should createTypeDocument and fail", function() {
var collectionID = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document?collection=" + collectionID);
expect(opt.type).toEqual("POST");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({}));
expect(opt.async).toEqual(false);
opt.error({});
});
var result = col.createTypeDocument(collectionID);
expect(result).toEqual(false);
});
it("should addDocument and succeed", function() {
var collectionID = 1;
spyOn(col, "createTypeDocument");
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document?collection=" + collectionID);
expect(opt.type).toEqual("POST");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({}));
expect(opt.async).toEqual(false);
opt.success({_id : 100});
});
var result = col.addDocument(collectionID);
expect(col.createTypeDocument).toHaveBeenCalled();
});
it("should getCollectionInfo and succeed", function() {
var identifier = 1;
spyOn(arangoHelper, "getRandomToken").andReturn("2");
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/collection/" + identifier + "?" + "2");
expect(opt.type).toEqual("GET");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.success({_id : 100});
});
var result = col.getCollectionInfo(identifier);
expect(result).toEqual({_id : 100});
});
it("should getCollectionInfo and fail", function() {
var identifier = 1;
spyOn(arangoHelper, "getRandomToken").andReturn("2");
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/collection/" + identifier + "?" + "2");
expect(opt.type).toEqual("GET");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.error({});
});
var result = col.getCollectionInfo(identifier);
expect(result).toEqual({});
});
it("should getEdge and succeed", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge/" + colid +"/"+ docid);
expect(opt.type).toEqual("GET");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.success("bla");
});
spyOn(window.arangoDocumentStore, "add");
var result = col.getEdge(colid, docid);
expect(result).toEqual(true);
expect(window.arangoDocumentStore.add).toHaveBeenCalledWith("bla");
});
it("should getEdge and fail", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge/" + colid +"/"+ docid);
expect(opt.type).toEqual("GET");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.error({});
});
var result = col.getEdge(colid, docid);
expect(result).toEqual(false);
});
it("should getDocument and succeed", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document/" + colid +"/"+ docid);
expect(opt.type).toEqual("GET");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.success("bla");
});
spyOn(window.arangoDocumentStore, "add");
var result = col.getDocument(colid, docid);
expect(result).toEqual(true);
expect(window.arangoDocumentStore.add).toHaveBeenCalledWith("bla");
});
it("should getDocument and fail", function() {
var docid = 1;
var colid = 1;
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document/" + colid +"/"+ docid);
expect(opt.type).toEqual("GET");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.error({});
});
var result = col.getDocument(colid, docid);
expect(result).toEqual(false);
});
it("should saveEdge and succeed", function() {
var docid = 1;
var colid = 1;
var model = {name : "heinz"};
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge/" + colid + "/" + docid);
expect(opt.type).toEqual("PUT");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(model);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.success("bla");
});
var result = col.saveEdge(colid, docid, model);
expect(result).toEqual(true);
});
it("should saveEdge and fail", function() {
var docid = 1;
var colid = 1;
var model = {name : "heinz"};
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/edge/" + colid + "/" + docid);
expect(opt.type).toEqual("PUT");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(model);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.error({});
});
var result = col.saveEdge(colid, docid, model);
expect(result).toEqual(false);
});
it("should saveDocument and succeed", function() {
var docid = 1;
var colid = 1;
var model = {name : "heinz"};
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document/" + colid + "/" + docid);
expect(opt.type).toEqual("PUT");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(model);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.success("bla");
});
var result = col.saveDocument(colid, docid, model);
expect(result).toEqual(true);
});
it("should saveDocument and fail", function() {
var docid = 1;
var colid = 1;
var model = {name : "heinz"};
spyOn($, "ajax").andCallFake(function(opt) {
expect(opt.url).toEqual("/_api/document/" + colid + "/" + docid);
expect(opt.type).toEqual("PUT");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.data).toEqual(model);
expect(opt.processData).toEqual(false);
expect(opt.async).toEqual(false);
opt.error({});
});
var result = col.saveDocument(colid, docid, model);
expect(result).toEqual(false);
});
it("should updateLocalDocument", function() {
spyOn(window.arangoDocumentStore, "reset");
var result = col.updateLocalDocument({x : "y"});
expect(window.arangoDocumentStore.reset).toHaveBeenCalled();
});
it("clearDocument", function() {
spyOn(window.arangoDocumentStore, "reset");
col.clearDocument();
expect(window.arangoDocumentStore.reset).toHaveBeenCalled();
});
});
}());

View File

@ -0,0 +1,290 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global $*/
(function() {
"use strict";
describe("arangoDocuments", function() {
var col;
beforeEach(function() {
window.documentsView = new window.DocumentsView();
col = new window.arangoDocuments();
window.arangoDocumentsStore = col;
});
it("should getFirstDocuments", function() {
col.currentPage = 2;
window.location.hash = "a/b/c"
col.getFirstDocuments();
expect(window.location.hash).toEqual("#a/b/c/1");
});
it("should getLastDocuments", function() {
col.currentPage = 2;
col.totalPages = 5;
window.location.hash = "a/b/c"
col.getLastDocuments();
expect(window.location.hash).toEqual("#a/b/c/5");
});
it("should getPrevDocuments", function() {
col.currentPage = 2;
window.location.hash = "a/b/c"
col.getPrevDocuments();
expect(window.location.hash).toEqual("#a/b/c/1");
});
it("should getNextDocuments", function() {
col.currentPage = 2;
col.totalPages = 5;
window.location.hash = "a/b/c"
col.getNextDocuments();
expect(window.location.hash).toEqual("#a/b/c/3");
});
it("should getDocuments and succeed", function() {
var colid = "12345";
var currpage = "0";
spyOn($, "ajax").andCallFake(function(opt) {
if (opt.type === "GET") {
expect(opt.url).toEqual("/_api/collection/" + colid + "/count");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
expect(opt.processData).toEqual(false);
opt.success({count : 100});
} else if (opt.type === "POST") {
expect(opt.url).toEqual('/_api/cursor');
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({
query : "FOR x in @@collection SORT TO_NUMBER(x._key) == 0 " +
"? x._key : TO_NUMBER(x._key) LIMIT @offset, @count RETURN x",
bindVars : {
"@collection" : colid,
"offset": 0,
"count": 10
}
}));
opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4},
{_id : 3, _rev : 2, _key : 4}]
});
}
});
spyOn(window.arangoDocumentsStore, "reset");
spyOn(window.documentsView, "drawTable");
spyOn(window.documentsView, "renderPagination");
spyOn(window.documentsView, "initTable");
var result = col.getDocuments(colid, currpage);
expect(window.documentsView.renderPagination).toHaveBeenCalledWith(10);
});
it("should getDocuments with exceeding sort count", function() {
var colid = "12345";
var currpage = "2";
spyOn($, "ajax").andCallFake(function(opt) {
if (opt.type === "GET") {
expect(opt.url).toEqual("/_api/collection/" + colid + "/count");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
expect(opt.processData).toEqual(false);
opt.success({count : 100000});
} else if (opt.type === "POST") {
expect(opt.url).toEqual('/_api/cursor');
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({
query : "FOR x in @@collection LIMIT @offset, @count RETURN x",
bindVars : {
"@collection" : colid,
"offset": 10,
"count": 10
}
}));
opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4},
{_id : 3, _rev : 2, _key : 4}]
});
}
});
spyOn(window.arangoDocumentsStore, "reset");
spyOn(window.documentsView, "drawTable");
spyOn(window.documentsView, "renderPagination");
spyOn(window.documentsView, "initTable");
var result = col.getDocuments(colid, currpage);
expect(window.documentsView.renderPagination).toHaveBeenCalledWith(10000);
});
it("should getDocuments with initial draw", function() {
var colid = "12345";
var currpage = "2";
spyOn($, "ajax").andCallFake(function(opt) {
if (opt.type === "GET") {
expect(opt.url).toEqual("/_api/collection/" + colid + "/count");
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
expect(opt.processData).toEqual(false);
opt.success({count : 0});
} else if (opt.type === "POST") {
expect(opt.url).toEqual('/_api/cursor');
expect(opt.contentType).toEqual("application/json");
expect(opt.cache).toEqual(false);
expect(opt.async).toEqual(false);
expect(opt.data).toEqual(JSON.stringify({
query : "FOR x in @@collection SORT TO_NUMBER(x._key) == 0 " +
"? x._key : TO_NUMBER(x._key) LIMIT @offset, @count RETURN x",
bindVars : {
"@collection" : colid,
"offset": 10,
"count": 10
}
}));
opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4},
{_id : 3, _rev : 2, _key : 4}]
});
}
});
spyOn(window.arangoDocumentsStore, "reset");
spyOn(window.documentsView, "drawTable");
spyOn(window.documentsView, "renderPagination");
spyOn(window.documentsView, "initTable");
var result = col.getDocuments(colid, currpage);
expect(window.documentsView.initTable).toHaveBeenCalled();
});
/*
getFilteredDocuments: function (colid, currpage, filter, bindValues) {
var self = this;
this.collectionID = colid;
this.currentPage = currpage;
this.currentFilterPage = currpage;
var filterString;
if(filter.length === 0){
filterString ="";
} else {
filterString = ' FILTER' + filter.join(' && ');
}
var sortCount = 10000;
var sortString = '';
if (this.documentsCount <= sortCount) {
//sorted
sortString = " SORT TO_NUMBER(u._key) == 0 ? u._key : TO_NUMBER(u._key)";
}
var myQueryVal = "FOR u in @@collection" + filterString + sortString +
" LIMIT @offset, @count RETURN u";
this.offset = (this.currentPage - 1) * this.documentsPerPage;
var myQuery = {
query: myQueryVal,
bindVars: {
"@collection": this.collectionID,
"count": this.documentsPerPage,
"offset": this.offset
},
options: {
fullCount: true
}
};
$.each(bindValues, function(k,v) {
myQuery.bindVars[k] = v;
});
$.ajax({
cache: false,
type: 'POST',
async: false,
url: '/_api/cursor',
data: JSON.stringify(myQuery),
contentType: "application/json",
success: function(data) {
self.clearDocuments();
self.documentsCount = data.extra.fullCount;
self.totalPages = Math.ceil(self.documentsCount / self.documentsPerPage);
if (
isNaN(this.currentPage)
|| this.currentPage === undefined
|| this.currentPage < 1
) {
this.currentPage = 1;
}
if (this.totalPages === 0) {
this.totalPages = 1;
}
this.offset = (this.currentPage - 1) * this.documentsPerPage;
if (self.documentsCount !== 0) {
$.each(data.result, function(k, v) {
window.arangoDocumentsStore.add({
"id": v._id,
"rev": v._rev,
"key": v._key,
"content": v
});
});
window.documentsView.drawTable();
window.documentsView.renderPagination(self.totalPages, true);
}
else {
window.documentsView.initTable();
window.documentsView.drawTable();
}
},
error: function(data) {
}
});
},
clearDocuments: function () {
window.arangoDocumentsStore.reset();
},
getStatisticsHistory: function(params) {
var self = this;
var body = {
startDate : params.startDate,
endDate : params.endDate,
figures : params.figures
};
var server = params.server;
var addAuth = function(){};
var url = "";
if (server) {
url = server.endpoint;
url += "/_admin/history";
if (server.isDBServer) {
url += "?DBserver=" + server.target;
}
addAuth = server.addAuth;
} else {
url = "/_admin/history";
}
$.ajax({
cache: false,
type: 'POST',
async: false,
url: url,
data: JSON.stringify(body),
contentType: "application/json",
beforeSend: addAuth,
success: function(data) {
self.history = data.result;
},
error: function(data) {
}
});
}
*/
});
}());

View File

@ -6,7 +6,7 @@
"use strict";
describe("Arango Collection Model", function() {
var myCollection = new window.arangoCollection();
var myCollection = new window.arangoCollectionModel();
it("verifies urlRoot", function() {
expect(myCollection.urlRoot).toEqual('/_api/collection');
});
@ -14,12 +14,12 @@
describe("Arango Database Model", function() {
it("verifies defaults", function() {
var myCollection = new window.arangoCollection();
var myCollection = new window.arangoCollectionModel();
expect(myCollection.get('id')).toEqual('');
expect(myCollection.get('name')).toEqual('');
expect(myCollection.get('status')).toEqual('');
expect(myCollection.get('type')).toEqual('');
expect(myCollection.isSystem).toBeFalsy();
expect(myCollection.get('isSystem')).toBeFalsy();
expect(myCollection.get('picture')).toEqual('');
});
});
@ -29,7 +29,7 @@
var name = 'blub',
status = 'active',
type = 'myType',
myCollection = new window.arangoCollection(
myCollection = new window.arangoCollectionModel(
{
name : name,
status : status,

View File

@ -6,17 +6,65 @@
"use strict";
describe("Arango Database Model", function() {
var model,
ajaxVerify;
beforeEach(function() {
model = new window.DatabaseModel(
{
name: 'myDatabase'
}
);
});
it("verifies isNew", function() {
var myDatabase = new window.Database();
expect(myDatabase.isNew()).toBeFalsy();
expect(model.isNew()).toBeFalsy();
});
});
describe("Arango Database Model", function() {
it("verifies url", function() {
var myDatabase = new window.Database();
expect(myDatabase.url).toEqual("/_api/database");
expect(model.url).toEqual("/_api/database");
});
});
it("verifies sync _create_", function() {
var myMethod = 'create',
myModel = model,
myOptions = '';
ajaxVerify = function(opt) {
expect(opt.url).toEqual('/_api/database');
expect(opt.type).toEqual('POST');
};
spyOn($, "ajax").andCallFake(function(opt) {
ajaxVerify(opt);
});
model.sync(myMethod, myModel, myOptions);
expect($.ajax).toHaveBeenCalled();
expect(model.url).toEqual("/_api/database");
});
it("verifies sync _update_", function() {
var myMethod = 'update',
myModel = model,
myOptions = '';
ajaxVerify = function(opt) {
expect(opt.url).toEqual('/_api/database');
expect(opt.type).toEqual('POST');
};
spyOn($, "ajax").andCallFake(function(opt) {
ajaxVerify(opt);
});
model.sync(myMethod, myModel, myOptions);
expect($.ajax).toHaveBeenCalled();
expect(model.url).toEqual("/_api/database");
});
});
}());

View File

@ -0,0 +1,29 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global $*/
(function() {
"use strict";
describe("Arango Log Model", function() {
var model;
beforeEach(function() {
model = new window.arangoLog();
});
it("verifies urlRoot", function() {
expect(model.urlRoot).toEqual('/_admin/log');
});
it("verifies defaults", function() {
expect(model.get('lid')).toEqual('');
expect(model.get('level')).toEqual('');
expect(model.get('timestamp')).toEqual('');
expect(model.get('text')).toEqual('');
expect(model.get('totalAmount')).toEqual('');
});
});
}());

View File

@ -20,7 +20,6 @@
});
model.fetch();
});
});
}());

View File

@ -0,0 +1,51 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global $*/
(function() {
"use strict";
describe("foxx Model", function() {
it("verifies url without _key", function() {
var myFoxx = new window.Foxx();
expect(myFoxx.url())
.toEqual("/_admin/aardvark/foxxes/install");
});
});
describe("foxx Model", function() {
it("verifies url with _key", function() {
var key = 'key',
myFoxx = new window.Foxx(
{
_key: key
}
);
expect(myFoxx.url())
.toEqual("/_admin/aardvark/foxxes/" + key);
});
});
describe("foxx Model", function() {
it("verifies defaults", function() {
var myFoxx = new window.Foxx();
expect(myFoxx.get('title')).toEqual('');
expect(myFoxx.get('version')).toEqual('');
expect(myFoxx.get('mount')).toEqual('');
expect(myFoxx.get('description')).toEqual('');
expect(myFoxx.get('git')).toEqual('');
expect(myFoxx.get('isSystem')).toBeFalsy();
expect(myFoxx.get('development')).toBeFalsy();
});
});
describe("foxx Model", function() {
it("verifies isNew", function() {
var myFoxx = new window.Foxx();
expect(myFoxx.isNew()).toBeFalsy();
});
});
}());

View File

@ -72,6 +72,8 @@
expect($.ajax).toHaveBeenCalled();
});
});
}());

View File

@ -1,7 +1,7 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global runs, waitsFor, jasmine*/
/*global $, arangoCollection*/
/*global $, arangoCollectionModel*/
(function() {
"use strict";

View File

@ -1,7 +1,7 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global runs, waitsFor, jasmine*/
/*global $, arangoCollection*/
/*global $, arangoCollectionModel*/
(function() {
"use strict";

View File

@ -16,7 +16,7 @@
beforeEach(function() {
var createCol = function(name, type, isSystem) {
return new window.arangoCollection({
return new window.arangoCollectionModel({
id: name,
type: type,
isSystem: isSystem || false,

View File

@ -1,7 +1,7 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global runs, waitsFor, jasmine*/
/*global $, arangoCollection*/
/*global $, arangoCollectionModel*/
(function() {
"use strict";
@ -17,7 +17,7 @@
$('body').append('<div id="content" class="removeMe"></div>');
myView = new window.CollectionView({
model: arangoCollection
model: arangoCollectionModel
});
});

View File

@ -16,21 +16,21 @@
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
edgeCol = new window.arangoCollection({
edgeCol = new window.arangoCollectionModel({
id: "e",
type: "edge",
isSystem: false,
name: "e",
status: "loaded"
});
docCol = new window.arangoCollection({
docCol = new window.arangoCollectionModel({
id: "d",
type: "document",
isSystem: false,
name: "d",
status: "loaded"
});
sysCol = new window.arangoCollection({
sysCol = new window.arangoCollectionModel({
id: "s",
type: "document",
isSystem: true,

View File

@ -36,7 +36,7 @@
beforeEach(function() {
var createCol = function(name, type, isSystem) {
return new window.arangoCollection({
return new window.arangoCollectionModel({
id: name,
type: type,
isSystem: isSystem || false,