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 | 39a56f5 | 2016-03-11 11:54:47 -0800 | [diff] [blame] | 20 | var _this = this; |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 21 | |
| 22 | const handleSvg = (el) => { |
| 23 | |
Matteo Scandolo | 7910819 | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 24 | d3.select($element[0]).select('svg').remove(); |
| 25 | |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 26 | svg = d3.select(el) |
| 27 | .append('svg') |
| 28 | .style('width', `${el.clientWidth}px`) |
| 29 | .style('height', `${el.clientHeight}px`); |
| 30 | } |
| 31 | |
Matteo Scandolo | 3a176a2 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 32 | const loadGlobalScope = () => { |
| 33 | ChartData.getLogicTree() |
| 34 | .then((tree) => { |
| 35 | LogicTopologyHelper.updateTree(svg); |
| 36 | }); |
| 37 | } |
| 38 | loadGlobalScope(); |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 39 | |
| 40 | $scope.$watch(() => this.selected, (selected) => { |
| 41 | if(selected){ |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 42 | ChartData.selectSubscriber(selected); |
| 43 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 44 | } |
Matteo Scandolo | 3a176a2 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 45 | else{ |
| 46 | ChartData.removeSubscriber(); |
| 47 | LogicTopologyHelper.updateTree(svg); |
| 48 | } |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 49 | }); |
| 50 | |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 51 | $rootScope.$on('instance.detail.hide', () => { |
| 52 | this.hideInstanceStats = true; |
| 53 | $timeout(() => { |
| 54 | this.selectedInstances = []; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 55 | ChartData.highlightInstances([]); |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 56 | LogicTopologyHelper.updateTree(svg); |
| 57 | }, 500); |
| 58 | }); |
Matteo Scandolo | 79de20a | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 59 | |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 60 | $rootScope.$on('instance.detail', (evt, service) => { |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 61 | ChartData.getInstanceStatus(service) |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 62 | .then((instances) => { |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 63 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 64 | }) |
Matteo Scandolo | 39a56f5 | 2016-03-11 11:54:47 -0800 | [diff] [blame] | 65 | .catch(e => { |
| 66 | _this.error = 'Service statistics are not available at this time. Please try again later.' |
| 67 | $timeout(() => { |
| 68 | _this.error = null; |
| 69 | }, 2000); |
| 70 | }) |
Matteo Scandolo | 7910819 | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 71 | }); |
| 72 | |
| 73 | d3.select(window) |
| 74 | .on('resize.logic', () => { |
| 75 | handleSvg($element[0]); |
| 76 | LogicTopologyHelper.setupTree(svg); |
| 77 | LogicTopologyHelper.updateTree(svg); |
| 78 | }); |
Matteo Scandolo | 79de20a | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 79 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 80 | handleSvg($element[0]); |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 81 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 82 | |
Matteo Scandolo | 574c73f | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 83 | this.selectSubscriberModal = () => { |
| 84 | this.openSelectSubscriberModal = true; |
| 85 | $scope.$apply(); |
| 86 | }; |
| 87 | |
| 88 | this.subscriberStatusModal = () => { |
| 89 | this.openSubscriberStatusModal = true; |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 90 | $scope.$apply(); |
| 91 | }; |
| 92 | |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 93 | // listen for subscriber modal event |
| 94 | $rootScope.$on('subscriber.modal.open', () => { |
Matteo Scandolo | 574c73f | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 95 | |
| 96 | if(ChartData.currentSubscriber){ |
| 97 | this.subscriberStatusModal(); |
| 98 | } |
| 99 | else{ |
| 100 | this.selectSubscriberModal(); |
| 101 | } |
| 102 | }); |
| 103 | |
| 104 | // listen for subscriber modal event |
| 105 | $rootScope.$on('subscriber.modal.open', () => { |
| 106 | |
| 107 | if(ChartData.currentSubscriber){ |
| 108 | this.currentSubscriber = ChartData.currentSubscriber; |
| 109 | this.subscriberStatusModal(); |
| 110 | } |
| 111 | else{ |
| 112 | this.selectSubscriberModal(); |
| 113 | } |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 114 | }); |
| 115 | |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 116 | } |
| 117 | }; |
| 118 | }); |
| 119 | })(); |