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 | |
| 23 | svg = d3.select(el) |
| 24 | .append('svg') |
| 25 | .style('width', `${el.clientWidth}px`) |
| 26 | .style('height', `${el.clientHeight}px`); |
| 27 | } |
| 28 | |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 29 | ChartData.getLogicTree() |
| 30 | .then((tree) => { |
| 31 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 32 | }); |
| 33 | |
| 34 | $scope.$watch(() => this.selected, (selected) => { |
| 35 | if(selected){ |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 36 | ChartData.selectSubscriber(selected); |
| 37 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 38 | } |
| 39 | }); |
| 40 | |
Matteo Scandolo | c303fd0 | 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 | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 45 | ChartData.highlightInstances([]); |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 46 | LogicTopologyHelper.updateTree(svg); |
| 47 | }, 500); |
| 48 | }); |
Matteo Scandolo | edd3d6f | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 49 | |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 50 | $rootScope.$on('instance.detail', (evt, service) => { |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 51 | ChartData.getInstanceStatus(service) |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 52 | .then((instances) => { |
Matteo Scandolo | 06afdfe | 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 | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 64 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 65 | }) |
Matteo Scandolo | edd3d6f | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 66 | }) |
| 67 | |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 68 | handleSvg($element[0]); |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 69 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 70 | |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 71 | this.openSubscriberModal = () => { |
| 72 | this.subscriberModal = true; |
| 73 | $scope.$apply(); |
| 74 | }; |
| 75 | |
Matteo Scandolo | cc8fa15 | 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 | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 81 | } |
| 82 | }; |
| 83 | }); |
| 84 | })(); |