blob: 55378fcbe7b5ede33a8f69946cc9e342859d0bfe [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
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 Scandolo7547f042016-02-09 09:13:30 -080019(function () {
20 'use strict';
Matteo Scandolo04564952016-02-24 11:22:48 -080021 angular.module('xos.diagnostic')
Matteo Scandolo7547f042016-02-09 09:13:30 -080022 .directive('logicTopology', function(){
23 return {
24 restrict: 'E',
25 scope: {
Matteo Scandolo219b1a72016-02-09 11:19:22 -080026 subscribers: '=',
27 selected: '='
Matteo Scandolo7547f042016-02-09 09:13:30 -080028 },
29 bindToController: true,
30 controllerAs: 'vm',
Matteo Scandoloc49ff702016-02-17 15:11:33 -080031 templateUrl: 'templates/logicTopology.tpl.html',
Matteo Scandolo012dddb2016-02-22 16:53:22 -080032 controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig, ChartData){
Matteo Scandolo7547f042016-02-09 09:13:30 -080033 $log.info('Logic Plane');
34
Matteo Scandolo219b1a72016-02-09 11:19:22 -080035 var svg;
Matteo Scandoloc49ff702016-02-17 15:11:33 -080036 this.selectedInstances = [];
37 this.hideInstanceStats = true;
Matteo Scandolo39a56f52016-03-11 11:54:47 -080038 var _this = this;
Matteo Scandolocc0db942016-02-11 17:37:08 -080039
40 const handleSvg = (el) => {
41
Matteo Scandolo79108192016-03-08 09:33:26 -080042 d3.select($element[0]).select('svg').remove();
43
Matteo Scandolocc0db942016-02-11 17:37:08 -080044 svg = d3.select(el)
45 .append('svg')
46 .style('width', `${el.clientWidth}px`)
47 .style('height', `${el.clientHeight}px`);
48 }
49
Matteo Scandolo3a176a22016-03-07 16:42:03 -080050 const loadGlobalScope = () => {
51 ChartData.getLogicTree()
52 .then((tree) => {
53 LogicTopologyHelper.updateTree(svg);
54 });
55 }
56 loadGlobalScope();
Matteo Scandolo219b1a72016-02-09 11:19:22 -080057
58 $scope.$watch(() => this.selected, (selected) => {
59 if(selected){
Matteo Scandolo012dddb2016-02-22 16:53:22 -080060 ChartData.selectSubscriber(selected);
61 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo219b1a72016-02-09 11:19:22 -080062 }
Matteo Scandolo3a176a22016-03-07 16:42:03 -080063 else{
64 ChartData.removeSubscriber();
65 LogicTopologyHelper.updateTree(svg);
66 }
Matteo Scandolo219b1a72016-02-09 11:19:22 -080067 });
68
Matteo Scandoloc49ff702016-02-17 15:11:33 -080069 $rootScope.$on('instance.detail.hide', () => {
70 this.hideInstanceStats = true;
71 $timeout(() => {
72 this.selectedInstances = [];
Matteo Scandolo012dddb2016-02-22 16:53:22 -080073 ChartData.highlightInstances([]);
Matteo Scandoloc49ff702016-02-17 15:11:33 -080074 LogicTopologyHelper.updateTree(svg);
75 }, 500);
76 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080077
Matteo Scandoloc49ff702016-02-17 15:11:33 -080078 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandolo012dddb2016-02-22 16:53:22 -080079 ChartData.getInstanceStatus(service)
Matteo Scandolo51031482016-02-17 13:54:11 -080080 .then((instances) => {
Matteo Scandoloc49ff702016-02-17 15:11:33 -080081 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080082 })
Matteo Scandolo39a56f52016-03-11 11:54:47 -080083 .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 Scandolo79108192016-03-08 09:33:26 -080089 });
90
91 d3.select(window)
92 .on('resize.logic', () => {
93 handleSvg($element[0]);
94 LogicTopologyHelper.setupTree(svg);
95 LogicTopologyHelper.updateTree(svg);
96 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080097
Matteo Scandolo219b1a72016-02-09 11:19:22 -080098 handleSvg($element[0]);
Matteo Scandolo35d53c82016-02-16 14:44:51 -080099 LogicTopologyHelper.setupTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -0800100
Matteo Scandolo574c73f2016-03-01 17:08:45 -0800101 this.selectSubscriberModal = () => {
102 this.openSelectSubscriberModal = true;
103 $scope.$apply();
104 };
105
106 this.subscriberStatusModal = () => {
107 this.openSubscriberStatusModal = true;
Matteo Scandolo388795a2016-02-22 09:57:55 -0800108 $scope.$apply();
109 };
110
Matteo Scandolo388795a2016-02-22 09:57:55 -0800111 // listen for subscriber modal event
Matteo Scandolof79f0b32016-09-30 10:23:10 -0700112 // $rootScope.$on('subscriber.modal.open', () => {
113 //
114 // if(ChartData.currentSubscriber){
115 // this.subscriberStatusModal();
116 // }
117 // else{
118 // this.selectSubscriberModal();
119 // }
120 // });
Matteo Scandolo574c73f2016-03-01 17:08:45 -0800121
122 // listen for subscriber modal event
123 $rootScope.$on('subscriber.modal.open', () => {
Matteo Scandolo574c73f2016-03-01 17:08:45 -0800124 if(ChartData.currentSubscriber){
125 this.currentSubscriber = ChartData.currentSubscriber;
126 this.subscriberStatusModal();
127 }
128 else{
129 this.selectSubscriberModal();
130 }
Matteo Scandolo388795a2016-02-22 09:57:55 -0800131 });
132
Matteo Scandolo7547f042016-02-09 09:13:30 -0800133 }
134 };
135 });
136})();