2 'app/gbp/common/gbp.service',
3 'app/gbp/resolved-policy/resolved-policy-list.service',
4 'app/gbp/endpoints/sxp-mapping-list.service'
8 angular.module('app.gbp').controller('RootGbpCtrl', RootGbpCtrl);
10 RootGbpCtrl.$inject = ['$mdDialog', '$rootScope', '$scope', '$state',
11 'EndpointsListService', 'NextTopologyService', 'ResolvedPolicyListService', 'RootGbpService',
12 'TenantListService', 'SxpMappingListService'];
14 function RootGbpCtrl($mdDialog, $rootScope, $scope, $state,
15 EndpointsListService, NextTopologyService, ResolvedPolicyListService, RootGbpService,
16 TenantListService, SxpMappingListService) {
19 $scope.apiType = 'operational';
20 $scope.activeObject = null;
21 $scope.endpoints = EndpointsListService.createList();
22 $scope.endpointSgtList = SxpMappingListService.createList();
24 $scope.rootTenant = null;
25 $scope.rootTenants = TenantListService.createList();
26 $scope.resolvedPolicy = {};
27 $scope.sidePanelObject = null;
28 $scope.sidePanelPage = false;
29 $scope.sidePanelPageEndpoint = false;
30 $scope.stateUrl = null;
31 $scope.topologyData = { nodes: [], links: [] };
32 $scope.viewPath = 'src/app/gbp/';
34 var resolvedPolicies = ResolvedPolicyListService.createList();
35 getResolvedPolicies();
38 $scope.broadcastFromRoot = broadcastFromRoot;
39 $scope.closeSidePanel = closeSidePanel;
40 $scope.openSfcDialog = openSfcDialog;
41 $scope.openSidePanel = openSidePanel;
42 $scope.setRootTenant = setRootTenant;
43 $scope.fillTopologyData = fillTopologyData;
44 $scope.highlightNode = highlightNode;
45 $scope.highlightLink = highlightLink;
46 $scope.fadeAll = fadeAll;
47 $scope.rootOpenEndpointDialog = rootOpenEndpointDialog;
48 $scope.rootDeleteEndpointDialog = rootDeleteEndpointDialog;
50 RootGbpService.setMainClass();
60 function broadcastFromRoot(eventName, val) {
61 $scope.$broadcast(eventName, val);
67 function closeSidePanel() {
68 if($scope.sidePanelPage) {
69 $scope.sidePanelPage = false;
70 $scope.sidePanelObject = null;
81 * @returns {{id: string, source: *, target: *, tenant: *}}
83 function createLink( linkId, type) {
84 var linkIdParts = linkId.split('++');
87 'source': linkIdParts[1],
88 'target': linkIdParts[2],
89 'tenant': $scope.rootTenant,
100 function createNode(nodeName) {
103 'tenantId': $scope.rootTenant,
113 $rootScope.nxTopology && NextTopologyService.fadeInAllLayers($rootScope.nxTopology);
117 * reads resolvedPolicies list, prepares nodes and links for topology and fills them
119 function fillTopologyData() {
120 var tempTopoData = {nodes: [], links: []};
121 $scope.resolvedPolicy = resolvedPolicies.aggregateResolvedPolicies();
123 tempTopoData.nodes = Object.keys($scope.resolvedPolicy.epgs).map(function (key) {
124 return createNode(key);
127 tempTopoData.links = Object.keys($scope.resolvedPolicy.contracts).map(function (key) {
128 return createLink(key, $scope.resolvedPolicy.contracts[key].type);
131 $scope.topologyData = tempTopoData;
132 $scope.topologyLoaded = true;
135 function getResolvedPolicies() {
136 if($scope.rootTenant) {
137 resolvedPolicies.get($scope.rootTenant, fillTopologyData);
145 function highlightNode(node) {
146 NextTopologyService.highlightNode($rootScope.nxTopology, node);
153 function highlightLink(link) {
154 NextTopologyService.highlightLink($rootScope.nxTopology, link);
161 $scope.rootTenants.clearData();
162 $scope.rootTenants.get('config');
163 $state.go('main.gbp.index.resolvedPolicy');
164 $scope.endpointSgtList.get();
173 function openSfcDialog(chainName) {
175 clickOutsideToClose: true,
176 controller: 'SfcTopologyController',
178 templateUrl: $scope.viewPath + 'sfc/dialog-sfc-topology.tpl.html',
179 parent: angular.element(document.body),
189 * Sets '$scope.sidePanelPage' to true. This variable is watched in index.tpl.html template
190 * and opens/closes side panel
192 function openSidePanel(page, object, type, element) {
193 $scope.sidePanelPage = page;
194 $scope.sidePanelObject = object;
198 $scope.innerObj.subject = element;
201 $scope.innerObj.clause = element;
204 $scope.innerObj.rule = element;
213 function setRootTenant() {
214 $scope.broadcastFromRoot('ROOT_TENANT_CHANGED');
216 if ($scope.stateUrl.startsWith('/resolved-policy')) {
217 getResolvedPolicies();
218 if($scope.sidePanelObject) {
219 if($scope.sidePanelObject['contract-id'])
220 openSidePanel('resolved-policy/sidepanel/views/contract-list-sidepanel');
222 openSidePanel('resolved-policy/sidepanel/views/epg-list-sidepanel');
228 * fills $scope.stateUrl with loaded url
229 * It's called on $viewContentLoaded event
231 function setStateUrl() {
232 $scope.stateUrl = $state.current.url;
235 if ($scope.stateUrl.startsWith('/resolved-policy')) {
236 getResolvedPolicies();
240 function rootOpenEndpointDialog(operation, endpointData) {
241 $scope.disableKeyFieldsEditing = operation === 'edit';
243 clickOutsideToClose: true,
244 controller: 'AddEndpointController',
246 templateUrl: $scope.viewPath + 'endpoints/dialog-add-endpoint.tpl.html',
247 parent: angular.element(document.body),
250 endpoint: endpointData
255 function rootDeleteEndpointDialog(endpointData) {
256 var confirm = $mdDialog.confirm()
257 .title('Delete endpoint')
258 .textContent('Do you want to delete endpoint?')
262 $mdDialog.show(confirm).then(function () {
263 endpointData.deleteEndpoint(function () {
264 $scope.$broadcast('endpointChanged');
271 /* event listeners */
273 * Event fired after content loaded, setStateUrl function is called to fill stateUrl method
275 $scope.$on('$viewContentLoaded', setStateUrl);