From 732afdec908e23e5a8779e862563135ea40746fa Mon Sep 17 00:00:00 2001 From: baigner <benedikt.aigner@rwth-aachen.de> Date: Tue, 15 May 2018 09:55:25 +0200 Subject: [PATCH] Right click options for variable lists work. Tool lists still to be done! Former-commit-id: f5ca5e46aafb945b94bfb58fae6ceff0fd42e522 --- kadmos/vistoms/templates/VISTOMS.html | 507 ++++++++++++-------------- 1 file changed, 231 insertions(+), 276 deletions(-) diff --git a/kadmos/vistoms/templates/VISTOMS.html b/kadmos/vistoms/templates/VISTOMS.html index de4254ed7..8f0b22ab2 100644 --- a/kadmos/vistoms/templates/VISTOMS.html +++ b/kadmos/vistoms/templates/VISTOMS.html @@ -18866,20 +18866,14 @@ $('.myPanel').lobiPanel('unpin'); } - + function markVariable(aNode,variableData) { - - function getFullXPath(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){return getFullXPath(data.parent,aText)} - else{return aText} - } - var path=""; - var xPath = getFullXPath(aNode, path); - d3.select('.d3-context-menu').style('display', 'none'); - + var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] + var xPath = "/"+firstFromSchema+aNode.data.xPath.split(firstFromSchema)[1]; + + d3.select('.d3-context-menu').style('display', 'none'); + var bootboxContent = {title: 'Marking variable as ' + variableData.variableType, message: '<p>Please be patient...</p>'}; var xhr = $.ajax({ type: 'POST', @@ -18933,17 +18927,8 @@ function unmarkVariable(aNode) { - var firstFromSchema = currentGraph.variableSchemes["schema"].name - function getFullXPath(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){return getFullXPath(data.parent,aText)} - else{return aText} - } - var path=""; - var xPath = getFullXPath(aNode, path); - var xPath_split = xPath.split(firstFromSchema)[1] - xPath = "/"+firstFromSchema+xPath_split; + var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] + var xPath = "/"+firstFromSchema+aNode.data.xPath.split(firstFromSchema)[1]; d3.select('.d3-context-menu').style('display', 'none'); @@ -19110,18 +19095,7 @@ { title: 'Copy x-path to clipboard', onMouseDown: function(elm, d, i) { - function copyToClipboard(text) - { - window.prompt("Copy to clipboard: Ctrl+C, Enter", text); - } - function copyXPathToClipboard(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){copyXPathToClipboard(data.parent,aText)} - else{copyToClipboard(aText);} - } - var copyText=""; - copyXPathToClipboard(d,copyText); + window.prompt("Copy to clipboard: Ctrl+C, Enter", d.data.xPath); d3.select('.d3-context-menu').style('display', 'none'); }, onMouseUp: function(elm, d, i) { @@ -19130,57 +19104,6 @@ }, childrenItems: [] }, - { - title: 'Download full tree as XML-file', - onMouseDown: function(elm, d, i) { - //Begin xml structure with the first element - var xmlString = "<"+nodes[0].data.name+">"+"</"+nodes[0].data.name+">"; - //Create a new xml document - var parser = new DOMParser(); - var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" - //Get initial xPath of the tree and pass it to the function "writeTreeToXML" - var initialXPath = "/"+nodes[0].data.name; - writeTreeToXML(nodes[0],xmlDocument,initialXPath); - //remove all attributes dummyID - removeAttributeInAllElements(xmlDocument,'dummyID'); - //Make the xml document a string - var serializer = new XMLSerializer(); - var xmlString = serializer.serializeToString(xmlDocument); - xmlString = vkbeautify.xml(xmlString); - //Download a document with the xml-schema - download(aName+'_full.xml',xmlString); - }, - onMouseUp: function(elm, d, i) { - }, - onMouseOver: function(elm, d, i) { - }, - childrenItems: [] - }, - { - title: 'Download tree as XML-file from current node', - onMouseDown: function(elm, d, i) { - var xmlString = putAncestorsInXMLString({ val : '' }, d).val; - var initialXPath = putAncestorsInXPath({ val : '' }, d).val; - //Create a new xml document - var parser = new DOMParser(); - var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" - //Get initial xPath of the tree and pass it to the function "writeCurrentTreeToXML" - writeTreeToXML(d,xmlDocument,initialXPath); - //remove all attributes dummyID - removeAttributeInAllElements(xmlDocument,'dummyID'); - //Make the xml document a string - var serializer = new XMLSerializer(); - xmlString = serializer.serializeToString(xmlDocument); - xmlString = vkbeautify.xml(xmlString); - //Download a document with the xml-schema - download(aName+"_"+d.data.name+'.xml',xmlString); - }, - onMouseUp: function(elm, d, i) { - }, - onMouseOver: function(elm, d, i) { - }, - childrenItems: [] - }, { title: 'Mark variable', onMouseDown: function(elm, d, i) {}, @@ -19202,169 +19125,8 @@ onMouseOver: function(elm, d, i) {}, childrenItems: [] } - ] - + ] - - - //Function writeTreeToXML goes through tree nodes and puts the into an xml document - function writeTreeToXML(aNode,anXMLDoc,anXPath) - { - //Variable "children" - //--> One children variable, no matter whether a node has "_children" (collapsed) or "children" (expanded) - var children; - if (aNode._children){children = aNode._children;} - else if (aNode.children){children = aNode.children;} - - //Get current xml element with its xPath - var element = anXMLDoc.evaluate(anXPath,anXMLDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; - if (element != null) {element.value = '...';} - - //If a node has children (collapsed or expanded), loop through them - if (children) - { - for (var i=0; i < children.length;i++) - { - //Name of the new XML element --> childName - var child = children[i]; - var childName = child.data.name.split(/[\[\]]+/);//Split childName at "[]" which is the uID - var cleanChildName = childName[0].split(/[\+\*\^\-\ \#]+/);//Split childName all special characters - var newNode = anXMLDoc.createElement(String(cleanChildName[0])); - - //The children are appended to the xPath --> newXPath - var newXPath = anXPath+"/"+cleanChildName[0]; - - //If childName contains a uID, make the uID an attribute - if (childName[1]) - { - if (parseInt(childName[1])) - { - var dummyID = childName[1]; - newNode.setAttribute("dummyID", dummyID) - newXPath = newXPath+"[@dummyID='"+dummyID+"']"; - } - else - { - var uID = childName[1]; - newNode.setAttribute("uID", uID) - newXPath = newXPath+"[@uID='"+uID+"']"; - } - } - if (cleanChildName.length>1) {newNode.setAttribute("elementName", childName[0])}; - - //Append the newNode to the xml structure - element.appendChild(newNode); - - - - ////aigner: Sorting of XML elements according to "uID" - // var items = element.children; - // var itemsArr = []; - // for (var j in items) { - // if (items[j].nodeType == 1) { // get rid of the whitespace text nodes - // itemsArr.push(items[j]); - // } - // } - // itemsArr.sort(function(a,b){ - // if (a.getAttribute("uID") < b.getAttribute("uID")) - // return -1; - // if (a.getAttribute("uID") > b.getAttribute("uID")) - // return 1; - // return 0; - // }); - - // for (j = 0; j < itemsArr.length; ++j) { - // element.appendChild(itemsArr[j]); - // } - - //call function writeTreeToXML recursively for all children - writeTreeToXML(child,anXMLDoc,newXPath) - } - } - else - { - if (aNode.data.value){element.innerHTML = String(aNode.data.value);} - else{element.innerHTML = " ";} - } - //return the xml document - return anXMLDoc; - } - - function removeAttributeInAllElements(aDocument,attribute) - { - var matchingElements = []; - var allElements = aDocument.getElementsByTagName('*'); - for (var i = 0, n = allElements.length; i < n; i++) - { - if (allElements[i].getAttribute(attribute) !== null) - { - allElements[i].removeAttribute(attribute); - } - } - return matchingElements; - } - - function putAncestorsInXMLString(strWrapper, aNode) - { - //Name of the new XML element - var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID - var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters - //If nodeName contains a uID, make the uID an attribute - if (nodeName[1]) - { - var uID = nodeName[1]; - strWrapper.val = "<"+cleanNodeName[0]+" uID='"+ uID +"'>"+strWrapper.val+"</"+cleanNodeName[0]+">";; - } - else - { - strWrapper.val = "<"+cleanNodeName[0]+">"+strWrapper.val+"</"+cleanNodeName[0]+">";; - } - var aParent = aNode.parent; - if (aParent) - { - return putAncestorsInXMLString(strWrapper, aParent); - } - else - { - return strWrapper; - } - } - - function putAncestorsInXPath(strWrapper, aNode) - { - //Name of the new XML element - var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID - var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters - //If nodeName contains a uID, make the uID an attribute - if (nodeName[1]) - { - var uID = nodeName[1]; - strWrapper.val = "/"+cleanNodeName[0]+"[@uID='"+uID+"']"+strWrapper.val; - } - else - { - strWrapper.val = "/"+cleanNodeName[0]+strWrapper.val; - } - var aParent = aNode.parent; - if (aParent) - { - return putAncestorsInXPath(strWrapper, aParent); - } - else - { - return strWrapper; - } - } - - - - - - - - - - var graphs, currentGraph, varCategories, entireData; entireData = data; @@ -20057,6 +19819,13 @@ variable.data = variable variable.data.name = variable.xPath.split("/")[variable.xPath.split("/").length-1] }) + + //build tree layout for vistoms + var newTree = {}; + buildTree(newTree, variables) + //variables = newTree + console.log(newTree) + console.log(variables) bootbox.prompt( { @@ -20095,12 +19864,12 @@ var treeLayoutSVG = treeLayoutdiv.append("svg").attr("class","treeLayoutSVG") var treeLayout = treeLayoutSVG.append("g").attr("class","treeLayout"); maketreeLayout(array, treeLayout, treeLayoutSVG, treeLayoutdiv, divClassName, headLine, varCategories[0].description); - show_bootBox_listMessage(functions,nodeMenu); + show_bootBox_listMessage(functions,toolMenu); } if (result.includes("List")) { show_bootBox_listMessage(variables,nodeMenu); - show_bootBox_listMessage(functions,nodeMenu); + show_bootBox_listMessage(functions,toolMenu); } } } @@ -22376,9 +22145,217 @@ return d.children || d._children ? "end" : "start"; }) //.text(function(d) { return d.data.text; }); - + + + //Function writeTreeToXML goes through tree nodes and puts the into an xml document + function writeTreeToXML(aNode,anXMLDoc,anXPath) + { + //Variable "children" + //--> One children variable, no matter whether a node has "_children" (collapsed) or "children" (expanded) + var children; + if (aNode._children){children = aNode._children;} + else if (aNode.children){children = aNode.children;} + + //Get current xml element with its xPath + var element = anXMLDoc.evaluate(anXPath,anXMLDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; + if (element != null) {element.value = '...';} + + //If a node has children (collapsed or expanded), loop through them + if (children) + { + for (var i=0; i < children.length;i++) + { + //Name of the new XML element --> childName + var child = children[i]; + var childName = child.data.name.split(/[\[\]]+/);//Split childName at "[]" which is the uID + var cleanChildName = childName[0].split(/[\+\*\^\-\ \#]+/);//Split childName all special characters + var newNode = anXMLDoc.createElement(String(cleanChildName[0])); + + //The children are appended to the xPath --> newXPath + var newXPath = anXPath+"/"+cleanChildName[0]; + + //If childName contains a uID, make the uID an attribute + if (childName[1]) + { + if (parseInt(childName[1])) + { + var dummyID = childName[1]; + newNode.setAttribute("dummyID", dummyID) + newXPath = newXPath+"[@dummyID='"+dummyID+"']"; + } + else + { + var uID = childName[1]; + newNode.setAttribute("uID", uID) + newXPath = newXPath+"[@uID='"+uID+"']"; + } + } + if (cleanChildName.length>1) {newNode.setAttribute("elementName", childName[0])}; + + //Append the newNode to the xml structure + element.appendChild(newNode); + + + + ////aigner: Sorting of XML elements according to "uID" + // var items = element.children; + // var itemsArr = []; + // for (var j in items) { + // if (items[j].nodeType == 1) { // get rid of the whitespace text nodes + // itemsArr.push(items[j]); + // } + // } + // itemsArr.sort(function(a,b){ + // if (a.getAttribute("uID") < b.getAttribute("uID")) + // return -1; + // if (a.getAttribute("uID") > b.getAttribute("uID")) + // return 1; + // return 0; + // }); + + // for (j = 0; j < itemsArr.length; ++j) { + // element.appendChild(itemsArr[j]); + // } + + //call function writeTreeToXML recursively for all children + writeTreeToXML(child,anXMLDoc,newXPath) + } + } + else + { + if (aNode.data.value){element.innerHTML = String(aNode.data.value);} + else{element.innerHTML = " ";} + } + //return the xml document + return anXMLDoc; + } + + function removeAttributeInAllElements(aDocument,attribute) + { + var matchingElements = []; + var allElements = aDocument.getElementsByTagName('*'); + for (var i = 0, n = allElements.length; i < n; i++) + { + if (allElements[i].getAttribute(attribute) !== null) + { + allElements[i].removeAttribute(attribute); + } + } + return matchingElements; + } + + function putAncestorsInXMLString(strWrapper, aNode) + { + //Name of the new XML element + var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID + var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters + //If nodeName contains a uID, make the uID an attribute + if (nodeName[1]) + { + var uID = nodeName[1]; + strWrapper.val = "<"+cleanNodeName[0]+" uID='"+ uID +"'>"+strWrapper.val+"</"+cleanNodeName[0]+">";; + } + else + { + strWrapper.val = "<"+cleanNodeName[0]+">"+strWrapper.val+"</"+cleanNodeName[0]+">";; + } + var aParent = aNode.parent; + if (aParent) + { + return putAncestorsInXMLString(strWrapper, aParent); + } + else + { + return strWrapper; + } + } + + function putAncestorsInXPath(strWrapper, aNode) + { + //Name of the new XML element + var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID + var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters + //If nodeName contains a uID, make the uID an attribute + if (nodeName[1]) + { + var uID = nodeName[1]; + strWrapper.val = "/"+cleanNodeName[0]+"[@uID='"+uID+"']"+strWrapper.val; + } + else + { + strWrapper.val = "/"+cleanNodeName[0]+strWrapper.val; + } + var aParent = aNode.parent; + if (aParent) + { + return putAncestorsInXPath(strWrapper, aParent); + } + else + { + return strWrapper; + } + } + + var nodeTreeMenu = nodeMenu; + var treeMenu = [ + { + title: 'Download full tree as XML-file', + onMouseDown: function(elm, d, i) { + //Begin xml structure with the first element + var xmlString = "<"+nodes[0].data.name+">"+"</"+nodes[0].data.name+">"; + //Create a new xml document + var parser = new DOMParser(); + var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" + //Get initial xPath of the tree and pass it to the function "writeTreeToXML" + var initialXPath = "/"+nodes[0].data.name; + writeTreeToXML(nodes[0],xmlDocument,initialXPath); + //remove all attributes dummyID + removeAttributeInAllElements(xmlDocument,'dummyID'); + //Make the xml document a string + var serializer = new XMLSerializer(); + var xmlString = serializer.serializeToString(xmlDocument); + xmlString = vkbeautify.xml(xmlString); + //Download a document with the xml-schema + download(aName+'_full.xml',xmlString); + }, + onMouseUp: function(elm, d, i) { + }, + onMouseOver: function(elm, d, i) { + }, + childrenItems: [] + }, + { + title: 'Download tree as XML-file from current node', + onMouseDown: function(elm, d, i) { + var xmlString = putAncestorsInXMLString({ val : '' }, d).val; + var initialXPath = putAncestorsInXPath({ val : '' }, d).val; + //Create a new xml document + var parser = new DOMParser(); + var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" + //Get initial xPath of the tree and pass it to the function "writeCurrentTreeToXML" + writeTreeToXML(d,xmlDocument,initialXPath); + //remove all attributes dummyID + removeAttributeInAllElements(xmlDocument,'dummyID'); + //Make the xml document a string + var serializer = new XMLSerializer(); + xmlString = serializer.serializeToString(xmlDocument); + xmlString = vkbeautify.xml(xmlString); + //Download a document with the xml-schema + download(aName+"_"+d.data.name+'.xml',xmlString); + }, + onMouseUp: function(elm, d, i) { + }, + onMouseOver: function(elm, d, i) { + }, + childrenItems: [] + } + ] + var nodeTreeMenu = nodeMenu.concat(treeMenu); + + + nodeEnter = nodeEnter - .on('contextmenu', d3.contextMenu(nodeMenu)); + .on('contextmenu', d3.contextMenu(nodeTreeMenu)); nodeEnter.append("svg:title").text("Click left to expand, click right to inspect") @@ -24211,18 +24188,7 @@ { title: 'Copy x-path to clipboard', onMouseDown: function(elm, d, i) { - function copyToClipboard(text) - { - window.prompt("Copy to clipboard: Ctrl+C, Enter", text); - } - function copyXPathToClipboard(data,aText) - { - aText = "/"+data.name+aText; - if (data.parent){copyXPathToClipboard(data.parent,aText)} - else{copyToClipboard(aText);} - } - var copyText=""; - copyXPathToClipboard(d,copyText); + window.prompt("Copy to clipboard: Ctrl+C, Enter", d.xPath); d3.select('.d3-context-menu').style('display', 'none'); }, onMouseUp: function(elm, d, i) { @@ -26640,18 +26606,7 @@ { title: 'Copy x-path to clipboard', onMouseDown: function(elm, d, i) { - function copyToClipboard(text) - { - window.prompt("Copy to clipboard: Ctrl+C, Enter", text); - } - function copyXPathToClipboard(data,aText) - { - aText = "/"+data.name+aText; - if (data.parent){copyXPathToClipboard(data.parent,aText)} - else{copyToClipboard(aText);} - } - var copyText=""; - copyXPathToClipboard(d,copyText); + window.prompt("Copy to clipboard: Ctrl+C, Enter", d.xPath); d3.select('.d3-context-menu').style('display', 'none'); }, onMouseUp: function(elm, d, i) { -- GitLab