SFC topology
[groupbasedpolicy.git] / groupbasedpolicy-ui / module / src / main / resources / gbp / sfc / dialog-sfc-topology.controller.js
1 define([
2     'app/gbp/sfc/sfc.service'
3 ], function () {
4     'use strict';
5
6     angular.module('app.gbp').controller('SfcTopologyController', SfcTopologyController);
7
8     SfcTopologyController.$inject = ['$filter', '$mdDialog', '$scope', 'chainName', 'SfcService'];
9     /* @ngInject */
10     function SfcTopologyController($filter, $mdDialog, $scope, chainName, SfcService) {
11         /* properties */
12         $scope.chain = SfcService.createObject({name: 'SFCGBP'});
13         $scope.topologyDataSfc = {nodes:[], links:[]};
14         $scope.cbkFunctionsSfc = {
15             clickNode: function(node){
16
17             },
18             clickLink: function(link){
19
20             },
21             topologyGenerated: function(){
22             }
23         };
24
25         /* methods */
26         $scope.closeDialog = closeDialog;
27
28         /* Implementations */
29
30         $scope.chain.get(function() {
31             $scope.chain.data && $scope.chain.data['sfc-service-function'] &&
32                 $scope.chain.data['sfc-service-function'].length && $scope.viewTopology();
33
34             $scope.topologyLoaded = true;
35         });
36
37         function closeDialog(){
38             $mdDialog.cancel();
39         }
40
41         function fillTopologyDataSfc() {
42             var topoData = {nodes:[], links:[]};
43             $scope.chain.data['sfc-service-function'].forEach(function(sf) {
44                 topoData.nodes.push({id: sf.name, 'node-id': sf.name, label: sf.name, type: sf.name});
45             })
46
47             $scope.topologyDataSfc = topoData;
48         }
49
50         $scope.viewTopology = function() {
51             $scope.topologySfc = new nx.graphic.Topology({
52                 height: 400,
53                 width: 600,
54                 scalable: true,
55                 theme:'blue',
56                 enableGradualScaling:true,
57                 nodeConfig: {
58                     color: '#0386d2',
59                     label: 'model.label',
60                     //scale: 'model.scale',
61                     iconType: function(vertex) {
62                         var type = vertex.get().type;
63                         switch (type) {
64                             case 'service-function-type:firewall':
65                                 return 'firewall';
66                             case 'service-function-type:dpi':
67                                 return 'accesspoint';
68                             default:
69                                 return 'unknown';
70                         }
71                     }
72                 },
73                 linkConfig: {
74                     label: 'model.label',
75                     linkType: 'parallel',
76                     color: '#0386d2',
77                     width: 5
78                 },
79                 showIcon: true,
80                 //dataProcessor: 'force',
81                 //autoLayout: true,
82                 enableSmartNode: false,
83                 tooltipManagerConfig: {
84                     showNodeTooltip: false,
85                     showLinkTooltip: false
86                 }
87             });
88             $scope.app =  new nx.ui.Application;
89
90             var nodes = [];
91             var links = [];
92
93             $scope.chain.data['sfc-service-function'].forEach(function(sf, index) {
94                 nodes.push({
95                     id: sf.name,
96                     label: sf.name,
97                     type: sf.type,
98                     x: 100*(index+1),
99                     y: 400
100                 });
101
102                 index>0 && links.push({
103                     source: index-1,
104                     target: index
105                 });
106             })
107
108             $scope.topologySfc.data({
109                 nodes: nodes,
110                 links: links
111             });
112
113             $scope.app.container(document.getElementById('next-vpp-topo'));
114             $scope.topologySfc.attach($scope.app);
115         };
116
117
118     }
119 });