blob: b12bfb530e24a139c0d94f1b9ba368c5a8a10d8e [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 Scandolo388795a2016-02-22 09:57:55 -080060 this.openSubscriberModal = () => {
61 this.subscriberModal = true;
62 $scope.$apply();
63 };
64
Matteo Scandolo388795a2016-02-22 09:57:55 -080065 // listen for subscriber modal event
66 $rootScope.$on('subscriber.modal.open', () => {
67 this.openSubscriberModal();
68 });
69
Matteo Scandolo7547f042016-02-09 09:13:30 -080070 }
71 };
72 });
73})();