blob: edd64ea1859af99707267b9dba648622650dfc34 [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 Scandolo012dddb2016-02-22 16:53:22 -080029 ChartData.getLogicTree()
30 .then((tree) => {
31 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo219b1a72016-02-09 11:19:22 -080032 });
33
34 $scope.$watch(() => this.selected, (selected) => {
35 if(selected){
Matteo Scandolo012dddb2016-02-22 16:53:22 -080036 ChartData.selectSubscriber(selected);
37 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo219b1a72016-02-09 11:19:22 -080038 }
39 });
40
Matteo Scandoloc49ff702016-02-17 15:11:33 -080041 $rootScope.$on('instance.detail.hide', () => {
42 this.hideInstanceStats = true;
43 $timeout(() => {
44 this.selectedInstances = [];
Matteo Scandolo012dddb2016-02-22 16:53:22 -080045 ChartData.highlightInstances([]);
Matteo Scandoloc49ff702016-02-17 15:11:33 -080046 LogicTopologyHelper.updateTree(svg);
47 }, 500);
48 });
Matteo Scandolo79de20a2016-02-16 15:06:11 -080049
Matteo Scandoloc49ff702016-02-17 15:11:33 -080050 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandolo012dddb2016-02-22 16:53:22 -080051 ChartData.getInstanceStatus(service)
Matteo Scandolo51031482016-02-17 13:54:11 -080052 .then((instances) => {
Matteo Scandoloc49ff702016-02-17 15:11:33 -080053 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080054 })
Matteo Scandolo79de20a2016-02-16 15:06:11 -080055 })
56
Matteo Scandolo219b1a72016-02-09 11:19:22 -080057 handleSvg($element[0]);
Matteo Scandolo35d53c82016-02-16 14:44:51 -080058 LogicTopologyHelper.setupTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080059
Matteo Scandolo574c73f2016-03-01 17:08:45 -080060 this.selectSubscriberModal = () => {
61 this.openSelectSubscriberModal = true;
62 $scope.$apply();
63 };
64
65 this.subscriberStatusModal = () => {
66 this.openSubscriberStatusModal = true;
Matteo Scandolo388795a2016-02-22 09:57:55 -080067 $scope.$apply();
68 };
69
Matteo Scandolo388795a2016-02-22 09:57:55 -080070 // listen for subscriber modal event
71 $rootScope.$on('subscriber.modal.open', () => {
Matteo Scandolo574c73f2016-03-01 17:08:45 -080072
73 if(ChartData.currentSubscriber){
74 this.subscriberStatusModal();
75 }
76 else{
77 this.selectSubscriberModal();
78 }
79 });
80
81 // listen for subscriber modal event
82 $rootScope.$on('subscriber.modal.open', () => {
83
84 if(ChartData.currentSubscriber){
85 this.currentSubscriber = ChartData.currentSubscriber;
86 this.subscriberStatusModal();
87 }
88 else{
89 this.selectSubscriberModal();
90 }
Matteo Scandolo388795a2016-02-22 09:57:55 -080091 });
92
Matteo Scandolo7547f042016-02-09 09:13:30 -080093 }
94 };
95 });
96})();