blob: f6798c6ead07df25de256aa32655474d9bcb5896 [file] [log] [blame]
Matteo Scandolo7547f042016-02-09 09:13:30 -08001(function () {
2 'use strict';
3 angular.module('xos.serviceTopology')
4 .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 Scandolo26d17e12016-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 Scandoloc49ff702016-02-17 15:11:33 -080064 LogicTopologyHelper.updateTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080065 })
Matteo Scandolo79de20a2016-02-16 15:06:11 -080066 })
67
Matteo Scandolo219b1a72016-02-09 11:19:22 -080068 handleSvg($element[0]);
Matteo Scandolo35d53c82016-02-16 14:44:51 -080069 LogicTopologyHelper.setupTree(svg);
Matteo Scandolo51031482016-02-17 13:54:11 -080070
Matteo Scandolo388795a2016-02-22 09:57:55 -080071 this.openSubscriberModal = () => {
72 this.subscriberModal = true;
73 $scope.$apply();
74 };
75
Matteo Scandolo388795a2016-02-22 09:57:55 -080076 // listen for subscriber modal event
77 $rootScope.$on('subscriber.modal.open', () => {
78 this.openSubscriberModal();
79 });
80
Matteo Scandolo7547f042016-02-09 09:13:30 -080081 }
82 };
83 });
84})();