Merge from ECOMP's repository
[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 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, $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.lcpAndTenant = null;
32     $scope.regionSelection = {lcpRegion: null, legacyRegion: null, tenant: null};
33     $scope.lcpRegionList = null;
34     $scope.isHomingData = false;
35     $scope.megaRegion = ['AAIAIC25', 'rdm3', 'rdm5a'];
36     $scope.isSoftDeleteEnabled = vfModule.nodeStatus.toLowerCase() !== 'assigned' && action === COMPONENT.DELETE;
37
38     $scope.isResumeEnabled = action === COMPONENT.RESUME;
39     if ($scope.isResumeEnabled) {
40         $scope.action = 'Instantiate';
41     }
42
43     initHomingData();
44
45     function getLcpCloudRegionTenantList() {
46         AaiService.getLcpCloudRegionTenantList(DataService
47             .getGlobalCustomerId(), DataService.getServiceType(), function(
48             response) {
49             $scope.lcpAndTenant = response;
50             $scope.isFeatureFlagCloudOwner = featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST);
51             $scope.lcpRegionList = _.uniqBy(response, 'cloudRegionId');
52         });
53     }
54
55     function initHomingData() {
56         AaiService.getHomingData(DataService.getVnfInstanceId(), DataService.getVfModuleInstanceId())
57             .then(function (res) {
58                 if (res && res.data) {
59                     $scope.regionSelection = {
60                         lcpRegion: (res.data[COMPONENT.CLOUD_REGION_ID]) ? res.data[COMPONENT.CLOUD_REGION_ID] : null,
61                         legacyRegion: null,
62                         tenant: (res.data[COMPONENT.TENANT_ID]) ? res.data[COMPONENT.TENANT_ID] : null
63                     };
64                     $scope.isHomingData = $scope.regionSelection.lcpRegion !== null && res.data.tenant !== null;
65                     $scope.isHomingData = $scope.isHomingData && (($scope.megaRegion).indexOf($scope.regionSelection.lcpRegion) === -1);
66                 }
67
68                 if (!$scope.isHomingData) {
69                     getLcpCloudRegionTenantList();
70                 }
71             })
72             .catch(function (error) {
73                 getLcpCloudRegionTenantList();
74             });
75     };
76
77     function getLcpRegionId()  {
78         if(_.isEmpty($scope.regionSelection.legacyRegion)) {
79             return $scope.regionSelection.lcpRegion
80         }
81         return $scope.regionSelection.legacyRegion;
82     }
83
84     $scope.deleteOrResume = function()  {
85
86         var regionSelectionList = [({id: "lcpRegion", value: getLcpRegionId()})];
87         regionSelectionList.push({id: "tenant", value: $scope.regionSelection.tenant});
88
89         var requestParams = {};
90         var requestDetails;
91         var msoType;
92         if ($scope.isResumeEnabled)  {
93             CreationService.initializeComponent(COMPONENT.VF_MODULE);
94             CreationService.setInventoryInfo();
95
96             requestDetails = CreationService.getMsoRequestDetails(regionSelectionList);
97             requestParams.url = CreationService.getMsoUrl();
98             msoType = COMPONENT.MSO_CREATE_REQ;
99         }
100         else {
101             DeleteResumeService.initializeComponent(COMPONENT.VF_MODULE);
102
103             requestDetails = DeleteResumeService.getMsoRequestDetails(regionSelectionList);
104             if(DeleteResumeService.isMacro === true)  {
105                 requestDetails.requestParameters.aLaCarte = false;
106             }
107             requestParams.url = DeleteResumeService.getMsoUrl();
108             msoType = COMPONENT.MSO_DELETE_REQ;
109         }
110
111         requestParams.requestDetails = requestDetails;
112         requestParams.userId = DataService.getLoggedInUserId();
113         $uibModalInstance.close({requestParams: requestParams, msoType: msoType});
114     };
115
116     $scope.softDelete = function()  {
117
118         var requestParams = {
119             tenantId: $scope.regionSelection.tenant,
120             lcpCloudRegionId: getLcpRegionId(),
121             serviceInstanceId: DataService.getServiceInstanceId(),
122             vnfInstanceId: DataService.getVnfInstanceId(),
123             vfModuleInstanceId: DataService.getVfModuleInstanceId()
124         };
125
126         requestParams.userId = DataService.getLoggedInUserId();
127         $uibModalInstance.close({requestParams : requestParams, msoType: COMPONENT.MSO_DEACTIVATE_AND_CLOUD_DELETE});
128     };
129
130     $scope.cancel = function() {
131         $uibModalInstance.dismiss('cancel');
132     };
133
134 };
135
136 appDS2.controller("vfModuleActionModalController", [ "COMPONENT", "$scope", "$uibModal", "CreationService",
137      "MsoService", "AaiService", "DeleteResumeService", "DataService", "$uibModalInstance", "action", "vfModule", "featureFlags",
138     vfModuleActionModalController ]);