Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
Matteo Scandolo | 4b3d872 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 3 | angular.module('xos.diagnostic') |
Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 4 | .directive('logicTopology', function(){ |
| 5 | return { |
| 6 | restrict: 'E', |
| 7 | scope: { |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 8 | subscribers: '=', |
| 9 | selected: '=' |
Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 10 | }, |
| 11 | bindToController: true, |
| 12 | controllerAs: 'vm', |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 13 | templateUrl: 'templates/logicTopology.tpl.html', |
Matteo Scandolo | 0344ef3 | 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 | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 15 | $log.info('Logic Plane'); |
| 16 | |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 17 | var svg; |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 18 | this.selectedInstances = []; |
| 19 | this.hideInstanceStats = true; |
Matteo Scandolo | 594dfbc | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 20 | |
| 21 | const handleSvg = (el) => { |
| 22 | |
Matteo Scandolo | d54a7fd | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 23 | d3.select($element[0]).select('svg').remove(); |
| 24 | |
Matteo Scandolo | 594dfbc | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 25 | svg = d3.select(el) |
| 26 | .append('svg') |
| 27 | .style('width', `${el.clientWidth}px`) |
| 28 | .style('height', `${el.clientHeight}px`); |
| 29 | } |
| 30 | |
Matteo Scandolo | d1b3bf5 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 31 | const loadGlobalScope = () => { |
| 32 | ChartData.getLogicTree() |
| 33 | .then((tree) => { |
| 34 | LogicTopologyHelper.updateTree(svg); |
| 35 | }); |
| 36 | } |
| 37 | loadGlobalScope(); |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 38 | |
| 39 | $scope.$watch(() => this.selected, (selected) => { |
| 40 | if(selected){ |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 41 | ChartData.selectSubscriber(selected); |
| 42 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 43 | } |
Matteo Scandolo | d1b3bf5 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 44 | else{ |
| 45 | ChartData.removeSubscriber(); |
| 46 | LogicTopologyHelper.updateTree(svg); |
| 47 | } |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 48 | }); |
| 49 | |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 50 | $rootScope.$on('instance.detail.hide', () => { |
| 51 | this.hideInstanceStats = true; |
| 52 | $timeout(() => { |
| 53 | this.selectedInstances = []; |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 54 | ChartData.highlightInstances([]); |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 55 | LogicTopologyHelper.updateTree(svg); |
| 56 | }, 500); |
| 57 | }); |
Matteo Scandolo | edd3d6f | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 58 | |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 59 | $rootScope.$on('instance.detail', (evt, service) => { |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 60 | ChartData.getInstanceStatus(service) |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 61 | .then((instances) => { |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 62 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 63 | }) |
Matteo Scandolo | d54a7fd | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 64 | }); |
| 65 | |
| 66 | d3.select(window) |
| 67 | .on('resize.logic', () => { |
| 68 | handleSvg($element[0]); |
| 69 | LogicTopologyHelper.setupTree(svg); |
| 70 | LogicTopologyHelper.updateTree(svg); |
| 71 | }); |
Matteo Scandolo | edd3d6f | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 72 | |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 73 | handleSvg($element[0]); |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 74 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 75 | |
Matteo Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 76 | this.selectSubscriberModal = () => { |
| 77 | this.openSelectSubscriberModal = true; |
| 78 | $scope.$apply(); |
| 79 | }; |
| 80 | |
| 81 | this.subscriberStatusModal = () => { |
| 82 | this.openSubscriberStatusModal = true; |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 83 | $scope.$apply(); |
| 84 | }; |
| 85 | |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 86 | // listen for subscriber modal event |
| 87 | $rootScope.$on('subscriber.modal.open', () => { |
Matteo Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 88 | |
| 89 | if(ChartData.currentSubscriber){ |
| 90 | this.subscriberStatusModal(); |
| 91 | } |
| 92 | else{ |
| 93 | this.selectSubscriberModal(); |
| 94 | } |
| 95 | }); |
| 96 | |
| 97 | // listen for subscriber modal event |
| 98 | $rootScope.$on('subscriber.modal.open', () => { |
| 99 | |
| 100 | if(ChartData.currentSubscriber){ |
| 101 | this.currentSubscriber = ChartData.currentSubscriber; |
| 102 | this.subscriberStatusModal(); |
| 103 | } |
| 104 | else{ |
| 105 | this.selectSubscriberModal(); |
| 106 | } |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 107 | }); |
| 108 | |
Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 109 | } |
| 110 | }; |
| 111 | }); |
| 112 | })(); |