Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 19 | (function () { |
| 20 | 'use strict'; |
Matteo Scandolo | 0456495 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 21 | angular.module('xos.diagnostic') |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 22 | .directive('logicTopology', function(){ |
| 23 | return { |
| 24 | restrict: 'E', |
| 25 | scope: { |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 26 | subscribers: '=', |
| 27 | selected: '=' |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 28 | }, |
| 29 | bindToController: true, |
| 30 | controllerAs: 'vm', |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 31 | templateUrl: 'templates/logicTopology.tpl.html', |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 32 | 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] | 33 | $log.info('Logic Plane'); |
| 34 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 35 | var svg; |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 36 | this.selectedInstances = []; |
| 37 | this.hideInstanceStats = true; |
Matteo Scandolo | 39a56f5 | 2016-03-11 11:54:47 -0800 | [diff] [blame] | 38 | var _this = this; |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 39 | |
| 40 | const handleSvg = (el) => { |
| 41 | |
Matteo Scandolo | 7910819 | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 42 | d3.select($element[0]).select('svg').remove(); |
| 43 | |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 44 | svg = d3.select(el) |
| 45 | .append('svg') |
| 46 | .style('width', `${el.clientWidth}px`) |
| 47 | .style('height', `${el.clientHeight}px`); |
| 48 | } |
| 49 | |
Matteo Scandolo | 3a176a2 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 50 | const loadGlobalScope = () => { |
| 51 | ChartData.getLogicTree() |
| 52 | .then((tree) => { |
| 53 | LogicTopologyHelper.updateTree(svg); |
| 54 | }); |
| 55 | } |
| 56 | loadGlobalScope(); |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 57 | |
| 58 | $scope.$watch(() => this.selected, (selected) => { |
| 59 | if(selected){ |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 60 | ChartData.selectSubscriber(selected); |
| 61 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 62 | } |
Matteo Scandolo | 3a176a2 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 63 | else{ |
| 64 | ChartData.removeSubscriber(); |
| 65 | LogicTopologyHelper.updateTree(svg); |
| 66 | } |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 67 | }); |
| 68 | |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 69 | $rootScope.$on('instance.detail.hide', () => { |
| 70 | this.hideInstanceStats = true; |
| 71 | $timeout(() => { |
| 72 | this.selectedInstances = []; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 73 | ChartData.highlightInstances([]); |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 74 | LogicTopologyHelper.updateTree(svg); |
| 75 | }, 500); |
| 76 | }); |
Matteo Scandolo | 79de20a | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 77 | |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 78 | $rootScope.$on('instance.detail', (evt, service) => { |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 79 | ChartData.getInstanceStatus(service) |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 80 | .then((instances) => { |
Matteo Scandolo | c49ff70 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 81 | LogicTopologyHelper.updateTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 82 | }) |
Matteo Scandolo | 39a56f5 | 2016-03-11 11:54:47 -0800 | [diff] [blame] | 83 | .catch(e => { |
| 84 | _this.error = 'Service statistics are not available at this time. Please try again later.' |
| 85 | $timeout(() => { |
| 86 | _this.error = null; |
| 87 | }, 2000); |
| 88 | }) |
Matteo Scandolo | 7910819 | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 89 | }); |
| 90 | |
| 91 | d3.select(window) |
| 92 | .on('resize.logic', () => { |
| 93 | handleSvg($element[0]); |
| 94 | LogicTopologyHelper.setupTree(svg); |
| 95 | LogicTopologyHelper.updateTree(svg); |
| 96 | }); |
Matteo Scandolo | 79de20a | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 97 | |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 98 | handleSvg($element[0]); |
Matteo Scandolo | 35d53c8 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 99 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 100 | |
Matteo Scandolo | 574c73f | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 101 | this.selectSubscriberModal = () => { |
| 102 | this.openSelectSubscriberModal = true; |
| 103 | $scope.$apply(); |
| 104 | }; |
| 105 | |
| 106 | this.subscriberStatusModal = () => { |
| 107 | this.openSubscriberStatusModal = true; |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 108 | $scope.$apply(); |
| 109 | }; |
| 110 | |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 111 | // listen for subscriber modal event |
Matteo Scandolo | f79f0b3 | 2016-09-30 10:23:10 -0700 | [diff] [blame] | 112 | // $rootScope.$on('subscriber.modal.open', () => { |
| 113 | // |
| 114 | // if(ChartData.currentSubscriber){ |
| 115 | // this.subscriberStatusModal(); |
| 116 | // } |
| 117 | // else{ |
| 118 | // this.selectSubscriberModal(); |
| 119 | // } |
| 120 | // }); |
Matteo Scandolo | 574c73f | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 121 | |
| 122 | // listen for subscriber modal event |
| 123 | $rootScope.$on('subscriber.modal.open', () => { |
Matteo Scandolo | 574c73f | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 124 | if(ChartData.currentSubscriber){ |
| 125 | this.currentSubscriber = ChartData.currentSubscriber; |
| 126 | this.subscriberStatusModal(); |
| 127 | } |
| 128 | else{ |
| 129 | this.selectSubscriberModal(); |
| 130 | } |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 131 | }); |
| 132 | |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 133 | } |
| 134 | }; |
| 135 | }); |
| 136 | })(); |