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 = ['$filter', '$mdDialog', '$rootScope', '$scope', '$state',
11 'EndpointsListService', 'NextTopologyService', 'ResolvedPolicyListService', 'RootGbpService',
12 'TenantListService', 'SxpMappingListService'];
14 function RootGbpCtrl($filter, $mdDialog, $rootScope, $scope, $state,
15 EndpointsListService, NextTopologyService, ResolvedPolicyListService, RootGbpService,
16 TenantListService, SxpMappingListService) {
18 $scope.apiType = 'operational';
19 $scope.activeObject = null;
20 $scope.endpoints = EndpointsListService.createList();
21 $scope.endpointSgtList = SxpMappingListService.createList();
23 $scope.rootTenant = null;
24 $scope.rootTenants = TenantListService.createList();
25 $scope.resolvedPolicy = {};
26 $scope.sidePanelObject = null;
27 $scope.sidePanelPage = false;
28 $scope.sidePanelPageEndpoint = false;
29 $scope.stateUrl = null;
30 $scope.topologyData = { nodes: [], links: [] };
31 $scope.viewPath = 'src/app/gbp/';
33 var resolvedPolicies = ResolvedPolicyListService.createList();
34 getResolvedPolicies();
37 $scope.broadcastFromRoot = broadcastFromRoot;
38 $scope.closeSidePanel = closeSidePanel;
39 $scope.openSfcDialog = openSfcDialog;
40 $scope.openSidePanel = openSidePanel;
41 $scope.setRootTenant = setRootTenant;
42 $scope.fillTopologyData = fillTopologyData;
43 $scope.highlightNode = highlightNode;
44 $scope.highlightLink = highlightLink;
45 $scope.fadeAll = fadeAll;
46 $scope.rootOpenEndpointDialog = rootOpenEndpointDialog;
47 $scope.rootDeleteEndpointDialog = rootDeleteEndpointDialog;
49 RootGbpService.setMainClass();
59 function broadcastFromRoot(eventName, val) {
60 $scope.$broadcast(eventName, val);
66 function closeSidePanel() {
67 if($scope.sidePanelPage) {
68 $scope.sidePanelPage = false;
69 $scope.sidePanelObject = null;
80 * @returns {{id: string, source: *, target: *, tenant: *}}
82 function createLink( linkId, type) {
83 var linkIdParts = linkId.split('_');
86 'source': linkIdParts[1],
87 'target': linkIdParts[2],
88 'tenant': $scope.rootTenant,
99 function createNode(nodeName) {
102 'tenantId': $scope.rootTenant,
112 $rootScope.nxTopology && NextTopologyService.fadeInAllLayers($rootScope.nxTopology);
116 * reads resolvedPolicies list, prepares nodes and links for topology and fills them
118 function fillTopologyData() {
119 var tempTopoData = {nodes: [], links: []};
120 $scope.resolvedPolicy = resolvedPolicies.aggregateResolvedPolicies();
122 tempTopoData.nodes = Object.keys($scope.resolvedPolicy.epgs).map(function (key) {
123 return createNode(key);
126 tempTopoData.links = Object.keys($scope.resolvedPolicy.contracts).map(function (key) {
127 return createLink(key, $scope.resolvedPolicy.contracts[key].type);
130 $scope.topologyData = tempTopoData;
131 $scope.topologyLoaded = true;
134 function getResolvedPolicies() {
135 if($scope.rootTenant) {
136 resolvedPolicies.get($scope.rootTenant, fillTopologyData);
144 function highlightNode(node) {
145 NextTopologyService.highlightNode($rootScope.nxTopology, node);
152 function highlightLink(link) {
153 NextTopologyService.highlightLink($rootScope.nxTopology, link);
160 $scope.rootTenants.clearData();
161 $scope.rootTenants.get('config');
162 $state.go('main.gbp.index.resolvedPolicy');
163 $scope.endpointSgtList.get();
172 function openSfcDialog(chainName) {
174 clickOutsideToClose: true,
175 controller: 'SfcTopologyController',
177 templateUrl: $scope.viewPath + 'sfc/dialog-sfc-topology.tpl.html',
178 parent: angular.element(document.body),
188 * Sets '$scope.sidePanelPage' to true. This variable is watched in index.tpl.html template
189 * and opens/closes side panel
191 function openSidePanel(page, object, type, element) {
192 $scope.sidePanelPage = page;
193 $scope.sidePanelObject = object;
197 $scope.innerObj.subject = element;
200 $scope.innerObj.clause = element;
203 $scope.innerObj.rule = element;
212 function setRootTenant() {
213 $scope.broadcastFromRoot('ROOT_TENANT_CHANGED');
215 if ($scope.stateUrl.startsWith('/resolved-policy')) {
216 getResolvedPolicies();
217 if($scope.sidePanelObject) {
218 if($scope.sidePanelObject['contract-id'])
219 openSidePanel('resolved-policy/sidepanel/views/contract-list-sidepanel');
221 openSidePanel('resolved-policy/sidepanel/views/epg-list-sidepanel');
227 * fills $scope.stateUrl with loaded url
228 * It's called on $viewContentLoaded event
230 function setStateUrl() {
231 $scope.stateUrl = $state.current.url;
234 if ($scope.stateUrl.startsWith('/resolved-policy')) {
235 getResolvedPolicies();
239 function rootOpenEndpointDialog(operation, endpointData) {
240 $scope.disableKeyFieldsEditing = operation === 'edit';
242 clickOutsideToClose: true,
243 controller: 'AddEndpointController',
245 templateUrl: $scope.viewPath + 'endpoints/dialog-add-endpoint.tpl.html',
246 parent: angular.element(document.body),
249 endpoint: endpointData
254 function rootDeleteEndpointDialog(endpointData) {
255 var confirm = $mdDialog.confirm()
256 .title('Delete endpoint')
257 .textContent('Do you want to delete endpoint?')
261 $mdDialog.show(confirm).then(function () {
262 endpointData.deleteEndpoint(function () {
263 $scope.$broadcast('endpointChanged');
270 /* event listeners */
272 * Event fired after content loaded, setStateUrl function is called to fill stateUrl method
274 $scope.$on('$viewContentLoaded', setStateUrl);