Merge "Merge from ecomp 3374149f - AngularJS UI"
[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 = {lcpRegion: 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             $scope.lcpAndTenant = response;
51             $scope.isFeatureFlagCloudOwner = featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST);
52             $scope.lcpRegionList = _.uniqBy(response, 'cloudRegionId');
53             $scope.vendorInCloudOwnerRegex = /^[^-]*-/;
54         });
55     }
56
57     function initHomingData() {
58         AaiService.getHomingData(DataService.getVnfInstanceId(), DataService.getVfModuleInstanceId())
59             .then(function (res) {
60                 if (res && res.data) {
61                     $scope.regionSelection = {
62                         lcpRegion: (res.data[COMPONENT.CLOUD_REGION_ID]) ? res.data[COMPONENT.CLOUD_REGION_ID] : null,
63                         legacyRegion: null,
64                         tenant: (res.data[COMPONENT.TENANT_ID]) ? res.data[COMPONENT.TENANT_ID] : null
65                     };
66                     $scope.isHomingData = $scope.regionSelection.lcpRegion !== null && res.data.tenant !== null;
67                     $scope.isHomingData = $scope.isHomingData && (($scope.megaRegion).indexOf($scope.regionSelection.lcpRegion) === -1);
68                 }
69
70                 if (!$scope.isHomingData) {
71                     getLcpCloudRegionTenantList();
72                 }
73             })
74             .catch(function (error) {
75                 getLcpCloudRegionTenantList();
76             });
77     };
78
79     function getLcpRegionId()  {
80         if(_.isEmpty($scope.regionSelection.legacyRegion)) {
81             return $scope.regionSelection.lcpRegion
82         }
83         return $scope.regionSelection.legacyRegion;
84     }
85
86     $scope.deleteOrResume = function()  {
87
88         var msoParameterList = [({id: "lcpRegion", value: getLcpRegionId()})];
89         msoParameterList.push({id: "tenant", value: $scope.regionSelection.tenant});
90
91         var requestParams = {};
92         var requestDetails;
93         var msoType;
94         if ($scope.isResumeEnabled)  {
95             CreationService.initializeComponent(COMPONENT.VF_MODULE);
96             CreationService.setInventoryInfo();
97
98             var availableVolumeGroupList = $scope.volumeGroups;
99
100             if (availableVolumeGroupList && availableVolumeGroupList.length > 0) {
101                 var volumeGroupList = FIELD.PARAMETER.AVAILABLE_VOLUME_GROUP;
102                 volumeGroupList.value = _.map(availableVolumeGroupList, function (volumeGroup) {
103                     return volumeGroup.name;
104                 });
105                 msoParameterList.push(volumeGroupList);
106             }
107
108             requestDetails = CreationService.getMsoRequestDetails(msoParameterList);
109             requestParams.url = CreationService.getMsoUrl();
110             msoType = COMPONENT.MSO_CREATE_REQ;
111         }
112         else {
113             DeleteResumeService.initializeComponent(COMPONENT.VF_MODULE);
114
115             requestDetails = DeleteResumeService.getMsoRequestDetails(msoParameterList);
116             if(DeleteResumeService.isMacro === true)  {
117                 requestDetails.requestParameters.aLaCarte = false;
118             }
119             requestParams.url = DeleteResumeService.getMsoUrl();
120             msoType = COMPONENT.MSO_DELETE_REQ;
121         }
122
123         requestParams.requestDetails = requestDetails;
124         requestParams.userId = DataService.getLoggedInUserId();
125         $uibModalInstance.close({requestParams: requestParams, msoType: msoType});
126     };
127
128     $scope.softDelete = function()  {
129
130         var requestParams = {
131             tenantId: $scope.regionSelection.tenant,
132             lcpCloudRegionId: getLcpRegionId(),
133             serviceInstanceId: DataService.getServiceInstanceId(),
134             vnfInstanceId: DataService.getVnfInstanceId(),
135             vfModuleInstanceId: DataService.getVfModuleInstanceId()
136         };
137
138         requestParams.userId = DataService.getLoggedInUserId();
139         $uibModalInstance.close({requestParams : requestParams, msoType: COMPONENT.MSO_DEACTIVATE_AND_CLOUD_DELETE});
140     };
141
142     $scope.removeVendorFromCloudOwner = function(cloudOwner) {
143         return AaiService.removeVendorFromCloudOwner(cloudOwner)
144     };
145
146     $scope.cancel = function() {
147         $uibModalInstance.dismiss('cancel');
148     };
149
150 };
151
152 appDS2.controller("vfModuleActionModalController", [ "COMPONENT", "FIELD", "$scope", "$uibModal", "CreationService",
153      "MsoService", "AaiService", "DeleteResumeService", "DataService", "$uibModalInstance", "action", "vfModule", "featureFlags",
154     vfModuleActionModalController ]);