b6725b1241fd1d68de758c3a26c7123ae64d880f
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / vf-module-homing-data-action / vf-module-homing-data-action.controller.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 "use strict";
22
23 var vfModuleActionModalController = function(COMPONENT, FIELD, $scope, $uibModal, CreationService,
24     MsoService, AaiService, DeleteResumeService, DataService, $uibModalInstance, action, vfModule, featureFlags) {
25
26
27     var _this = this;
28
29     $scope.action = action;
30     $scope.vfModuleName = vfModule.name;
31     $scope.volumeGroups = vfModule.volumeGroups;
32     $scope.lcpAndTenant = null;
33     $scope.regionSelection = {optionId: null, legacyRegion: null, tenant: null};
34     $scope.lcpRegionList = null;
35     $scope.isHomingData = false;
36     $scope.megaRegion = ['AAIAIC25'];
37     $scope.isSoftDeleteEnabled = vfModule.nodeStatus.toLowerCase() !== 'assigned' && action === COMPONENT.DELETE;
38
39     $scope.isResumeEnabled = action === COMPONENT.RESUME;
40     if ($scope.isResumeEnabled) {
41         $scope.action = 'Instantiate';
42     }
43
44     initHomingData();
45
46     function getLcpCloudRegionTenantList() {
47         AaiService.getLcpCloudRegionTenantList(DataService
48             .getGlobalCustomerId(), DataService.getServiceType(), function(
49             response) {
50             DataService.setCloudRegionTenantList(response);
51             $scope.lcpAndTenant = response;
52             $scope.isFeatureFlagCloudOwner = featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST);
53             $scope.lcpRegionList = _.uniqBy(response, 'cloudRegionOptionId');
54             $scope.vendorInCloudOwnerRegex = /^[^-]*-/;
55         });
56     }
57
58     function initHomingData() {
59         AaiService.getHomingData(DataService.getVnfInstanceId(), DataService.getVfModuleInstanceId())
60             .then(function (res) {
61                 if (res && res.data) {
62                     $scope.regionSelection = {
63                         optionId: (res.data[COMPONENT.CLOUD_REGION_ID]) ? res.data[COMPONENT.CLOUD_REGION_ID] : null,
64                         legacyRegion: null,
65                         tenant: (res.data[COMPONENT.TENANT_ID]) ? res.data[COMPONENT.TENANT_ID] : null
66                     };
67                     $scope.isHomingData = $scope.regionSelection.optionId !== null && res.data.tenant !== null;
68                     $scope.isHomingData = $scope.isHomingData && !$scope.selectedLcpRegionIsMegaRegion();
69                 }
70
71                 if (!$scope.isHomingData) {
72                     getLcpCloudRegionTenantList();
73                 }
74             })
75             .catch(function (error) {
76                 getLcpCloudRegionTenantList();
77             });
78     }
79
80     function getLcpRegionId()  {
81         if(_.isEmpty($scope.regionSelection.legacyRegion)) {
82             return DataService.getCloudOwnerAndLcpCloudRegionFromOptionId($scope.regionSelection.optionId).cloudRegionId;
83         }
84         return $scope.regionSelection.legacyRegion;
85     }
86
87     $scope.deleteOrResume = function()  {
88
89         var msoParameterList = [({id: "lcpRegion", value: getLcpRegionId()})];
90         msoParameterList.push({id: "tenant", value: $scope.regionSelection.tenant});
91
92         var requestParams = {};
93         var requestDetails;
94         var msoType;
95         if ($scope.isResumeEnabled)  {
96             CreationService.initializeComponent(COMPONENT.VF_MODULE);
97             CreationService.setInventoryInfo();
98
99             var availableVolumeGroupList = $scope.volumeGroups;
100
101             if (availableVolumeGroupList && availableVolumeGroupList.length > 0) {
102                 var volumeGroupList = FIELD.PARAMETER.AVAILABLE_VOLUME_GROUP;
103                 volumeGroupList.value = _.map(availableVolumeGroupList, function (volumeGroup) {
104                     return volumeGroup.name;
105                 });
106                 msoParameterList.push(volumeGroupList);
107             }
108
109             requestDetails = CreationService.getMsoRequestDetails(msoParameterList);
110             requestParams.url = CreationService.getMsoUrl();
111             msoType = COMPONENT.MSO_CREATE_REQ;
112         }
113         else {
114             DeleteResumeService.initializeComponent(COMPONENT.VF_MODULE);
115
116             requestDetails = DeleteResumeService.getMsoRequestDetails(msoParameterList);
117             if(DeleteResumeService.isMacro === true)  {
118                 requestDetails.requestParameters.aLaCarte = false;
119             }
120             requestParams.url = DeleteResumeService.getMsoUrl();
121             msoType = COMPONENT.MSO_DELETE_REQ;
122         }
123
124         requestParams.requestDetails = requestDetails;
125         requestParams.userId = DataService.getLoggedInUserId();
126         $uibModalInstance.close({requestParams: requestParams, msoType: msoType});
127     };
128
129     $scope.softDelete = function()  {
130
131         var requestParams = {
132             tenantId: $scope.regionSelection.tenant,
133             lcpCloudRegionId: getLcpRegionId(),
134             serviceInstanceId: DataService.getServiceInstanceId(),
135             vnfInstanceId: DataService.getVnfInstanceId(),
136             vfModuleInstanceId: DataService.getVfModuleInstanceId()
137         };
138
139         requestParams.userId = DataService.getLoggedInUserId();
140         $uibModalInstance.close({requestParams : requestParams, msoType: COMPONENT.MSO_DEACTIVATE_AND_CLOUD_DELETE});
141     };
142
143     $scope.removeVendorFromCloudOwner = function(cloudOwner) {
144         return AaiService.removeVendorFromCloudOwner(cloudOwner)
145     };
146
147     $scope.selectedLcpRegionIsMegaRegion = function() {
148         let cloudRegionId =
149             DataService.getCloudOwnerAndLcpCloudRegionFromOptionId($scope.regionSelection.optionId).cloudRegionId;
150         return ($scope.megaRegion).indexOf(cloudRegionId) > -1
151     };
152
153     $scope.cancel = function() {
154         $uibModalInstance.dismiss('cancel');
155     };
156
157 };
158
159 appDS2.controller("vfModuleActionModalController", [ "COMPONENT", "FIELD", "$scope", "$uibModal", "CreationService",
160      "MsoService", "AaiService", "DeleteResumeService", "DataService", "$uibModalInstance", "action", "vfModule", "featureFlags",
161     vfModuleActionModalController ]);