summaryrefslogtreecommitdiffstats
path: root/vbd/gui/module/src/main/resources/vpp/controllers/bdm.controller.js
blob: b49fe8af89ebbb13c66646459229b946a0d57698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

define(['app/vpp/vpp.module'], function(vpp) {
    vpp.register.controller('bdmCtrl', ['$scope', '$rootScope','$filter', 'dataService', 'toastService', function ($scope, $rootScope, filter, dataService, toastService) {

    }]);

    vpp.register.controller('TableController', ['$scope', '$rootScope','$filter', 'dataService', 'toastService', function ($scope, $rootScope, filter, dataService, toastService) {
        var vm = this;
        vm.rowCollection = dataService.tableContent;
        vm.displayedCollection = [].concat(vm.rowCollection);
        vm.updateAssignment = function(receivedInterface) {
            var interf = _.find(dataService.interfaces, {name: receivedInterface.name, 'phys-address': receivedInterface['phys-address']});
            angular.copy(receivedInterface, interf);
            if (interf.assigned){
                interf['v3po:l2']['bridge-domain'] = dataService.selectedBd.name;
            } else {
                interf['v3po:l2']['bridge-domain'] = '';
            }
            dataService.injectBridgeDomainsTopoElements();
            dataService.buildTableContent();
            var previouslyChangedInterface = _.find(dataService.changedInterfaces, {name: interf.name, 'phys-address': interf['phys-address']});
            if (!previouslyChangedInterface) {
                dataService.changedInterfaces.push(interf);
            }
            console.log(dataService.changedInterfaces);
        };
    }]);

    vpp.register.controller('BridgeDomainsController', ['$scope', '$rootScope','$filter', 'dataService', 'bdmBridgeDomainService', 'toastService',
        function($scope, $rootScope, $filter, dataService, bdmBridgeDomainService, toastService) {
            $scope.addBd = function() {
                var obj = bdmBridgeDomainService.createObj('vBD' + ((Math.random() * 100) + 1) );

                bdmBridgeDomainService.add(obj,
                    function(data) {
                        console.log('successadding vbd');
                    },
                    function() {
                        console.warn('add bd failed');
                    });
            };

            /*var vm = this;
            vm.dataService = dataService;

            dataService.nextApp.container(document.getElementById('bridge-domains-next-app'));
            dataService.bridgeDomainsTopo.attach(dataService.nextApp);

            window.addEventListener('resize', function () {
                if ($location.path() === '/bridgedomains') {
                    dataService.topo.adaptToContainer();
                }
            });

            vm.bridgedomains = dataService.bridgedomains;
            vm.selectedBd = dataService.selectedBd;

            dataService.bridgeDomainsTopo.on('clickNode',function(topo,node) {
                console.log(node);
            });

            vm.bdChanged = function() {
                dataService.injectBridgeDomainsTopoElements();
                dataService.buildTableContent();
            };

            vm.addBd = function() {
                //show dialog
                $mdDialog.show({
                    controller: function() {
                        var vm = this;
                        vm.bd = {};
                        vm.waiting = false;

                        //function called when the cancel button ( 'x' in the top right) is clicked
                        vm.close = function() {
                            $mdDialog.cancel();
                        };

                        vm.isDone = function(status) {
                            vm.waiting = false;
                            if (status === 'success') {
                                dataService.bridgedomains.push(vm.bd);
                                dataService.selectedBd.name = vm.bd.name;
                                dataService.injectBridgeDomainsTopoElements();
                                dataService.buildTableContent();
                                vm.close();
                            }
                        };

                        //function called when the update button is clicked
                        vm.updateConfig = function() {
                            vm.waiting = true;
                            //send a POST with the entered content in the form field

                        };
                    },
                    controllerAs: 'NewBdDialogCtrl',
                    templateUrl: 'templates/new-bd-dialog.html',
                    parent: angular.element(document.body),
                    clickOutsideToClose:false
                })
            };



            vm.deploy = function() {

            };

            vm.removeBd = function() {
                if(vm.selectedBd.name) {
                    var successCallback = function(success) {
                        if (success) {
                            console.log(vm.bridgedomains);
                            _.remove(vm.bridgedomains, {
                                name: vm.selectedBd.name
                            });
                            toastService.showToast('Bridge Domain Removed!');
                            vm.selectedBd.name = '';
                            dataService.clearInjectedInterfacesInBridgeDomainTopo();
                            dataService.injectBdIntoBridgeDomainsTopo();
                            dataService.tableContent.length = 0;
                        } else {
                            toastService.showToast('Error removing Bridge Domain!');

                        }
                    };

                    //... removeBdFromOdl(vm.selectedBd.name, successCallback);
                }
            };
            */
    }]);
});