blob: ce81beccf3fe8104e0c60a235fe655df42c96025 [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
23 svg = d3.select(el)
24 .append('svg')
25 .style('width', `${el.clientWidth}px`)
26 .style('height', `${el.clientHeight}px`);
27 }
28
Matteo Scandolo0344ef32016-02-22 16:53:22 -080029 ChartData.getLogicTree()
30 .then((tree) => {
31 LogicTopologyHelper.updateTree(svg);
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080032 });
33
34 $scope.$watch(() => this.selected, (selected) => {
35 if(selected){
Matteo Scandolo0344ef32016-02-22 16:53:22 -080036 ChartData.selectSubscriber(selected);
37 LogicTopologyHelper.updateTree(svg);
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080038 }
39 });
40
Matteo Scandoloc303fd02016-02-17 15:11:33 -080041 $rootScope.$on('instance.detail.hide', () => {
42 this.hideInstanceStats = true;
43 $timeout(() => {
44 this.selectedInstances = [];
Matteo Scandolo0344ef32016-02-22 16:53:22 -080045 ChartData.highlightInstances([]);
Matteo Scandoloc303fd02016-02-17 15:11:33 -080046 LogicTopologyHelper.updateTree(svg);
47 }, 500);
48 });
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080049
Matteo Scandoloc303fd02016-02-17 15:11:33 -080050 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandolo0344ef32016-02-22 16:53:22 -080051 ChartData.getInstanceStatus(service)
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080052 .then((instances) => {
Matteo Scandolo06afdfe2016-02-23 13:47:14 -080053 // this.hideInstanceStats = false;
54 // // HACK if array is empty wait for animation
55 // if(instances.length === 0){
56 // this.hideInstanceStats = true;
57 // $timeout(() => {
58 // this.selectedInstances = instances;
59 // }, 500);
60 // }
61 // else{
62 // this.selectedInstances = instances;
63 // }
Matteo Scandoloc303fd02016-02-17 15:11:33 -080064 LogicTopologyHelper.updateTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080065 })
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080066 })
67
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080068 handleSvg($element[0]);
Matteo Scandolo7fd4d042016-02-16 14:44:51 -080069 LogicTopologyHelper.setupTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080070
Matteo Scandolocc8fa152016-02-22 09:57:55 -080071 this.openSubscriberModal = () => {
72 this.subscriberModal = true;
73 $scope.$apply();
74 };
75
Matteo Scandolocc8fa152016-02-22 09:57:55 -080076 // listen for subscriber modal event
77 $rootScope.$on('subscriber.modal.open', () => {
78 this.openSubscriberModal();
79 });
80
Matteo Scandolo735606c2016-02-09 09:13:30 -080081 }
82 };
83 });
84})();