blob: 722328d5aefbb7f3ce93134b0cb04c85770e7afc [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
23 svg = d3.select(el)
24 .append('svg')
25 .style('width', `${el.clientWidth}px`)
26 .style('height', `${el.clientHeight}px`);
27 }
28
Matteo Scandolo3a176a22016-03-07 16:42:03 -080029 const loadGlobalScope = () => {
30 ChartData.getLogicTree()
31 .then((tree) => {
32 LogicTopologyHelper.updateTree(svg);
33 });
34 }
35 loadGlobalScope();
Matteo Scandolo219b1a72016-02-09 11:19:22 -080036
37 $scope.$watch(() => this.selected, (selected) => {
38 if(selected){
Matteo Scandolo012dddb2016-02-22 16:53:22 -080039 ChartData.selectSubscriber(selected);
40 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo219b1a72016-02-09 11:19:22 -080041 }
Matteo Scandolo3a176a22016-03-07 16:42:03 -080042 else{
43 ChartData.removeSubscriber();
44 LogicTopologyHelper.updateTree(svg);
45 }
Matteo Scandolo219b1a72016-02-09 11:19:22 -080046 });
47
Matteo Scandoloc49ff702016-02-17 15:11:33 -080048 $rootScope.$on('instance.detail.hide', () => {
49 this.hideInstanceStats = true;
50 $timeout(() => {
51 this.selectedInstances = [];
Matteo Scandolo012dddb2016-02-22 16:53:22 -080052 ChartData.highlightInstances([]);
Matteo Scandoloc49ff702016-02-17 15:11:33 -080053 LogicTopologyHelper.updateTree(svg);
54 }, 500);
55 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080056
Matteo Scandoloc49ff702016-02-17 15:11:33 -080057 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandolo012dddb2016-02-22 16:53:22 -080058 ChartData.getInstanceStatus(service)
Matteo Scandolo51031482016-02-17 13:54:11 -080059 .then((instances) => {
Matteo Scandoloc49ff702016-02-17 15:11:33 -080060 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080061 })
Matteo Scandolo79de20a2016-02-16 15:06:11 -080062 })
63
Matteo Scandolo219b1a72016-02-09 11:19:22 -080064 handleSvg($element[0]);
Matteo Scandolo35d53c82016-02-16 14:44:51 -080065 LogicTopologyHelper.setupTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080066
Matteo Scandolo574c73f2016-03-01 17:08:45 -080067 this.selectSubscriberModal = () => {
68 this.openSelectSubscriberModal = true;
69 $scope.$apply();
70 };
71
72 this.subscriberStatusModal = () => {
73 this.openSubscriberStatusModal = true;
Matteo Scandolo388795a2016-02-22 09:57:55 -080074 $scope.$apply();
75 };
76
Matteo Scandolo388795a2016-02-22 09:57:55 -080077 // listen for subscriber modal event
78 $rootScope.$on('subscriber.modal.open', () => {
Matteo Scandolo574c73f2016-03-01 17:08:45 -080079
80 if(ChartData.currentSubscriber){
81 this.subscriberStatusModal();
82 }
83 else{
84 this.selectSubscriberModal();
85 }
86 });
87
88 // listen for subscriber modal event
89 $rootScope.$on('subscriber.modal.open', () => {
90
91 if(ChartData.currentSubscriber){
92 this.currentSubscriber = ChartData.currentSubscriber;
93 this.subscriberStatusModal();
94 }
95 else{
96 this.selectSubscriberModal();
97 }
Matteo Scandolo388795a2016-02-22 09:57:55 -080098 });
99
Matteo Scandolo7547f042016-02-09 09:13:30 -0800100 }
101 };
102 });
103})();