blob: a14ec574c5a07e73a53b745dab1a90deb3f82a75 [file] [log] [blame]
Matteo Scandolo7547f042016-02-09 09:13:30 -08001(function () {
2 'use strict';
Matteo Scandolo04564952016-02-24 11:22:48 -08003 angular.module('xos.diagnostic')
Matteo Scandolo7547f042016-02-09 09:13:30 -08004 .directive('logicTopology', function(){
5 return {
6 restrict: 'E',
7 scope: {
Matteo Scandolo219b1a72016-02-09 11:19:22 -08008 subscribers: '=',
9 selected: '='
Matteo Scandolo7547f042016-02-09 09:13:30 -080010 },
11 bindToController: true,
12 controllerAs: 'vm',
Matteo Scandoloc49ff702016-02-17 15:11:33 -080013 templateUrl: 'templates/logicTopology.tpl.html',
Matteo Scandolo012dddb2016-02-22 16:53:22 -080014 controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig, ChartData){
Matteo Scandolo7547f042016-02-09 09:13:30 -080015 $log.info('Logic Plane');
16
Matteo Scandolo219b1a72016-02-09 11:19:22 -080017 var svg;
Matteo Scandoloc49ff702016-02-17 15:11:33 -080018 this.selectedInstances = [];
19 this.hideInstanceStats = true;
Matteo Scandolo39a56f52016-03-11 11:54:47 -080020 var _this = this;
Matteo Scandolocc0db942016-02-11 17:37:08 -080021
22 const handleSvg = (el) => {
23
Matteo Scandolo79108192016-03-08 09:33:26 -080024 d3.select($element[0]).select('svg').remove();
25
Matteo Scandolocc0db942016-02-11 17:37:08 -080026 svg = d3.select(el)
27 .append('svg')
28 .style('width', `${el.clientWidth}px`)
29 .style('height', `${el.clientHeight}px`);
30 }
31
Matteo Scandolo3a176a22016-03-07 16:42:03 -080032 const loadGlobalScope = () => {
33 ChartData.getLogicTree()
34 .then((tree) => {
35 LogicTopologyHelper.updateTree(svg);
36 });
37 }
38 loadGlobalScope();
Matteo Scandolo219b1a72016-02-09 11:19:22 -080039
40 $scope.$watch(() => this.selected, (selected) => {
41 if(selected){
Matteo Scandolo012dddb2016-02-22 16:53:22 -080042 ChartData.selectSubscriber(selected);
43 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo219b1a72016-02-09 11:19:22 -080044 }
Matteo Scandolo3a176a22016-03-07 16:42:03 -080045 else{
46 ChartData.removeSubscriber();
47 LogicTopologyHelper.updateTree(svg);
48 }
Matteo Scandolo219b1a72016-02-09 11:19:22 -080049 });
50
Matteo Scandoloc49ff702016-02-17 15:11:33 -080051 $rootScope.$on('instance.detail.hide', () => {
52 this.hideInstanceStats = true;
53 $timeout(() => {
54 this.selectedInstances = [];
Matteo Scandolo012dddb2016-02-22 16:53:22 -080055 ChartData.highlightInstances([]);
Matteo Scandoloc49ff702016-02-17 15:11:33 -080056 LogicTopologyHelper.updateTree(svg);
57 }, 500);
58 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080059
Matteo Scandoloc49ff702016-02-17 15:11:33 -080060 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandolo012dddb2016-02-22 16:53:22 -080061 ChartData.getInstanceStatus(service)
Matteo Scandolo51031482016-02-17 13:54:11 -080062 .then((instances) => {
Matteo Scandoloc49ff702016-02-17 15:11:33 -080063 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080064 })
Matteo Scandolo39a56f52016-03-11 11:54:47 -080065 .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 Scandolo79108192016-03-08 09:33:26 -080071 });
72
73 d3.select(window)
74 .on('resize.logic', () => {
75 handleSvg($element[0]);
76 LogicTopologyHelper.setupTree(svg);
77 LogicTopologyHelper.updateTree(svg);
78 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080079
Matteo Scandolo219b1a72016-02-09 11:19:22 -080080 handleSvg($element[0]);
Matteo Scandolo35d53c82016-02-16 14:44:51 -080081 LogicTopologyHelper.setupTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080082
Matteo Scandolo574c73f2016-03-01 17:08:45 -080083 this.selectSubscriberModal = () => {
84 this.openSelectSubscriberModal = true;
85 $scope.$apply();
86 };
87
88 this.subscriberStatusModal = () => {
89 this.openSubscriberStatusModal = true;
Matteo Scandolo388795a2016-02-22 09:57:55 -080090 $scope.$apply();
91 };
92
Matteo Scandolo388795a2016-02-22 09:57:55 -080093 // listen for subscriber modal event
Matteo Scandolof79f0b32016-09-30 10:23:10 -070094 // $rootScope.$on('subscriber.modal.open', () => {
95 //
96 // if(ChartData.currentSubscriber){
97 // this.subscriberStatusModal();
98 // }
99 // else{
100 // this.selectSubscriberModal();
101 // }
102 // });
Matteo Scandolo574c73f2016-03-01 17:08:45 -0800103
104 // listen for subscriber modal event
105 $rootScope.$on('subscriber.modal.open', () => {
Matteo Scandolo574c73f2016-03-01 17:08:45 -0800106 if(ChartData.currentSubscriber){
107 this.currentSubscriber = ChartData.currentSubscriber;
108 this.subscriberStatusModal();
109 }
110 else{
111 this.selectSubscriberModal();
112 }
Matteo Scandolo388795a2016-02-22 09:57:55 -0800113 });
114
Matteo Scandolo7547f042016-02-09 09:13:30 -0800115 }
116 };
117 });
118})();