Skip to content

Commit

Permalink
Reuse some code between Camel tracer and debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Dec 13, 2013
1 parent e3c94c2 commit 8b906d0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 53 deletions.
42 changes: 42 additions & 0 deletions hawtio-web/src/main/webapp/app/camel/js/camelHelpers.ts
Expand Up @@ -1175,4 +1175,46 @@ module Camel {
}
return value;
}

/**
* Function to highlight the selected toNode in the nodes graph
*
* @param nodes the nodes
* @param toNode the node to highlight
*/
export function highlightSelectedNode(nodes, toNode) {
// lets clear the selected node first
nodes.attr("class", "node");

nodes.filter(function (item) {
if (item) {
var cid = item["cid"];
var rid = item["rid"];
var type = item["type"];
var elementId = item["elementId"];

// if its from then match on rid
if ("from" === type) {
return toNode === rid;
}

// okay favor using element id as the cids can become
// undefined or mangled with mbean object names, causing this to not work
// where as elementId when present works fine
if (elementId) {
// we should match elementId if defined
return toNode === elementId;
}
// then fallback to cid
if (cid) {
return toNode === cid;
} else {
// and last rid
return toNode === rid;
}
}
return null;
}).attr("class", "node selected");
}

}
22 changes: 2 additions & 20 deletions hawtio-web/src/main/webapp/app/camel/js/debug.ts
Expand Up @@ -91,6 +91,7 @@ module Camel {
$scope.gridOptions = Camel.createBrowseGridOptions();
$scope.gridOptions.selectWithCheckboxOnly = false;
$scope.gridOptions.showSelectionCheckbox = false;
$scope.gridOptions.multiSelect = false;
$scope.gridOptions.afterSelectionChange = onSelectionChanged;
$scope.gridOptions.columnDefs.push({
field: 'toNode',
Expand Down Expand Up @@ -121,33 +122,14 @@ module Camel {
}
onSelectionChanged();
};


// END


function onSelectionChanged() {
var toNode = getStoppedBreakpointId();
if (toNode) {
// lets highlight the node in the diagram
var nodes = getDiagramNodes();

// lets clear the selected node first
nodes.attr("class", "node");

nodes.filter(function (item) {
if (item) {
var cid = item["cid"];
var rid = item["rid"];
if (cid) {
// we should match cid if defined
return toNode === cid;
} else {
return toNode === rid;
}
}
return null;
}).attr("class", "node selected");
Camel.highlightSelectedNode(nodes, toNode);
}
}

Expand Down
34 changes: 1 addition & 33 deletions hawtio-web/src/main/webapp/app/camel/js/trace.ts
Expand Up @@ -125,39 +125,7 @@ module Camel {
if (toNode) {
// lets highlight the node in the diagram
var nodes = d3.select("svg").selectAll("g .node");

// lets clear the selected node first
nodes.attr("class", "node");

nodes.filter(function (item) {
if (item) {
var cid = item["cid"];
var rid = item["rid"];
var type = item["type"];
var elementId = item["elementId"];

// if its from then match on rid
if ("from" === type) {
return toNode === rid;
}

// okay favor using element id as the cids can become
// undefined or mangled with mbean object names, causing this to not work
// where as elementId when present works fine
if (elementId) {
// we should match elementId if defined
return toNode === elementId;
}
// then fallback to cid
if (cid) {
return toNode === cid;
} else {
// and last rid
return toNode === rid;
}
}
return null;
}).attr("class", "node selected");
Camel.highlightSelectedNode(nodes, toNode);
}
}
});
Expand Down

0 comments on commit 8b906d0

Please sign in to comment.