53111950caed5e87d3789a9482c078459ba1807a
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-test-environment / new-test-environment.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 (function () {
22     'use strict';
23
24     appDS2.controller("newTestEnvironmentModalController", ["$uibModalInstance", "$uibModal", "AaiService", "TestEnvironmentsService","OwningEntityService",
25         "$log", "$scope", "_", "COMPONENT","$rootScope", "featureFlags", newTestEnvironmentsModalController]);
26
27     function newTestEnvironmentsModalController($uibModalInstance, $uibModal, AaiService, TestEnvironmentsService, OwningEntityService, $log, $scope, _, COMPONENT, $rootScope, featureFlags ) {
28         var vm = this;
29         vm.newEnvironment = {};
30         vm.releaseVersions = {};
31
32         var init = function () {
33             vm.newEnvironment.operationalEnvironmentType = "VNF";
34             loadCategoryParameters();
35             loadEcompEnvironmentsList();
36         };
37
38         var loadEcompEnvironmentsList = function () {
39             TestEnvironmentsService.loadAAIestEnvironments("ONAP")
40             .then(function(response) {
41                 vm.environments = response.operationalEnvironment;
42             })
43             .catch(function (error) {
44                 vm.aaiConnectError = error.message;
45                 $log.error(error);
46             });
47         };
48
49         var loadCategoryParameters = function () {
50             OwningEntityService.getOwningEntityProperties(function(response){
51                 vm.environmentsTypesList = response["operational-environment-type"].map(function (environmentType){
52                     return environmentType.name;});
53                 vm.workloadContextList = response["workload-context"].map(function (context){
54                     return context.name;});
55                 vm.releaseVersions = response["release"].map(function (releaseOptions){
56                     return releaseOptions.name;});
57             },COMPONENT.TENANT_ISOLATION_FAMILY);
58         }
59
60
61         vm.setEcompEnvironment = function (selectedIndex) {
62             var ecompEnvironment = vm.environments[selectedIndex];
63             vm.newEnvironment.ecompInstanceId = ecompEnvironment.operationalEnvironmentId;
64             vm.newEnvironment.ecompInstanceName = ecompEnvironment.operationalEnvironmentName;
65             vm.newEnvironment.tenantContext = ecompEnvironment.tenantContext;
66         };
67
68         vm.close = function () {
69             $uibModalInstance.close();
70         };
71
72         vm.createEnvironment = function () {
73             if($scope.newTestEnvironment.$valid) {
74                 var requestDetails = vm.newEnvironment;
75                 delete vm.newEnvironment['release'];
76                 $rootScope.$broadcast(COMPONENT.MSO_CREATE_ENVIRONMENT, {
77                     url : COMPONENT.OPERATIONAL_ENVIRONMENT_CREATE,
78                     requestDetails : requestDetails
79                 });
80                 vm.close();
81             }
82         };
83
84         vm.isShowReleaseEnabled = function () {
85             return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_1908_RELEASE_TENANT_ISOLATION)
86         };
87
88         init();
89     }
90 })();