8000 ui: better smart graph support · jsxtech/arangodb@bfda3d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit bfda3d4

Browse files
committed
ui: better smart graph support
1 parent e12ba2a commit bfda3d4

File tree

3 files changed

+110
-35
lines changed

3 files changed

+110
-35
lines changed

js/apps/system/_admin/aardvark/APP/aardvark.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@ authRouter.get('/graph/:name', function (req, res) {
379379
vertexCollections: vertexCollections
380380
}
381381
};
382+
if (isEnterprise) {
383+
if (graph.__isSmart) {
384+
toReturn.settings.isSmart = graph.__isSmart;
385+
toReturn.settings.smartGraphAttribute = graph.__smartGraphAttribute;
386+
}
387+
}
382388
} else {
383389
var aqlQuery;
384390
if (config.query) {
@@ -607,6 +613,12 @@ authRouter.get('/graph/:name', function (req, res) {
607613
startVertex: startVertex
608614
}
609615
};
616+
if (isEnterprise) {
617+
if (graph.__isSmart) {
618+
toReturn.settings.isSmart = graph.__isSmart;
619+
toReturn.settings.smartGraphAttribute = graph.__smartGraphAttribute;
620+
}
621+
}
610622
}
611623

612624
res.json(toReturn);

js/apps/system/_admin/aardvark/APP/frontend/js/collections/graphCollection.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@
2929
});
3030
},
3131

32+
createNode: function (gName, gCollection, data, callback) {
33+
$.ajax({
34+
type: 'POST',
35+
url: arangoHelper.databaseUrl('/_api/gharial/') + encodeURIComponent(gName) + '/vertex/' + encodeURIComponent(gCollection),
36+
contentType: 'application/json',
37+
data: JSON.stringify(data),
38+
processData: true,
39+
success: function (response) {
40+
callback(false, response.vertex._id);
41+
},
42+
error: function (response) {
43+
callback(true, null, response.responseJSON.errorMessage);
44+
}
45+
});
46+
},
47+
48+
createEdge: function (gName, gCollection, data, callback) {
49+
$.ajax({
50+
cache: false,
51+
type: < 67E6 span class=pl-s>'POST',
52+
url: arangoHelper.databaseUrl('/_api/gharial/') + encodeURIComponent(gName) + '/edge/' + encodeURIComponent(gCollection),
53+
data: JSON.stringify(data),
54+
contentType: 'application/json',
55+
processData: false,
56+
success: function (response) {
57+
callback(false, response.edge._id);
58+
},
59+
error: function (response) {
60+
callback(true, null, response.responseJSON.errorMessage);
61+
}
62+
});
63+
},
64+
3265
comparator: function (item, item2) {
3366
var a = item.get('_key') || '';
3467
var b = item2.get('_key') || '';

js/apps/system/_admin/aardvark/APP/frontend/js/views/graphViewer.js

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,12 @@
824824
addNode: function () {
825825
var self = this;
826826

827-
var collectionId = $('.modal-body #new-node-collection-attr').val();
827+
var collection = $('.modal-body #new-node-collection-attr').val();
828828
var key = $('.modal-body #new-node-key-attr').last().val();
829829

830830
var callback = function (error, id, msg) {
831831
if (error) {
832-
arangoHelper.arangoError('Could not create node', msg.errorMessage);
832+
arangoHelper.arangoError('Could not create node', msg);
833833
} else {
834834
$('#emptyGraph').remove();
835835
self.currentGraph.graph.addNode({
@@ -850,12 +850,20 @@
850850
self.cameraToNode(self.currentGraph.graph.nodes(id));
851851
}
852852
};
853-
854-
if (key !== '' || key !== undefined) {
855-
this.documentStore.createTypeDocument(collectionId, key, callback);
856-
} else {
857-
this.documentStore.createTypeDocument(collectionId, null, callback);
853+
var data = {};
854+
if (key !== '' && key !== undefined) {
855+
data._key = key;
856+
}
857+
if (this.graphSettings.isSmart) {
858+
var smartAttribute = $('#new-smart-key-attr').val();
859+
if (smartAttribute !== '' && smartAttribute !== undefined) {
860+
data[this.graphSettings.smartGraphAttribute] = smartAttribute;
861+
} else {
862+
data[this.graphSettings.smartGraphAttribute] = null;
863+
}
858864
}
865+
866+
this.collection.createNode(self.name, collection, data, callback);
859867
},
860868

861869
deleteEdgeModal: function (edgeId) {
@@ -905,7 +913,7 @@
905913
_.each(this.graphSettings.vertexCollections, function (val) {
906914
collections.push({
907915
label: val.name,
908-
value: val.id
916+
value: val.name
909917
});
910918
});
911919

@@ -926,6 +934,27 @@
926934
)
927935
);
928936

937+
if (this.graphSettings.isSmart) {
938+
tableContent.push(
939+
window.modalView.createTextEntry(
940+
'new-smart-key-attr',
941+
this.graphSettings.smartGraphAttribute + '*',
942+
undefined,
943+
'The attribute value that is used to smartly shard the vertices of a graph. \n' +
944+
'Every vertex in this Graph has to have this attribute. \n' +
945+
'Cannot be modified later.',
946+
'Cannot 10000 be modified later.',
947+
false,
948+
[
949+
{
950+
rule: Joi.string().allow('').optional(),
951+
msg: ''
952+
}
953+
]
954+
)
955+
);
956+
}
957+
929958
tableContent.push(
930959
window.modalView.createSelectEntry(
931960
'new-node-collection-attr',
@@ -956,33 +985,27 @@
956985
var from = self.contextState._from;
957986
var to = self.contextState._to;
958987

959-
var collectionName;
988+
var collection;
960989
if ($('.modal-body #new-edge-collection-attr').val() === '') {
961-
collectionName = $('.modal-body #new-edge-collection-attr').text();
990+
collection = $('.modal-body #new-edge-collection-attr').text();
962991
} else {
963-
collectionName = $('.modal-body #new-edge-collection-attr').val();
992+
collection = $('.modal-body #new-edge-collection-attr').val();
964993
}
965994
var key = $('.modal-body #new-edge-key-attr').last().val();
966995

967-
var callback = function (error, data, msg) {
996+
var callback = function (error, id, msg) {
968997
if (!error) {
969-
// success
998+
var edge = {
999+
source: from,
1000+
target: to,
1001+
id: id,
1002+
color: self.graphConfig.edgeColor || self.ecolor
1003+
};
1004+
9701005
if (self.graphConfig.edgeEditable === 'true') {
971-
self.currentGraph.graph.addEdge({
972-
source: from,
973-
size: 1,
974-
target: to,
975-
id: data._id,
976-
color: self.graphConfig.edgeColor || self.ecolor
977-
});
978-
} else {
979-
self.currentGraph.graph.addEdge({
980-
source: from,
981-
target: to,
982-
id: data._id,
983-
color: self.graphConfig.edgeColor || self.ecolor
984-
});
1006+
edge.size = 1;
9851007
}
1008+
self.currentGraph.graph.addEdge(edge);
9861009

9871010
// rerender graph
9881011
if (self.graphConfig) {
@@ -992,19 +1015,22 @@
9921015
}
9931016
self.currentGraph.refresh();
9941017
} else {
995-
arangoHelper.arangoError('Could not create edge', msg.errorMessage);
1018+
arangoHelper.arangoError('Could not create edge', msg);
9961019
}
9971020

9981021
// then clear states
9991022
self.clearOldContextMenu(true);
10001023
window.modalView.hide();
10011024
};
10021025

1003-
if (key !== '' || key !== undefined) {
1004-
this.documentStore.createTypeEdge(collectionName, from, to, key, callback);
1005-
} else {
1006-
this.documentStore.createTypeEdge(collectionName, from, to, null, callback);
1026+
var data = {
1027+
_from: from,
1028+
_to: to
1029+
};
1030+
if (key !== '' && key !== undefined) {
1031+
data._key = key;
10071032
}
1033+
this.collection.createEdge(self.name, collection, data, callback);
10081034
},
10091035

10101036
addEdgeModal: function (edgeDefinitions) {
@@ -1053,7 +1079,7 @@
10531079
'new-edge-collection-attr',
10541080
'Edge collection',
10551081
edgeDefinitions[0],
1056-
'The edges collection to be used.'
1082+
'The edge collection to be used.'
10571083
)
10581084
);
10591085
}
@@ -1980,8 +2006,12 @@
19802006

19812007
// validate edgeDefinitions
19822008
var foundEdgeDefinitions = self.getEdgeDefinitionCollections(fromCollection, toCollection);
1983-
self.addEdgeModal(foundEdgeDefinitions, self.contextState._from, self.contextState._to);
1984-
self.clearOldContextMenu(false);
2009+
if (foundEdgeDefinitions.length === 0) {
2010+
arangoHelper.arangoNotification('Graph', 'No valid edge definition found.');
2011+
} else {
2012+
self.addEdgeModal(foundEdgeDefinitions, self.contextState._from, self.contextState._to);
2013+
self.clearOldContextMenu(false);
2014+
}
19852015
} else {
19862016
if (!self.dragging) {
19872017
if (self.contextState.createEdge === true) {

0 commit comments

Comments
 (0)
0