mirror of https://gitee.com/bigwinds/arangodb
edit graph
This commit is contained in:
parent
0ed55b132b
commit
e6520a6bc0
|
@ -49,6 +49,27 @@
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addVertexCollection: function(vertexCollectionName) {
|
||||||
|
$.ajax(
|
||||||
|
{
|
||||||
|
async: false,
|
||||||
|
type: "POST",
|
||||||
|
url: this.urlRoot + "/" + this.get("_key") + "/vertex",
|
||||||
|
data: JSON.stringify({collection: vertexCollectionName})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteVertexCollection: function(vertexCollectionName) {
|
||||||
|
$.ajax(
|
||||||
|
{
|
||||||
|
async: false,
|
||||||
|
type: "DELETE",
|
||||||
|
url: this.urlRoot + "/" + this.get("_key") + "/vertex/" + vertexCollectionName
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
defaults: {
|
defaults: {
|
||||||
name: "",
|
name: "",
|
||||||
|
|
|
@ -121,7 +121,7 @@
|
||||||
|
|
||||||
saveEditedGraph: function() {
|
saveEditedGraph: function() {
|
||||||
var name = $("#editGraphName").html(),
|
var name = $("#editGraphName").html(),
|
||||||
vertexCollections = _.pluck($('#newVertexCollections').select2("data"), "text"),
|
editedVertexCollections = _.pluck($('#newVertexCollections').select2("data"), "text"),
|
||||||
edgeDefinitions = [],
|
edgeDefinitions = [],
|
||||||
newEdgeDefinitions = {},
|
newEdgeDefinitions = {},
|
||||||
self = this,
|
self = this,
|
||||||
|
@ -138,8 +138,8 @@
|
||||||
index = index.replace("s2id_newEdgeDefinitions", "");
|
index = index.replace("s2id_newEdgeDefinitions", "");
|
||||||
collection = _.pluck($('#s2id_newEdgeDefinitions' + index).select2("data"), "text")[0];
|
collection = _.pluck($('#s2id_newEdgeDefinitions' + index).select2("data"), "text")[0];
|
||||||
if (collection && collection !== "") {
|
if (collection && collection !== "") {
|
||||||
from = _.pluck($('#s2id_newFromCollections' + index).select2("data"), "text");
|
from = _.pluck($('#s2id_fromCollections' + index).select2("data"), "text");
|
||||||
to = _.pluck($('#s2id_newToCollections' + index).select2("data"), "text");
|
to = _.pluck($('#s2id_toCollections' + index).select2("data"), "text");
|
||||||
if (from !== 1 && to !== 1) {
|
if (from !== 1 && to !== 1) {
|
||||||
var edgeDefinition = {
|
var edgeDefinition = {
|
||||||
collection: collection,
|
collection: collection,
|
||||||
|
@ -159,12 +159,31 @@
|
||||||
var currentOrphanage = graph.get("orphanCollections");
|
var currentOrphanage = graph.get("orphanCollections");
|
||||||
var currentCollections = [];
|
var currentCollections = [];
|
||||||
|
|
||||||
|
//delete removed orphans
|
||||||
|
currentOrphanage.forEach(
|
||||||
|
function(oC) {
|
||||||
|
if (editedVertexCollections.indexOf(oC) === -1) {
|
||||||
|
graph.deleteVertexCollection(oC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//add new orphans
|
||||||
|
editedVertexCollections.forEach(
|
||||||
|
function(vC) {
|
||||||
|
if (currentOrphanage.indexOf(vC) === -1) {
|
||||||
|
graph.addVertexCollection(vC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//evaluate all new, edited and deleted edge definitions
|
//evaluate all new, edited and deleted edge definitions
|
||||||
var newEDs = [];
|
var newEDs = [];
|
||||||
var editedEDs = [];
|
var editedEDs = [];
|
||||||
var deletedEDs = [];
|
var deletedEDs = [];
|
||||||
|
|
||||||
|
|
||||||
currentEdgeDefinitions.forEach(
|
currentEdgeDefinitions.forEach(
|
||||||
function(eD) {
|
function(eD) {
|
||||||
var collection = eD.collection;
|
var collection = eD.collection;
|
||||||
|
@ -186,6 +205,8 @@
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
newEDs.forEach(
|
newEDs.forEach(
|
||||||
function(eD) {
|
function(eD) {
|
||||||
graph.addEdgeDefinition(newEdgeDefinitions[eD]);
|
graph.addEdgeDefinition(newEdgeDefinitions[eD]);
|
||||||
|
@ -309,8 +330,26 @@
|
||||||
|
|
||||||
createEditGraphModal: function(name, edgeDefinitions, orphanCollections) {
|
createEditGraphModal: function(name, edgeDefinitions, orphanCollections) {
|
||||||
var buttons = [],
|
var buttons = [],
|
||||||
|
collList = [],
|
||||||
|
eCollList = [],
|
||||||
tableContent = [],
|
tableContent = [],
|
||||||
|
collections = this.options.collectionCollection.models,
|
||||||
maxIndex;
|
maxIndex;
|
||||||
|
|
||||||
|
collections.forEach(function (c) {
|
||||||
|
if (c.get("isSystem")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
collList.push(c.id);
|
||||||
|
if (c.get('type') === "edge") {
|
||||||
|
|
||||||
|
eCollList.push(c.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.counter = 0;
|
||||||
|
window.modalView.enableHotKeys = false;
|
||||||
|
|
||||||
|
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
window.modalView.disableSubmitOnEnter = true;
|
window.modalView.disableSubmitOnEnter = true;
|
||||||
|
|
||||||
|
@ -335,9 +374,10 @@
|
||||||
"Some info for edge definitions",
|
"Some info for edge definitions",
|
||||||
"Edge definitions",
|
"Edge definitions",
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
true,
|
true,
|
||||||
true,
|
1,
|
||||||
1
|
eCollList
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -351,7 +391,8 @@
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
1
|
1,
|
||||||
|
eCollList
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -365,7 +406,8 @@
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
10
|
10,
|
||||||
|
collList
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
tableContent.push(
|
tableContent.push(
|
||||||
|
@ -378,7 +420,8 @@
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
10
|
10,
|
||||||
|
collList
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -391,7 +434,11 @@
|
||||||
orphanCollections,
|
orphanCollections,
|
||||||
"Some info for vertex collections",
|
"Some info for vertex collections",
|
||||||
"Vertex Collections",
|
"Vertex Collections",
|
||||||
false
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
10,
|
||||||
|
collList
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
buttons.push(
|
buttons.push(
|
||||||
|
@ -403,7 +450,7 @@
|
||||||
|
|
||||||
|
|
||||||
window.modalView.show(
|
window.modalView.show(
|
||||||
"modalGraphTable.ejs", "Add new Graph", buttons, tableContent, null, this.events
|
"modalGraphTable.ejs", "Edit Graph", buttons, tableContent, null, this.events
|
||||||
);
|
);
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
|
@ -527,8 +574,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
createNewGraphModal: function() {
|
createNewGraphModal: function() {
|
||||||
var buttons = [], collList = [], eCollList = [],
|
var buttons = [],
|
||||||
tableContent = [], collections = this.options.collectionCollection.models;
|
collList = [],
|
||||||
|
eCollList = [],
|
||||||
|
tableContent = [],
|
||||||
|
collections = this.options.collectionCollection.models;
|
||||||
|
|
||||||
collections.forEach(function (c) {
|
collections.forEach(function (c) {
|
||||||
if (c.get("isSystem")) {
|
if (c.get("isSystem")) {
|
||||||
|
@ -622,75 +672,6 @@
|
||||||
);
|
);
|
||||||
$('#row_fromCollections1').hide();
|
$('#row_fromCollections1').hide();
|
||||||
$('#row_toCollections1').hide();
|
$('#row_toCollections1').hide();
|
||||||
},
|
|
||||||
|
|
||||||
createEditGraphModal2: function(name, vertices, edgeDefinitions) {
|
|
||||||
var buttons = [],
|
|
||||||
tableContent = [];
|
|
||||||
|
|
||||||
this.counter = 0;
|
|
||||||
|
|
||||||
tableContent.push(
|
|
||||||
window.modalView.createReadOnlyEntry(
|
|
||||||
"graphName",
|
|
||||||
"Name",
|
|
||||||
name,
|
|
||||||
"The name to identify the graph. Has to be unique."
|
|
||||||
)
|
|
||||||
);
|
|
||||||
edgeDefinitions.forEach(function(ed) {
|
|
||||||
tableContent.push(
|
|
||||||
window.modalView.createReadOnlyEntry(
|
|
||||||
"edgeDefinitions" + this.counter,
|
|
||||||
"Edge definitions",
|
|
||||||
ed.collection,
|
|
||||||
"Some info for edge definitions"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
tableContent.push(
|
|
||||||
window.modalView.createSelect2Entry(
|
|
||||||
"fromCollections" + this.counter,
|
|
||||||
"fromCollections",
|
|
||||||
ed.from,
|
|
||||||
"The collection that contain the start vertices of the relation.",
|
|
||||||
"",
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
tableContent.push(
|
|
||||||
window.modalView.createSelect2Entry(
|
|
||||||
"toCollections" + this.counter,
|
|
||||||
"toCollections",
|
|
||||||
ed.to,
|
|
||||||
"The collection that contain the end vertices of the relation.",
|
|
||||||
"",
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
this.counter++;
|
|
||||||
});
|
|
||||||
|
|
||||||
tableContent.push(
|
|
||||||
window.modalView.createSelect2Entry(
|
|
||||||
"vertexCollections",
|
|
||||||
"Vertex collections",
|
|
||||||
vertices,
|
|
||||||
"Some info for vertex collections",
|
|
||||||
"Vertex Collections",
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
buttons.push(
|
|
||||||
window.modalView.createDeleteButton("Delete", this.deleteGraph.bind(this))
|
|
||||||
);
|
|
||||||
buttons.push(
|
|
||||||
window.modalView.createNeutralButton("Save", this.deleteGraph.bind(this))
|
|
||||||
);
|
|
||||||
|
|
||||||
window.modalView.show("modalGraphTable.ejs", "Edit Graph", buttons, tableContent);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue