diff options
author | 2016-02-05 13:26:48 +0100 | |
---|---|---|
committer | 2016-02-06 03:57:32 +0000 | |
commit | 03b448f806cc561f62941e231f3de9e38e8b9a4e (patch) | |
tree | 309b97eab6581eb4dda4a3ef3746fb4539456b71 /vbd/gui/module/src/main/resources/vpp/controllers | |
parent | 843fe81ebf7f11920a52f625bf863a1fad4d29de (diff) |
Splitting sources
- splitted vpp.controller.js and vpp.services.js into smaller files to
avoid blocking and problems during merging
Change-Id: I379dc1e5154c6f685fb6a976db239b620e58fc6e
Signed-off-by: Daniel Malachovsky <daniel.malachovsky@pantheon.sk>
Diffstat (limited to 'vbd/gui/module/src/main/resources/vpp/controllers')
6 files changed, 508 insertions, 0 deletions
diff --git a/vbd/gui/module/src/main/resources/vpp/controllers/bdm.bridgedomain.controller.js b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.bridgedomain.controller.js new file mode 100644 index 000000000..ea65afbc9 --- /dev/null +++ b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.bridgedomain.controller.js @@ -0,0 +1,18 @@ +/* + * 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('bdmBridgeDomainCtrl', ['$scope', '$rootScope', '$timeout' ,'dataService', 'toastService', '$mdSidenav', '$mdDialog', + function ($scope, $rootScope, $timeout ,dataService, toastService, $mdSidenav, $mdDialog) { + + }]); + + +}); diff --git a/vbd/gui/module/src/main/resources/vpp/controllers/bdm.controller.js b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.controller.js new file mode 100644 index 000000000..02c9879a8 --- /dev/null +++ b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.controller.js @@ -0,0 +1,127 @@ +/* + * 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', function(dataService, $location, $mdDialog, toastService) { + 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); + } + }; + }); +});
\ No newline at end of file diff --git a/vbd/gui/module/src/main/resources/vpp/controllers/bdm.interface.controller.js b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.interface.controller.js new file mode 100644 index 000000000..5aa68a9dc --- /dev/null +++ b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.interface.controller.js @@ -0,0 +1,17 @@ +/* + * 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('bdmInterfaceCtrl', ['$scope', '$rootScope', '$timeout' ,'dataService', 'toastService', '$mdSidenav', '$mdDialog', + function ($scope, $rootScope, $timeout ,dataService, toastService, $mdSidenav, $mdDialog) { + + }]); + + +});
\ No newline at end of file diff --git a/vbd/gui/module/src/main/resources/vpp/controllers/bdm.vpp.controller.js b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.vpp.controller.js new file mode 100644 index 000000000..5ef5c3c6a --- /dev/null +++ b/vbd/gui/module/src/main/resources/vpp/controllers/bdm.vpp.controller.js @@ -0,0 +1,17 @@ +/* + * 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('bdmVppCtrl', ['$scope', '$rootScope', '$timeout' ,'dataService', 'toastService', '$mdSidenav', '$mdDialog', + function ($scope, $rootScope, $timeout ,dataService, toastService, $mdSidenav, $mdDialog) { + + }]); + + +}); diff --git a/vbd/gui/module/src/main/resources/vpp/controllers/inventory.controller.js b/vbd/gui/module/src/main/resources/vpp/controllers/inventory.controller.js new file mode 100644 index 000000000..f447bd0fb --- /dev/null +++ b/vbd/gui/module/src/main/resources/vpp/controllers/inventory.controller.js @@ -0,0 +1,281 @@ +/* + * 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('InventoryTableController', ['$scope', '$rootScope','$filter', 'toastService', 'VppService', '$mdDialog', 'dataService', 'VppInterfaceService', + function($scope, $rootScope, filter, toastService, VppService, $mdDialog, dataService, VppInterfaceService) { + + $scope.getVppList = function() { + $scope.initVppList(); + + VppService.getVppList( + // success callback + function(data) { + $scope.vppList = data; + $scope.$broadcast('RELOAD_VPP_TABLE'); + }, + // error callback + function(res) { + console.warn("Can't load VPPs from controller. Nothing is mounted, or other error", res); + } + ); + }; + + $scope.initVppList = function() { + $scope.vppList = []; + }; + + $scope.viewTopology = function(vpp) { + $mdDialog.show({ + controller: function() { + var vm = this; + + $scope.topo = new nx.graphic.Topology({ + height: 350, + width: 500, + scalable: true, + theme:'blue', + enableGradualScaling:true, + nodeConfig: { + color: '#414040', + label: 'model.label', + scale: 'model.scale', + iconType: function(vertex) { + var type = vertex.get().type; + if (type === 'bd') { + return 'bd' + } else if (type === 'vpp') { + return 'switch' + } else { + return 'interf'; + } + } + }, + linkConfig: { + label: 'model.label', + linkType: 'parallel', + color: function(link) { + if (link.getData().type === 'tunnel') { + return '#00FF00'; + } else { + return '#414040'; + } + }, + width: function(link) { + if (link.getData().type === 'tunnel') { + return 5; + } + } + }, + showIcon: true, + dataProcessor: 'force', + autoLayout: true, + enableSmartNode: false, + tooltipManagerConfig: { + nodeTooltipContentClass: 'TooltipNode', + linkTooltipContentClass: 'TooltipLink' + } + }); + $scope.app = new nx.ui.Application; + + vm.vpp = vpp; + vm.vpp.type = 'vpp'; + vm.vpp.label = vm.vpp.name; + + var nodes = [].concat(vm.vpp); + var links = []; + + _.forEach(vm.vpp.interfaces, function(interf, index){ + interf.label = interf.name; + interf.scale = 0.5; + nodes.push(interf); + links.push({source: 0, target: index + 1}); + }); + + console.log(vpp); + console.log(nodes); + console.log(links); + + $scope.topo.data({ + nodes: nodes, + links: links + }); + + this.close = function() { + $mdDialog.cancel(); + }; + + }, + onComplete: function() { + console.log(document.getElementById('next-vpp-topo')); + $scope.app.container(document.getElementById('next-vpp-topo')); + $scope.topo.attach($scope.app); + + }, + templateUrl: $scope.view_path + 'vpp-topo.html', + controllerAs: 'VppTopoCtrl', + parent: angular.element(document.body), + clickOutsideToClose:true + }) + }; + + $scope.addVppShowForm = function() { + $mdDialog.show({ + controller: function() { + var vm = this; + vm.vpp = {}; + //function called when the cancel button ( 'x' in the top right) is clicked + vm.close = function() { + $mdDialog.cancel(); + }; + + vm.finished = function(successful) { + if (successful) { + vm.close(); + vm.waiting = false; + toastService.showToast('New VPP added!'); + $scope.getVppList(); + } else { + vm.waiting = false; + toastService.showToast('Error adding new VPP'); + } + }; + + //function called when the update button is clicked + vm.updateConfig = function() { + vm.waiting = true; + VppService.mountVpp(vm.vpp.name, vm.vpp.ip, vm.vpp.port, vm.vpp.un, vm.vpp.pw, vm.finished); + }; + }, + controllerAs: 'NewVppDialogCtrl', + templateUrl: $scope.view_path + 'new-vpp-dialog.html', + parent: angular.element(document.body), + clickOutsideToClose:true + }) + }; + + $scope.editVppShowForm = function(vppObject) { + + $mdDialog.show({ + controller: function() { + var vm = this; + + vm.vpp = { + name: vppObject.name, + status: vppObject.status, + ip: vppObject.ipAddress, + port: vppObject.port + }; + + //function called when the cancel button ( 'x' in the top right) is clicked + vm.close = function() { + $mdDialog.cancel(); + }; + + vm.finishedUpdating = function(successful) { + if (successful) { + vm.close(); + vm.waiting = false; + toastService.showToast('VPP configuration updated!'); + $scope.getVppList(); + } else { + vm.waiting = false; + toastService.showToast('Error configuring VPP'); + } + }; + + vm.finishedDeleting = function(successful) { + if (successful) { + VppService.mountVpp(vm.vpp.name, vm.vpp.ip, vm.vpp.port, vm.vpp.un, vm.vpp.pw, vm.finishedUpdating); + $scope.getVppList(); + } else { + vm.waiting = false; + toastService.showToast('Error configuring VPP'); + } + }; + + //function called when the update button is clicked + vm.updateConfig = function() { + //VppService.editVpp(vm.vpp.name, vm.vpp.ip, vm.vpp.port, vm.vpp.un, vm.vpp.pw, vm.finishedUpdating); + VppService.deleteVpp(vm.vpp, vm.finishedDeleting); + }; + }, + controllerAs: 'ConfigVppDialogCtrl', + templateUrl: $scope.view_path + 'config-vpp-dialog.html', + parent: angular.element(document.body), + clickOutsideToClose:true + }); + }; + + $scope.deleteVpp = function(vppObject) { + + var finished = function(successful) { + if (successful) { + toastService.showToast('Removed VPP!'); + $scope.getVppList(); + } else { + toastService.showToast('Error removing VPP'); + } + }; + + VppService.deleteVpp(vppObject, finished); + }; + + $scope.getVppList(); + }]); + + vpp.register.controller('InventoryTableDefinitonController', ['$scope', function($scope) { + + var actionCellTemplate = + '<md-button ng-click="grid.appScope.viewTopology(row.entity)"><span style="color:black !important;">View Topology</span></md-button>' + + '<md-button ng-click="grid.appScope.editVppShowForm(row.entity)" ng-hide="row.entity.status === \'connected\'"><span style="color:black !important;">Edit</span></md-button>' + + '<md-button ng-click="grid.appScope.deleteVpp(row.entity)"><span style="color:black !important;">Delete</span></md-button>'; + + $scope.gridOptions = { + + expandableRowTemplate: $scope.view_path + 'inventory-table-interfaces-subgrid.tpl.html', + //subGridVariable will be available in subGrid scope + expandableRowScope: { + subGridVariable: 'subGridScopeVariable' + } + + } + + $scope.gridOptions.columnDefs = [ + { name: 'name' }, + { name: 'ipAddress'}, + { name: 'port'}, + { name: 'status'}, + { name:' ',cellTemplate: actionCellTemplate} + ]; + + + //$scope.gridOptions.data = $scope.vppList; + + $scope.gridOptions.onRegisterApi = function(gridApi){ + $scope.gridApi = gridApi; + }; + + $scope.$on('RELOAD_VPP_TABLE', function(event) { + $scope.gridOptions.data = $scope.vppList.map(function(item) { + item.subGridOptions = { + columnDefs: [ + { name:"name" }, + { name:"phys-address"}, + { name:"oper-status"} + ], + data: item.interfaces + }; + + return item; + }); + }); + + }]); +});
\ No newline at end of file diff --git a/vbd/gui/module/src/main/resources/vpp/controllers/vpp.controller.js b/vbd/gui/module/src/main/resources/vpp/controllers/vpp.controller.js new file mode 100644 index 000000000..6b2dde830 --- /dev/null +++ b/vbd/gui/module/src/main/resources/vpp/controllers/vpp.controller.js @@ -0,0 +1,48 @@ +/* + * 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 + */ + +var modules = [ + // module + 'app/vpp/vpp.module', + // services + 'app/vpp/services/vpp.services', + 'app/vpp/services/inventory.service', + 'app/vpp/services/bdm.service', + 'app/vpp/services/bdm.bridgedomain.service', + 'app/vpp/services/bdm.interface.service', + 'app/vpp/services/bdm.vpp.service', + //controllers + 'app/vpp/controllers/inventory.controller', + 'app/vpp/controllers/bdm.controller', + 'app/vpp/controllers/bdm.bridgedomain.controller', + 'app/vpp/controllers/bdm.vpp.controller', + 'app/vpp/controllers/bdm.interface.controller' +]; + + +define(modules, function(vpp) { + + vpp.controller('vppCtrl', ['$scope', '$rootScope', '$timeout', 'toastService', '$mdSidenav', '$mdDialog', + function ($scope, $rootScope, $timeout, toastService, $mdSidenav, $mdDialog) { + + $rootScope['section_logo'] = 'src/app/vpp/assets/images/vpp.gif'; + $scope.view_path = 'src/app/vpp/views/'; + + $scope.mainView = "inventory"; + + $scope.setMainView = function(viewName) { + $scope.mainView = viewName; + }; + + + }]); + + +}); + + |