1
0
Fork 0

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

This commit is contained in:
gschwab 2014-06-30 15:22:52 +02:00
commit 32f997bf8f
2 changed files with 493 additions and 49 deletions

View File

@ -180,14 +180,12 @@
}
}
);
//if no edge definition is left
if (edgeDefinitions.length === 0) {
$('#s2id_newEdgeDefinitions0 .select2-choices').css("border-color", "red");
return;
}
//get current edgeDefs/orphanage
var graph = this.collection.findWhere({_key: name});
var currentEdgeDefinitions = graph.get("edgeDefinitions");
@ -202,7 +200,6 @@
}
}
);
//add new orphans
editedVertexCollections.forEach(
function(vC) {
@ -212,7 +209,6 @@
}
);
//evaluate all new, edited and deleted edge definitions
var newEDs = [];
var editedEDs = [];
@ -259,7 +255,6 @@
graph.deleteEdgeDefinition(eD);
}
);
this.updateGraphManagementView();
window.modalView.hide();
},
@ -315,6 +310,13 @@
index,
edgeDefinitionElements;
if (!name) {
arangoHelper.arangoError(
"A name for the graph has to be provided."
);
return 0;
}
if (this.collection.findWhere({_key: name})) {
arangoHelper.arangoError(
"The graph '" + name + "' already exists."
@ -343,12 +345,7 @@
}
}
);
if (!name) {
arangoHelper.arangoError(
"A name for the graph has to be provided."
);
return 0;
}
this.collection.create({
name: name,
edgeDefinitions: edgeDefinitions,

View File

@ -1,6 +1,6 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, runs, expect, waitsFor*/
/*global spyOn, runs, expect, waitsFor, arangoHelper*/
/*global GraphManagementView, _, jasmine, $*/
(function () {
@ -40,6 +40,22 @@
document.body.removeChild(modalDiv);
});
it("should updateGraphManagementView", function () {
spyOn(view.collection, "fetch").andCallFake(function (a) {
a.success();
});
spyOn(view, "render");
view.updateGraphManagementView();
expect(view.render).toHaveBeenCalled();
});
it("should fetch the graphs on render", function () {
spyOn(graphs, "fetch");
view.render();
@ -112,7 +128,7 @@
return "blabalblub";
},
width : function () {
return 100
return 100;
},
html : function () {
@ -209,8 +225,8 @@
to: ["blob"]
}],
orphanCollections: []
});
var e = {
}),
e = {
currentTarget: {
id: "blabalblub"
},
@ -260,8 +276,7 @@
to: ["blob"]
}],
orphanCollections: []
});
var e = {
}), e = {
currentTarget: {
id: "blabalblub"
},
@ -299,7 +314,8 @@
});
it("should not set to and from for added definition as already in use and has been entered manually", function () {
it("should not set to and from for added definition as already in " +
"use and has been entered manually", function () {
view.removedECollList = ["moppel"];
var model = view.collection.create({
_key: "blub2",
@ -310,8 +326,7 @@
to: ["blob"]
}],
orphanCollections: []
});
var e = {
}), e = {
currentTarget: {
id: "blabalblub"
},
@ -349,7 +364,8 @@
});
it("should not set to and from for removed definition as already in use and has been entered manually", function () {
it("should not set to and from for removed definition as " +
"already in use and has been entered manually", function () {
view.removedECollList = ["moppel"];
var model = view.collection.create({
_key: "blub2",
@ -360,8 +376,7 @@
to: ["blob"]
}],
orphanCollections: []
});
var e = {
}), e = {
currentTarget: {
id: "blabalblub"
},
@ -390,8 +405,8 @@
view.setFromAndTo(e);
expect(e.stopPropagation).toHaveBeenCalled();
expect(view.removedECollList.indexOf("moppel")).toEqual(-1)
expect(view.eCollList.indexOf("moppel")).not.toEqual(-1)
expect(view.removedECollList.indexOf("moppel")).toEqual(-1);
expect(view.eCollList.indexOf("moppel")).not.toEqual(-1);
model.destroy();
@ -413,19 +428,74 @@
spyOn(window.modalView, "show");
view.options.collectionCollection.add({name : "NONSYSTEM", isSystem : false, type : "edge"});
view.options.collectionCollection.add({name : "SYSTEM", isSystem : true, type : 'document'});
view.options.collectionCollection.add(
{name : "NONSYSTEM", isSystem : false, type : "edge"});
view.options.collectionCollection.add(
{name : "SYSTEM", isSystem : true, type : 'document'});
view.editGraph(e);
expect(e.stopPropagation).toHaveBeenCalled();
expect(view.removedECollList.length).toEqual(0)
expect(view.eCollList.length).not.toEqual(0)
expect(view.removedECollList.length).toEqual(0);
expect(view.eCollList.length).not.toEqual(0);
expect(window.modalView.show).toHaveBeenCalled();
});
it("should search", function () {
var a = {
val : function () {
return "searchString";
},
html: function () {
return "";
},
focus: function () {
return "";
},
0 : {setSelectionRange: function () {
return "";
}}
}, g = {
_key: "blub2",
name: "blub2",
edgeDefinitions: [{
collection: "blub",
from: ["bla"],
to: ["blob"]
},{
collection: "blub2",
from: ["bla"],
to: ["blob"]
}],
orphanCollections: [],
get : function (a) {
return g[a];
}
};
spyOn(view.collection, "filter").andCallFake(function (a) {
a(g);
return g;
});
spyOn(window, "$").andReturn(a);
spyOn(view.template, "render");
view.search();
expect(view.template.render).toHaveBeenCalledWith({
graphs : g,
searchString : "searchString"
});
});
it("should create edit graph modal in edit mode", function () {
var g = {
@ -442,15 +512,9 @@
}],
orphanCollections: [],
get : function (a) {
return g[a]
return g[a];
}
};
spyOn(view.collection, "findWhere").andReturn(
g
);
var e = {
}, e = {
currentTarget: {
id: "blabalblub"
},
@ -459,32 +523,201 @@
removed : {id : "moppel"}
};
spyOn(view.collection, "findWhere").andReturn(
g
);
spyOn(e, "stopPropagation");
spyOn(window.modalView, "show");
view.options.collectionCollection.add({name : "NONSYSTEM", isSystem : false, type : "edge"});
view.options.collectionCollection.add({name : "SYSTEM", isSystem : true, type : 'document'});
view.options.collectionCollection.add(
{name : "NONSYSTEM", isSystem : false, type : "edge"});
view.options.collectionCollection.add(
{name : "SYSTEM", isSystem : true, type : 'document'});
view.editGraph(e);
expect(e.stopPropagation).toHaveBeenCalled();
expect(view.removedECollList.length).toEqual(1)
expect(view.eCollList.length).toEqual(0)
expect(view.removedECollList.length).toEqual(1);
expect(view.eCollList.length).toEqual(0);
expect(window.modalView.show).toHaveBeenCalled();
});
/*editGraph : function(e) {
e.stopPropagation();
this.collection.fetch();
this.graphToEdit = this.evaluateGraphName($(e.currentTarget).attr("id"), '_settings');
var graph = this.collection.findWhere({_key: this.graphToEdit});
this.createEditGraphModal(
graph
it("should not saveEditedGraph as no defintions are supplied", function () {
var
a = {
p : "",
setParam : function (p) {
a.p = p;
},
select2: function () {
if (a.p === "#newVertexCollections") {
return "newVertexCollections";
}
if (a.p === "#s2id_newEdgeDefinitions1") {
return "collection";
}
if (a.p === "#s2id_fromCollections1") {
return "fromCollection";
}
if (a.p === "#s2id_toCollections1") {
return "toCollection";
}
},
attr : function () {
if (a.p.indexOf("edgeD") !== -1) {
return "1";
}
},
toArray: function () {
if (a.p === "[id^=s2id_newEdgeDefinitions]") {
return ["edgeD1", "edgeD2", "edgeD3"];
}
},
css : function () {
},
0 : {value : "name"}
};
spyOn(_, "pluck").andCallFake(function (s, b) {
if (s === "newVertexCollections") {
return ["orphan1", "orphan2", "orphan3"];
}
if (s === "collection") {
return [undefined];
}
if (s === "fromCollection") {
return ["fromCollection"];
}
if (s === "toCollection") {
return ["toCollection"];
}
});
spyOn(window, "$").andCallFake(function (x) {
a.setParam(x);
return a;
});
spyOn(view, "updateGraphManagementView");
view.saveEditedGraph();
expect(view.updateGraphManagementView).not.toHaveBeenCalled();
});
it("should saveEditedGraph", function () {
var
a = {
p : "",
setParam : function (p) {
a.p = p;
},
select2: function () {
if (a.p === "#newVertexCollections") {
return "newVertexCollections";
}
if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) {
return a.p.split("#s2id_newEdgeDefinitions")[1];
}
if (a.p.indexOf("#s2id_fromCollections") !== -1) {
return "fromCollection";
}
if (a.p.indexOf("#s2id_toCollections") !== -1) {
return "toCollection";
}
},
attr : function () {
if (a.p.indexOf("edgeD") !== -1) {
return a.p;
}
},
toArray: function () {
if (a.p === "[id^=s2id_newEdgeDefinitions]") {
return ["edgeD1", "edgeD2", "edgeD3"];
}
},
0 : {value : "name"}
}, g = {
_key: "blub2",
name: "blub2",
edgeDefinitions: [{
collection: "blub",
from: ["bla"],
to: ["blob"]
},{
collection: "collection2",
from: ["bla"],
to: ["blob"]
}],
orphanCollections: ["o1", "o2", "o3"],
get : function (a) {
return g[a];
},
deleteVertexCollection : function (o) {
g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1);
},
addVertexCollection : function (o) {
g.orphanCollections.push(o);
},
addEdgeDefinition : function (o) {
g.edgeDefinitions.push(o);
},
modifyEdgeDefinition : function (o) {
},
deleteEdgeDefinition : function (o) {
g.edgeDefinitions.forEach(function (e) {
if (e.collection === o.collection) {
delete g.edgeDefinitions[e];
}
});
}
};
spyOn(_, "pluck").andCallFake(function (s, b) {
if (s === "newVertexCollections") {
return ["orphan1", "orphan2", "orphan3"];
}
if (s.indexOf("edgeD") !== -1) {
return ["collection" + s.split("edgeD")[1] ];
}
if (s === "fromCollection") {
return ["fromCollection"];
}
if (s === "toCollection") {
return ["toCollection"];
}
});
spyOn(window, "$").andCallFake(function (x) {
a.setParam(x);
return a;
});
spyOn(view.collection, "findWhere").andReturn(
g
);
},*/
spyOn(view, "updateGraphManagementView");
spyOn(window.modalView, "hide");
view.saveEditedGraph();
expect(view.updateGraphManagementView).toHaveBeenCalled();
expect(window.modalView.hide).toHaveBeenCalled();
});
it("should create a sorted list of all graphs", function () {
var list = $("div.tile h5.collectionName", "#graphManagementThumbnailsIn");
@ -495,6 +728,220 @@
expect($(list[2]).html()).toEqual(g3._key);
});
it("should not saveCreatedGraph as name already exists", function () {
var
a = {
p : "",
setParam : function (p) {
a.p = p;
},
select2: function () {
if (a.p === "#newVertexCollections") {
return "newVertexCollections";
}
if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) {
return a.p.split("#s2id_newEdgeDefinitions")[1];
}
if (a.p.indexOf("#s2id_fromCollections") !== -1) {
return "fromCollection";
}
if (a.p.indexOf("#s2id_toCollections") !== -1) {
return "toCollection";
}
},
attr : function () {
if (a.p.indexOf("edgeD") !== -1) {
return a.p;
}
},
toArray: function () {
if (a.p === "[id^=s2id_newEdgeDefinitions]") {
return ["edgeD1", "edgeD2", "edgeD3"];
}
},
val : function () {
return "name";
}
}, g = {
_key: "name",
name: "name",
edgeDefinitions: [{
collection: "blub",
from: ["bla"],
to: ["blob"]
},{
collection: "collection2",
from: ["bla"],
to: ["blob"]
}],
orphanCollections: ["o1", "o2", "o3"],
get : function (a) {
return g[a];
},
deleteVertexCollection : function (o) {
g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1);
},
addVertexCollection : function (o) {
g.orphanCollections.push(o);
},
addEdgeDefinition : function (o) {
g.edgeDefinitions.push(o);
},
modifyEdgeDefinition : function (o) {
},
deleteEdgeDefinition : function (o) {
g.edgeDefinitions.forEach(function (e) {
if (e.collection === o.collection) {
delete g.edgeDefinitions[e];
}
});
}
};
spyOn(_, "pluck").andCallFake(function (s, b) {
if (s === "newVertexCollections") {
return ["orphan1", "orphan2", "orphan3"];
}
if (s.indexOf("edgeD") !== -1) {
return ["collection" + s.split("edgeD")[1] ];
}
if (s === "fromCollection") {
return ["fromCollection"];
}
if (s === "toCollection") {
return ["toCollection"];
}
});
spyOn(window, "$").andCallFake(function (x) {
a.setParam(x);
return a;
});
spyOn(view.collection, "findWhere").andReturn(
g
);
spyOn(arangoHelper, "arangoError");
view.createNewGraph();
expect(arangoHelper.arangoError).toHaveBeenCalledWith(
"The graph '" + "name" + "' already exists.");
});
it("should not saveCreatedGraph as name is missing", function () {
var
a = {
p : "",
setParam : function (p) {
a.p = p;
},
select2: function () {
if (a.p === "#newVertexCollections") {
return "newVertexCollections";
}
if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) {
return a.p.split("#s2id_newEdgeDefinitions")[1];
}
if (a.p.indexOf("#s2id_fromCollections") !== -1) {
return "fromCollection";
}
if (a.p.indexOf("#s2id_toCollections") !== -1) {
return "toCollection";
}
},
attr : function () {
if (a.p.indexOf("edgeD") !== -1) {
return a.p;
}
},
toArray: function () {
if (a.p === "[id^=s2id_newEdgeDefinitions]") {
return ["edgeD1", "edgeD2", "edgeD3"];
}
},
val : function () {
return undefined;
}
}, g = {
_key: "name",
name: "name",
edgeDefinitions: [{
collection: "blub",
from: ["bla"],
to: ["blob"]
},{
collection: "collection2",
from: ["bla"],
to: ["blob"]
}],
orphanCollections: ["o1", "o2", "o3"],
get : function (a) {
return g[a];
},
deleteVertexCollection : function (o) {
g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1);
},
addVertexCollection : function (o) {
g.orphanCollections.push(o);
},
addEdgeDefinition : function (o) {
g.edgeDefinitions.push(o);
},
modifyEdgeDefinition : function (o) {
},
deleteEdgeDefinition : function (o) {
g.edgeDefinitions.forEach(function (e) {
if (e.collection === o.collection) {
delete g.edgeDefinitions[e];
}
});
}
};
spyOn(_, "pluck").andCallFake(function (s, b) {
if (s === "newVertexCollections") {
return ["orphan1", "orphan2", "orphan3"];
}
if (s.indexOf("edgeD") !== -1) {
return ["collection" + s.split("edgeD")[1] ];
}
if (s === "fromCollection") {
return ["fromCollection"];
}
if (s === "toCollection") {
return ["toCollection"];
}
});
spyOn(window, "$").andCallFake(function (x) {
a.setParam(x);
return a;
});
spyOn(view.collection, "findWhere").andReturn(
g
);
spyOn(arangoHelper, "arangoError");
view.createNewGraph();
expect(arangoHelper.arangoError).toHaveBeenCalledWith(
"A name for the graph has to be provided.");
});
describe("creating a new graph", function () {
it("should create a new empty graph", function () {