I am trying to remove a link from a node (TreeNode) which is nested inside a groupTemplate. My aim is to revert a dragging action (from a node to another) or the delete action of a link. At the moment, just to give you some hints, I am working on AngularJS declaring both GraphLinksModel arrays in the “controller.js” as below:
item = 4;
for(i=0; i< items; i++){
....
nodeDataArray.push({ isGroup: true, key: -i-1, text: "Board "+(i+1), color: "lightblue", fig: "RoundedRectangle", xy: x+" "+y });
}
...
linkDataArray.push({ key: 10000, from: 1000, to: 0, category: "Mapping", fromNode: "Board 2", toNode: "Board 1" });
$scope.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
$scope.model.linkFromPortIdProperty = "fromNode";
$scope.model.linkToPortIdProperty = "toNode";
while in the “directory.js” (which has the logic of the GraphLinksModel actions) i added the following:
myDiagram = $(go.Diagram, element[0],
{
...
"undoManager.isEnabled": false,
"ModelChanged": function(evt) {
if (evt.isTransactionFinished){
if(evt.as == "Initial Layout") document.getElementById("mySavedModel").value = evt.model.toJson();
else if(evt.as == "Delete" || evt.as == "Linking"){
...
old_linkarray = go.Model.fromJson(document.getElementById("mySavedModel").value).linkDataArray;
new_linkarray = evt.model.linkDataArray;
result = model_links_diff(old_linkarray, new_linkarray); //it returns some info and the difference (json object) between the old model and the new one (both saved in a div)
if(result.revert){
if(result.action == "mount"){
console.log("REVERT MOUNT");
myDiagram.startTransaction("mount action not allowed");
//AT THIS POINT: --> result.link = { key: 10000, from: 1000, to: 0, category: "Mapping", fromNode: "Board 2", toNode: "Board 1" };
myDiagram.model.removeLinkData(result.link);
myDiagram.commitTransaction("mount action not allowed");
...
So at this point I can do the addLinkData (not pasted here) transaction and it works but not the removeLinkData. What am I missing?
Thanks in advance…