From 69ab304624c82da9b2e15fa007af8ddff614d10f Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 6 Aug 2013 11:07:16 +0200 Subject: [PATCH] GraphViewer: Fixed a bug that occured when editing nodes/edges, and jslintified --- .../js/graphViewer/graph/arangoAdapter.js | 15 +-- .../js/graphViewer/graph/communityNode.js | 27 +++--- html/admin/js/graphViewer/ui/graphViewerUI.js | 4 +- .../js/graphViewer/ui/modalDialogHelper.js | 96 ++++++++++--------- .../js/graphViewer/ui/nodeShaperControls.js | 2 +- 5 files changed, 75 insertions(+), 69 deletions(-) diff --git a/html/admin/js/graphViewer/graph/arangoAdapter.js b/html/admin/js/graphViewer/graph/arangoAdapter.js index 45f0e094e3..4919f9cdc0 100644 --- a/html/admin/js/graphViewer/graph/arangoAdapter.js +++ b/html/admin/js/graphViewer/graph/arangoAdapter.js @@ -160,7 +160,13 @@ function ArangoAdapter(nodes, edges, config) { getNRandom = function(n, callback) { var list = [], - i = 0; + i = 0, + onSuccess = function(data) { + list.push(data.document || {}); + if (list.length === n) { + callback(list); + } + }; for (i = 0; i < n; i++) { $.ajax({ cache: false, @@ -170,12 +176,7 @@ function ArangoAdapter(nodes, edges, config) { collection: nodeCollection }), contentType: "application/json", - success: function(data) { - list.push(data.document || {}); - if (list.length === n) { - callback(list); - } - } + success: onSuccess }); } }, diff --git a/html/admin/js/graphViewer/graph/communityNode.js b/html/admin/js/graphViewer/graph/communityNode.js index 7fefea41a8..609c0e6a2a 100644 --- a/html/admin/js/graphViewer/graph/communityNode.js +++ b/html/admin/js/graphViewer/graph/communityNode.js @@ -169,7 +169,7 @@ function CommunityNode(parent, initial) { updateNodeArray(); self._size++; }, - + insertInitialNodes = function(ns) { _.each(ns, function(n) { nodes[n._id] = n; @@ -409,11 +409,11 @@ function CommunityNode(parent, initial) { addDistortion = function(distFunc) { if (self._expanded) { - var oldFocus = distFunc.focus(); - var newFocus = [ - oldFocus[0] - self.position.x, - oldFocus[1] - self.position.y - ]; + var oldFocus = distFunc.focus(), + newFocus = [ + oldFocus[0] - self.position.x, + oldFocus[1] - self.position.y + ]; distFunc.focus(newFocus); _.each(nodeArray, function(n) { n.position = distFunc(n); @@ -447,13 +447,14 @@ function CommunityNode(parent, initial) { shapeEdges = function(g, addQue) { var idFunction = function(d) { - return d._id; - }; + return d._id; + }, + line, + interior; if (self._expanded) { - var line, - interior = g - .selectAll(".link") - .data(intEdgeArray, idFunction); + interior = g + .selectAll(".link") + .data(intEdgeArray, idFunction); // Append the group and class to all new interior.enter() .append("g") @@ -469,7 +470,7 @@ function CommunityNode(parent, initial) { }, collapseNode = function(n) { - removeOutboundEdgesFromNode(n) + removeOutboundEdgesFromNode(n); }; //////////////////////////////////// diff --git a/html/admin/js/graphViewer/ui/graphViewerUI.js b/html/admin/js/graphViewer/ui/graphViewerUI.js index 1c3fe1242e..73a1681406 100644 --- a/html/admin/js/graphViewer/ui/graphViewerUI.js +++ b/html/admin/js/graphViewer/ui/graphViewerUI.js @@ -176,7 +176,7 @@ function GraphViewerUI(container, adapterConfig, optWidth, optHeight, viewerConf searchAttrExampleList.appendChild(entry); entry.onclick = function() { searchAttrField.value = r; - } + }; }); }); }, @@ -402,4 +402,4 @@ function GraphViewerUI(container, adapterConfig, optWidth, optHeight, viewerConf graphViewer.loadGraph(startNode); } -} \ No newline at end of file +} diff --git a/html/admin/js/graphViewer/ui/modalDialogHelper.js b/html/admin/js/graphViewer/ui/modalDialogHelper.js index 699154ccbb..d426e93062 100644 --- a/html/admin/js/graphViewer/ui/modalDialogHelper.js +++ b/html/admin/js/graphViewer/ui/modalDialogHelper.js @@ -204,7 +204,10 @@ var modalDialogHelper = modalDialogHelper || {}; }); }, - insertDecissionInput = function(idPre, idPost, group, text, isDefault, interior, contentTh, table) { + insertModalRow, + + insertDecissionInput = function(idPre, idPost, group, + text, isDefault, interior, contentTh, table) { var input = document.createElement("input"), id = idPre + idPost, lbl = document.createElement("label"); @@ -283,56 +286,57 @@ var modalDialogHelper = modalDialogHelper || {}; addLineButton.id = id + "_addLine"; addLineButton.className = "graphViewer-icon-button gv-icon-small add"; if (list.length > 0) { - input.value = o.objects[0]; + input.value = list[0]; } for (i = 1; i < list.length; i++) { addNewLine(list[i]); } - }, - - insertModalRow = function(table, idprefix, o) { - var tr = document.createElement("tr"), - labelTh = document.createElement("th"), - contentTh = document.createElement("th"); - table.appendChild(tr); - tr.appendChild(labelTh); - labelTh.className = "collectionTh"; - if (o.text) { - labelTh.appendChild(document.createTextNode(o.text + ":")); - } else { - labelTh.className += " capitalize"; - if (o.type && o.type === "extenadable") { - labelTh.appendChild(document.createTextNode(o.id + ":")); - } else { - labelTh.appendChild(document.createTextNode(o.id + ":")); - } - } - tr.appendChild(contentTh); - contentTh.className = "collectionTh"; - switch(o.type) { - case "text": - contentTh.appendChild(createTextInput(idprefix + o.id)); - break; - case "checkbox": - contentTh.appendChild(createCheckboxInput(idprefix + o.id)); - break; - case "list": - contentTh.appendChild(createListInput(idprefix + o.id, o.objects)); - break; - case "extendable": - insertExtendableInput(idprefix, o.id, o.objects, contentTh, table, tr); - break; - case "decission": - insertDecissionInput(idprefix, o.id, o.group, o.text, o.isDefault, o.interior, contentTh, table); - labelTh.innerHTML = ""; - break; - default: - //Sorry unknown - table.removeChild(tr); - break; - } - return tr; }; + + insertModalRow = function(table, idprefix, o) { + var tr = document.createElement("tr"), + labelTh = document.createElement("th"), + contentTh = document.createElement("th"); + table.appendChild(tr); + tr.appendChild(labelTh); + labelTh.className = "collectionTh"; + if (o.text) { + labelTh.appendChild(document.createTextNode(o.text + ":")); + } else { + labelTh.className += " capitalize"; + if (o.type && o.type === "extenadable") { + labelTh.appendChild(document.createTextNode(o.id + ":")); + } else { + labelTh.appendChild(document.createTextNode(o.id + ":")); + } + } + tr.appendChild(contentTh); + contentTh.className = "collectionTh"; + switch(o.type) { + case "text": + contentTh.appendChild(createTextInput(idprefix + o.id)); + break; + case "checkbox": + contentTh.appendChild(createCheckboxInput(idprefix + o.id)); + break; + case "list": + contentTh.appendChild(createListInput(idprefix + o.id, o.objects)); + break; + case "extendable": + insertExtendableInput(idprefix, o.id, o.objects, contentTh, table, tr); + break; + case "decission": + insertDecissionInput(idprefix, o.id, o.group, o.text, + o.isDefault, o.interior, contentTh, table); + labelTh.innerHTML = ""; + break; + default: + //Sorry unknown + table.removeChild(tr); + break; + } + return tr; + }; modalDialogHelper.modalDivTemplate = function (title, buttonTitle, idprefix, callback) { // Create needed Elements diff --git a/html/admin/js/graphViewer/ui/nodeShaperControls.js b/html/admin/js/graphViewer/ui/nodeShaperControls.js index 8a1bc7342d..0aff7a8124 100644 --- a/html/admin/js/graphViewer/ui/nodeShaperControls.js +++ b/html/admin/js/graphViewer/ui/nodeShaperControls.js @@ -251,7 +251,7 @@ function NodeShaperControls(list, shaper) { colourkey = $("#" + idprefix + "colour-attribute").attr("value"), selected = $("input[type='radio'][name='colour']:checked").attr("id"); if (selected === idprefix + "samecolour") { - colourkey = key + colourkey = key; } shaper.changeTo({ label: key,