Update license headers
[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", newTestEnvironmentsModalController]);
26
27     function newTestEnvironmentsModalController($uibModalInstance, $uibModal, AaiService, TestEnvironmentsService,OwningEntityService, $log, $scope, _, COMPONENT, $rootScope) {
28         var vm = this;
29         vm.newEnvironment = {};
30
31         var init = function () {
32             vm.newEnvironment.operationalEnvironmentType = "VNF";
33             loadCategoryParameters();
34             loadEcompEnvironmentsList();
35         };
36
37         var loadEcompEnvironmentsList = function () {
38             TestEnvironmentsService.loadAAIestEnvironments("ECOMP")
39             .then(function(response) {
40                 vm.environments = response.operationalEnvironment;
41             })
42             .catch(function (error) {
43                 vm.aaiConnectError = error.message;
44                 $log.error(error);
45             });
46         };
47
48         var loadCategoryParameters = function () {
49             OwningEntityService.getOwningEntityProperties(function(response){
50                vm.environmentsTypesList = response["operational-environment-type"].map(function (x){
51                     return x.name;});
52                vm.workloadContextList = response["workload-context"].map(function (x){
53                    return x.name;});
54             },COMPONENT.TENANT_ISOLATION_FAMILY);
55         }
56
57
58         vm.setEcompEnvironment = function (selectedIndex) {
59             var ecompEnvironment = vm.environments[selectedIndex];
60             vm.newEnvironment.ecompInstanceId = ecompEnvironment.operationalEnvironmentId;
61             vm.newEnvironment.ecompInstanceName = ecompEnvironment.operationalEnvironmentName;
62             vm.newEnvironment.tenantContext = ecompEnvironment.tenantContext;
63         };
64
65         vm.close = function () {
66             $uibModalInstance.close();
67         };
68
69         vm.createEnvironment = function () {
70             if($scope.newTestEnvironment.$valid) {
71                 vm.newEnvironment.workloadContext = vm.newEnvironment.operationalEnvironmentType + '_' + vm.newEnvironment.workloadContext;
72                 var requestDetails = vm.newEnvironment;
73                 $rootScope.$broadcast(COMPONENT.MSO_CREATE_ENVIRONMENT, {
74                     url : COMPONENT.OPERATIONAL_ENVIRONMENT_CREATE,
75                     requestDetails : requestDetails
76                 });
77                 vm.close();
78             }
79         };
80
81
82
83         init();
84     }
85 })();