Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
| 3 | angular.module('xos.serviceTopology') |
| 4 | .directive('logicTopology', function(){ |
| 5 | return { |
| 6 | restrict: 'E', |
| 7 | scope: { |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 8 | subscribers: '=', |
| 9 | selected: '=' |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 10 | }, |
| 11 | bindToController: true, |
| 12 | controllerAs: 'vm', |
| 13 | template: '', |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame^] | 14 | controller: function($element, $log, $scope, d3, LogicTopologyHelper, Node){ |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 15 | $log.info('Logic Plane'); |
| 16 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 17 | var svg; |
| 18 | |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 19 | |
| 20 | const handleSvg = (el) => { |
| 21 | |
| 22 | svg = d3.select(el) |
| 23 | .append('svg') |
| 24 | .style('width', `${el.clientWidth}px`) |
| 25 | .style('height', `${el.clientHeight}px`); |
| 26 | } |
| 27 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 28 | $scope.$watch(() => this.subscribers, (subscribers) => { |
| 29 | if(subscribers){ |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 30 | |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame^] | 31 | LogicTopologyHelper.addSubscribers(angular.copy(subscribers)); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 32 | |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame^] | 33 | Node.queryWithInstances().$promise |
| 34 | .then((computeNodes) => { |
| 35 | LogicTopologyHelper.addComputeNodes(computeNodes); |
| 36 | LogicTopologyHelper.updateTree(svg); |
| 37 | }); |
| 38 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 39 | } |
| 40 | }); |
| 41 | |
| 42 | $scope.$watch(() => this.selected, (selected) => { |
| 43 | if(selected){ |
| 44 | $log.info(`Update logic layer for subscriber ${selected.humanReadableName}`); |
| 45 | } |
| 46 | }); |
| 47 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 48 | handleSvg($element[0]); |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame^] | 49 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 50 | } |
| 51 | }; |
| 52 | }); |
| 53 | })(); |