|
824 | 824 | addNode: function () {
|
825 | 825 | var self = this;
|
826 | 826 |
|
827 |
| - var collectionId = $('.modal-body #new-node-collection-attr').val(); |
| 827 | + var collection = $('.modal-body #new-node-collection-attr').val(); |
828 | 828 | var key = $('.modal-body #new-node-key-attr').last().val();
|
829 | 829 |
|
830 | 830 | var callback = function (error, id, msg) {
|
831 | 831 | if (error) {
|
832 |
| - arangoHelper.arangoError('Could not create node', msg.errorMessage); |
| 832 | + arangoHelper.arangoError('Could not create node', msg); |
833 | 833 | } else {
|
834 | 834 | $('#emptyGraph').remove();
|
835 | 835 | self.currentGraph.graph.addNode({
|
|
850 | 850 | self.cameraToNode(self.currentGraph.graph.nodes(id));
|
851 | 851 | }
|
852 | 852 | };
|
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 | + } |
858 | 864 | }
|
| 865 | + |
| 866 | + this.collection.createNode(self.name, collection, data, callback); |
859 | 867 | },
|
860 | 868 |
|
861 | 869 | deleteEdgeModal: function (edgeId) {
|
|
905 | 913 | _.each(this.graphSettings.vertexCollections, function (val) {
|
906 | 914 | collections.push({
|
907 | 915 | label: val.name,
|
908 |
| - value: val.id |
| 916 | + value: val.name |
909 | 917 | });
|
910 | 918 | });
|
911 | 919 |
|
|
926 | 934 | )
|
927 | 935 | );
|
928 | 936 |
|
| 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 | + |
929 | 958 | tableContent.push(
|
930 | 959 | window.modalView.createSelectEntry(
|
931 | 960 | 'new-node-collection-attr',
|
|
956 | 985 | var from = self.contextState._from;
|
957 | 986 | var to = self.contextState._to;
|
958 | 987 |
|
959 |
| - var collectionName; |
| 988 | + var collection; |
960 | 989 | 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(); |
962 | 991 | } else {
|
963 |
| - collectionName = $('.modal-body #new-edge-collection-attr').val(); |
| 992 | + collection = $('.modal-body #new-edge-collection-attr').val(); |
964 | 993 | }
|
965 | 994 | var key = $('.modal-body #new-edge-key-attr').last().val();
|
966 | 995 |
|
967 |
| - var callback = function (error, data, msg) { |
| 996 | + var callback = function (error, id, msg) { |
968 | 997 | 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 | + |
970 | 1005 | 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; |
985 | 1007 | }
|
| 1008 | + self.currentGraph.graph.addEdge(edge); |
986 | 1009 |
|
987 | 1010 | // rerender graph
|
988 | 1011 | if (self.graphConfig) {
|
|
992 | 1015 | }
|
993 | 1016 | self.currentGraph.refresh();
|
994 | 1017 | } else {
|
995 |
| - arangoHelper.arangoError('Could not create edge', msg.errorMessage); |
| 1018 | + arangoHelper.arangoError('Could not create edge', msg); |
996 | 1019 | }
|
997 | 1020 |
|
998 | 1021 | // then clear states
|
999 | 1022 | self.clearOldContextMenu(true);
|
1000 | 1023 | window.modalView.hide();
|
1001 | 1024 | };
|
1002 | 1025 |
|
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; |
1007 | 1032 | }
|
| 1033 | + this.collection.createEdge(self.name, collection, data, callback); |
1008 | 1034 | },
|
1009 | 1035 |
|
1010 | 1036 | addEdgeModal: function (edgeDefinitions) {
|
|
1053 | 1079 | 'new-edge-collection-attr',
|
1054 | 1080 | 'Edge collection',
|
1055 | 1081 | edgeDefinitions[0],
|
1056 |
| - 'The edges collection to be used.' |
| 1082 | + 'The edge collection to be used.' |
1057 | 1083 | )
|
1058 | 1084 | );
|
1059 | 1085 | }
|
|
1980 | 2006 |
|
1981 | 2007 | // validate edgeDefinitions
|
1982 | 2008 | 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 | + } |
1985 | 2015 | } else {
|
1986 | 2016 | if (!self.dragging) {
|
1987 | 2017 | if (self.contextState.createEdge === true) {
|
|
0 commit comments