blob: f88b80ab06f86f7fbc7aa6bdeea6dc9e68733699 [file] [log] [blame]
Matteo Scandolo735606c2016-02-09 09:13:30 -08001(function () {
2 'use strict';
Matteo Scandolo4b3d8722016-02-24 11:22:48 -08003 angular.module('xos.diagnostic')
Matteo Scandolo735606c2016-02-09 09:13:30 -08004 .directive('logicTopology', function(){
5 return {
6 restrict: 'E',
7 scope: {
Matteo Scandoloeeb9c082016-02-09 11:19:22 -08008 subscribers: '=',
9 selected: '='
Matteo Scandolo735606c2016-02-09 09:13:30 -080010 },
11 bindToController: true,
12 controllerAs: 'vm',
Matteo Scandoloc303fd02016-02-17 15:11:33 -080013 templateUrl: 'templates/logicTopology.tpl.html',
Matteo Scandolo0344ef32016-02-22 16:53:22 -080014 controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig, ChartData){
Matteo Scandolo735606c2016-02-09 09:13:30 -080015 $log.info('Logic Plane');
16
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080017 var svg;
Matteo Scandoloc303fd02016-02-17 15:11:33 -080018 this.selectedInstances = [];
19 this.hideInstanceStats = true;
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080020
21 const handleSvg = (el) => {
22
Matteo Scandolod54a7fd2016-03-08 09:33:26 -080023 d3.select($element[0]).select('svg').remove();
24
Matteo Scandolo594dfbc2016-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 Scandolod1b3bf52016-03-07 16:42:03 -080031 const loadGlobalScope = () => {
32 ChartData.getLogicTree()
33 .then((tree) => {
34 LogicTopologyHelper.updateTree(svg);
35 });
36 }
37 loadGlobalScope();
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080038
39 $scope.$watch(() => this.selected, (selected) => {
40 if(selected){
Matteo Scandolo0344ef32016-02-22 16:53:22 -080041 ChartData.selectSubscriber(selected);
42 LogicTopologyHelper.updateTree(svg);
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080043 }
Matteo Scandolod1b3bf52016-03-07 16:42:03 -080044 else{
45 ChartData.removeSubscriber();
46 LogicTopologyHelper.updateTree(svg);
47 }
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080048 });
49
Matteo Scandoloc303fd02016-02-17 15:11:33 -080050 $rootScope.$on('instance.detail.hide', () => {
51 this.hideInstanceStats = true;
52 $timeout(() => {
53 this.selectedInstances = [];
Matteo Scandolo0344ef32016-02-22 16:53:22 -080054 ChartData.highlightInstances([]);
Matteo Scandoloc303fd02016-02-17 15:11:33 -080055 LogicTopologyHelper.updateTree(svg);
56 }, 500);
57 });
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080058
Matteo Scandoloc303fd02016-02-17 15:11:33 -080059 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandolo0344ef32016-02-22 16:53:22 -080060 ChartData.getInstanceStatus(service)
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080061 .then((instances) => {
Matteo Scandoloc303fd02016-02-17 15:11:33 -080062 LogicTopologyHelper.updateTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080063 })
Matteo Scandolod54a7fd2016-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 Scandoloedd3d6f2016-02-16 15:06:11 -080072
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080073 handleSvg($element[0]);
Matteo Scandolo7fd4d042016-02-16 14:44:51 -080074 LogicTopologyHelper.setupTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080075
Matteo Scandolo5bb16682016-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 Scandolocc8fa152016-02-22 09:57:55 -080083 $scope.$apply();
84 };
85
Matteo Scandolocc8fa152016-02-22 09:57:55 -080086 // listen for subscriber modal event
87 $rootScope.$on('subscriber.modal.open', () => {
Matteo Scandolo5bb16682016-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 Scandolocc8fa152016-02-22 09:57:55 -0800107 });
108
Matteo Scandolo735606c2016-02-09 09:13:30 -0800109 }
110 };
111 });
112})();