org.onap migration
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-test-environment / new-test-environment.controller.js
1 (function () {
2     'use strict';
3
4     appDS2.controller("newTestEnvironmentModalController", ["$uibModalInstance", "$uibModal", "AaiService", "TestEnvironmentsService","OwningEntityService",
5         "$log", "$scope", "_", "COMPONENT","$rootScope", newTestEnvironmentsModalController]);
6
7     function newTestEnvironmentsModalController($uibModalInstance, $uibModal, AaiService, TestEnvironmentsService,OwningEntityService, $log, $scope, _, COMPONENT, $rootScope) {
8         var vm = this;
9         vm.newEnvironment = {};
10
11         var init = function () {
12             vm.newEnvironment.operationalEnvironmentType = "VNF";
13             loadCategoryParameters();
14             loadEcompEnvironmentsList();
15         };
16
17         var loadEcompEnvironmentsList = function () {
18             TestEnvironmentsService.loadAAIestEnvironments("ECOMP")
19             .then(function(response) {
20                 vm.environments = response.operationalEnvironment;
21             })
22             .catch(function (error) {
23                 vm.aaiConnectError = error.message;
24                 $log.error(error);
25             });
26         };
27
28         var loadCategoryParameters = function () {
29             OwningEntityService.getOwningEntityProperties(function(response){
30                vm.environmentsTypesList = response["operational-environment-type"].map(function (x){
31                     return x.name;});
32                vm.workloadContextList = response["workload-context"].map(function (x){
33                    return x.name;});
34             },COMPONENT.TENANT_ISOLATION_FAMILY);
35         }
36
37
38         vm.setEcompEnvironment = function (selectedIndex) {
39             var ecompEnvironment = vm.environments[selectedIndex];
40             vm.newEnvironment.ecompInstanceId = ecompEnvironment.operationalEnvironmentId;
41             vm.newEnvironment.ecompInstanceName = ecompEnvironment.operationalEnvironmentName;
42             vm.newEnvironment.tenantContext = ecompEnvironment.tenantContext;
43         };
44
45         vm.close = function () {
46             $uibModalInstance.close();
47         };
48
49         vm.createEnvironment = function () {
50             if($scope.newTestEnvironment.$valid) {
51                 vm.newEnvironment.workloadContext = vm.newEnvironment.operationalEnvironmentType + '_' + vm.newEnvironment.workloadContext;
52                 var requestDetails = vm.newEnvironment;
53                 $rootScope.$broadcast(COMPONENT.MSO_CREATE_ENVIRONMENT, {
54                     url : COMPONENT.OPERATIONAL_ENVIRONMENT_CREATE,
55                     requestDetails : requestDetails
56                 });
57                 vm.close();
58             }
59         };
60
61
62
63         init();
64     }
65 })();