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', |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 13 | templateUrl: 'templates/logicTopology.tpl.html', |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 14 | controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig, ChartData){ |
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; |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 18 | this.selectedInstances = []; |
| 19 | this.hideInstanceStats = true; |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 20 | |
| 21 | const handleSvg = (el) => { |
| 22 | |
| 23 | svg = d3.select(el) |
| 24 | .append('svg') |
| 25 | .style('width', `${el.clientWidth}px`) |
| 26 | .style('height', `${el.clientHeight}px`); |
| 27 | } |
| 28 | |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 29 | ChartData.getLogicTree() |
| 30 | .then((tree) => { |
| 31 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 32 | }); |
| 33 | |
| 34 | $scope.$watch(() => this.selected, (selected) => { |
| 35 | if(selected){ |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 36 | ChartData.selectSubscriber(selected); |
| 37 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 38 | } |
| 39 | }); |
| 40 | |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 41 | $rootScope.$on('instance.detail.hide', () => { |
| 42 | this.hideInstanceStats = true; |
| 43 | $timeout(() => { |
| 44 | this.selectedInstances = []; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 45 | ChartData.highlightInstances([]); |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 46 | LogicTopologyHelper.updateTree(svg); |
| 47 | }, 500); |
| 48 | }); |
Matteo Scandolo | 79de20a | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 49 | |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 50 | $rootScope.$on('instance.detail', (evt, service) => { |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 51 | ChartData.getInstanceStatus(service) |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 52 | .then((instances) => { |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 53 | // this.hideInstanceStats = false; |
| 54 | // // HACK if array is empty wait for animation |
| 55 | // if(instances.length === 0){ |
| 56 | // this.hideInstanceStats = true; |
| 57 | // $timeout(() => { |
| 58 | // this.selectedInstances = instances; |
| 59 | // }, 500); |
| 60 | // } |
| 61 | // else{ |
| 62 | // this.selectedInstances = instances; |
| 63 | // } |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 64 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 65 | }) |
Matteo Scandolo | 79de20a | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 66 | }) |
| 67 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 68 | handleSvg($element[0]); |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 69 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 70 | |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 71 | this.openSubscriberModal = () => { |
| 72 | this.subscriberModal = true; |
| 73 | $scope.$apply(); |
| 74 | }; |
| 75 | |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 76 | // listen for subscriber modal event |
| 77 | $rootScope.$on('subscriber.modal.open', () => { |
| 78 | this.openSubscriberModal(); |
| 79 | }); |
| 80 | |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 81 | } |
| 82 | }; |
| 83 | }); |
| 84 | })(); |