handling cloud owner and lcp region in create port mirroring configuration
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / AddNetworkNodeController.js
1 /*-
2 * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  * 
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  * ============LICENSE_END=========================================================
19 */
20
21 /**
22  * The Instantiation (or View/Edit) Controller controls the instantiation/removal of
23  * deployable objects (Services, VNFs, VF-Modules, Networks, and Volume-Groups)
24  */
25
26 "use strict";
27
28 appDS2.controller("AddNetworkNodeController", ["COMPONENT", "FIELD", "PARAMETER", "DataService", "CreationService", "$scope", "$window", "$location",
29     function (COMPONENT, FIELD, PARAMETER, DataService, CreationService, $scope, $window, $location) {
30
31         $scope.serviceMetadataFields = [];
32         $scope.tenantList = [];
33         $scope.nodeTemplateFields = {};
34         
35         $scope.regexInstanceName = /^([a-z])+([0-9a-z\-_\.]*)$/i;
36         $scope.errorMsg = FIELD.ERROR.INSTANCE_NAME_VALIDATE;
37
38         var handleGetParametersResponse = function(parameters) {
39             $scope.serviceMetadataFields = parameters.summaryList;
40             $scope.tenantList = DataService.getCloudRegionTenantList();
41
42         if(DataService.getPortMirroningConfigFields()){
43             $scope.nodeTemplateFields =DataService.getPortMirroningConfigFields();
44         }else {
45             $scope.nodeTemplateFields = angular.copy(_.keyBy(parameters.userProvidedList, 'id'));
46         }
47
48            $scope.modelName = DataService.getModelInfo(COMPONENT.VNF).modelCustomizationName;
49         };
50
51         CreationService.initializeComponent(COMPONENT.VNF);
52
53         CreationService.getParameters(handleGetParametersResponse);
54
55         $scope.setTenant = function(field)  {
56             var cloudOwnerAndLcpCloudRegion = DataService.getCloudOwnerAndLcpCloudRegionFromOptionId(field.value);
57             $scope.nodeTemplateFields.cloudRegionId = cloudOwnerAndLcpCloudRegion.cloudRegionId;
58             $scope.nodeTemplateFields.cloudOwner = cloudOwnerAndLcpCloudRegion.cloudOwner;
59             $scope.nodeTemplateFields.tenant.optionList = _.filter($scope.tenantList,
60                 {'cloudRegionId': cloudOwnerAndLcpCloudRegion.cloudRegionId, 'isPermitted': true});
61         };
62
63         $scope.cancel = function()  {
64             $window.history.back();
65         };
66
67         $scope.next = function()  {
68             // DataService.setLcpRegion($scope.nodeTemplateFields.lcpRegion.value);
69             // DataService.setModelInstanceName($scope.nodeTemplateFields.instanceName.value);
70             // DataService.setTenant($scope.nodeTemplateFields.tenant.value);
71             // var suppressRollback = ($scope.nodeTemplateFields.suppressRollback.value) ? true : false;
72             // DataService.setSuppressRollback(suppressRollback);
73             DataService.setPortMirroningConfigFields($scope.nodeTemplateFields);
74             $location.path("/serviceProxyConfig");
75         };
76
77         $scope.$on('$routeChangeStart', function (event, next, current) {
78             if(next.$$route.originalPath !=="/serviceProxyConfig"){
79                 DataService.setPortMirroningConfigFields(null);
80             }
81         });
82     }]);