Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kick off a simple jsplumb directive, check out UI developer help for …
…example
- Loading branch information
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
hawtio-web/src/main/webapp/app/ui/js/jsPlumbDirective.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
module UI { | ||
|
||
export class JSPlumb { | ||
public restrict = 'A'; | ||
|
||
public link = ($scope, $element, $attrs) => { | ||
|
||
$element.bind('DOMNodeInserted', (event) => { | ||
// TODO - handle added nodes here, like from ng-repeat for example | ||
}); | ||
|
||
setTimeout(() => { | ||
$scope.jsPlumb = jsPlumb.getInstance({ | ||
Container: $element | ||
}); | ||
|
||
$scope.jsPlumb.importDefaults({ | ||
DragOptions : { cursor: "pointer", zIndex:2000 } | ||
}); | ||
|
||
var nodes = []; | ||
var transitions = []; | ||
|
||
var nodeEls = $element.find('.jsplumb-node'); | ||
angular.forEach(nodeEls, (node) => { | ||
|
||
var el = $(node); | ||
|
||
nodes.push({ | ||
el: el, | ||
width: el.width(), | ||
height: el.height() | ||
}); | ||
$scope.jsPlumb.addEndpoint(el); | ||
$scope.jsPlumb.draggable(el, { | ||
containment: $element | ||
}); | ||
}); | ||
|
||
angular.forEach(nodes, (node) => { | ||
var targets:any = node.el.attr('connect-to'); | ||
if (targets) { | ||
targets = targets.split(','); | ||
angular.forEach(targets, (target) => { | ||
var targetEl = $element.find(target); | ||
var transition = { | ||
source: node.el, | ||
target: targetEl | ||
}; | ||
$scope.jsPlumb.connect(transition); | ||
transitions.push(transition); | ||
}); | ||
} | ||
}); | ||
|
||
$scope.jsPlumbNodes = nodes; | ||
$scope.jsPlumbTransitions = transitions; | ||
|
||
setTimeout(() => { | ||
$scope.layout = dagre.layout() | ||
.nodeSep(100) | ||
.edgeSep(10) | ||
.rankSep(50) | ||
.nodes(nodes) | ||
.transitions(transitions) | ||
.debugLevel(1) | ||
.run(); | ||
Core.$apply($scope); | ||
}, 50); | ||
}, 50); | ||
|
||
|
||
}; | ||
} | ||
|
||
export class JSPlumbConnection { | ||
public restrict = 'A'; | ||
|
||
public link = ($scope, $element, $attrs) => { | ||
if (!angular.isDefined($scope.jsPlumb)) { | ||
return; | ||
} | ||
|
||
console.log("here!"); | ||
|
||
var targets = $attrs['connectTo'].split(','); | ||
|
||
angular.forEach(targets, (target) => { | ||
|
||
var targetEl = $element.parent().find(target); | ||
|
||
$scope.jsPlumb.connect({ | ||
source: $element, | ||
target: targetEl | ||
}); | ||
}); | ||
|
||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters