Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
Matteo Scandolo | 0456495 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 3 | angular.module('xos.diagnostic') |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 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 | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 53 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 54 | }) |
Matteo Scandolo | 79de20a | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 55 | }) |
| 56 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 57 | handleSvg($element[0]); |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 58 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 59 | |
Matteo Scandolo | 574c73f | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 60 | this.selectSubscriberModal = () => { |
| 61 | this.openSelectSubscriberModal = true; |
| 62 | $scope.$apply(); |
| 63 | }; |
| 64 | |
| 65 | this.subscriberStatusModal = () => { |
| 66 | this.openSubscriberStatusModal = true; |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 67 | $scope.$apply(); |
| 68 | }; |
| 69 | |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 70 | // listen for subscriber modal event |
| 71 | $rootScope.$on('subscriber.modal.open', () => { |
Matteo Scandolo | 574c73f | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 72 | |
| 73 | if(ChartData.currentSubscriber){ |
| 74 | this.subscriberStatusModal(); |
| 75 | } |
| 76 | else{ |
| 77 | this.selectSubscriberModal(); |
| 78 | } |
| 79 | }); |
| 80 | |
| 81 | // listen for subscriber modal event |
| 82 | $rootScope.$on('subscriber.modal.open', () => { |
| 83 | |
| 84 | if(ChartData.currentSubscriber){ |
| 85 | this.currentSubscriber = ChartData.currentSubscriber; |
| 86 | this.subscriberStatusModal(); |
| 87 | } |
| 88 | else{ |
| 89 | this.selectSubscriberModal(); |
| 90 | } |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 91 | }); |
| 92 | |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 93 | } |
| 94 | }; |
| 95 | }); |
| 96 | })(); |