blob: f88b80ab06f86f7fbc7aa6bdeea6dc9e68733699 [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 Scandolocc0db942016-02-11 17:37:08 -080020
21 const handleSvg = (el) => {
22
Matteo Scandolo79108192016-03-08 09:33:26 -080023 d3.select($element[0]).select('svg').remove();
24
Matteo Scandolocc0db942016-02-11 17:37:08 -080025 svg = d3.select(el)
26 .append('svg')
27 .style('width', `${el.clientWidth}px`)
28 .style('height', `${el.clientHeight}px`);
29 }
30
Matteo Scandolo3a176a22016-03-07 16:42:03 -080031 const loadGlobalScope = () => {
32 ChartData.getLogicTree()
33 .then((tree) => {
34 LogicTopologyHelper.updateTree(svg);
35 });
36 }
37 loadGlobalScope();
Matteo Scandolo219b1a72016-02-09 11:19:22 -080038
39 $scope.$watch(() => this.selected, (selected) => {
40 if(selected){
Matteo Scandolo012dddb2016-02-22 16:53:22 -080041 ChartData.selectSubscriber(selected);
42 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo219b1a72016-02-09 11:19:22 -080043 }
Matteo Scandolo3a176a22016-03-07 16:42:03 -080044 else{
45 ChartData.removeSubscriber();
46 LogicTopologyHelper.updateTree(svg);
47 }
Matteo Scandolo219b1a72016-02-09 11:19:22 -080048 });
49
Matteo Scandoloc49ff702016-02-17 15:11:33 -080050 $rootScope.$on('instance.detail.hide', () => {
51 this.hideInstanceStats = true;
52 $timeout(() => {
53 this.selectedInstances = [];
Matteo Scandolo012dddb2016-02-22 16:53:22 -080054 ChartData.highlightInstances([]);
Matteo Scandoloc49ff702016-02-17 15:11:33 -080055 LogicTopologyHelper.updateTree(svg);
56 }, 500);
57 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080058
Matteo Scandoloc49ff702016-02-17 15:11:33 -080059 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandolo012dddb2016-02-22 16:53:22 -080060 ChartData.getInstanceStatus(service)
Matteo Scandolo51031482016-02-17 13:54:11 -080061 .then((instances) => {
Matteo Scandoloc49ff702016-02-17 15:11:33 -080062 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080063 })
Matteo Scandolo79108192016-03-08 09:33:26 -080064 });
65
66 d3.select(window)
67 .on('resize.logic', () => {
68 handleSvg($element[0]);
69 LogicTopologyHelper.setupTree(svg);
70 LogicTopologyHelper.updateTree(svg);
71 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080072
Matteo Scandolo219b1a72016-02-09 11:19:22 -080073 handleSvg($element[0]);
Matteo Scandolo35d53c82016-02-16 14:44:51 -080074 LogicTopologyHelper.setupTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080075
Matteo Scandolo574c73f2016-03-01 17:08:45 -080076 this.selectSubscriberModal = () => {
77 this.openSelectSubscriberModal = true;
78 $scope.$apply();
79 };
80
81 this.subscriberStatusModal = () => {
82 this.openSubscriberStatusModal = true;
Matteo Scandolo388795a2016-02-22 09:57:55 -080083 $scope.$apply();
84 };
85
Matteo Scandolo388795a2016-02-22 09:57:55 -080086 // listen for subscriber modal event
87 $rootScope.$on('subscriber.modal.open', () => {
Matteo Scandolo574c73f2016-03-01 17:08:45 -080088
89 if(ChartData.currentSubscriber){
90 this.subscriberStatusModal();
91 }
92 else{
93 this.selectSubscriberModal();
94 }
95 });
96
97 // listen for subscriber modal event
98 $rootScope.$on('subscriber.modal.open', () => {
99
100 if(ChartData.currentSubscriber){
101 this.currentSubscriber = ChartData.currentSubscriber;
102 this.subscriberStatusModal();
103 }
104 else{
105 this.selectSubscriberModal();
106 }
Matteo Scandolo388795a2016-02-22 09:57:55 -0800107 });
108
Matteo Scandolo7547f042016-02-09 09:13:30 -0800109 }
110 };
111 });
112})();