aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/webapp/app/vid/scripts/controller/testEnvironmentsController.js
blob: 63ddac2fb68ba4abd4b7dd3737823ce5db37c6ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
(function () {
    'use strict';

    appDS2.controller("testEnvironmentsController", ["$uibModal", "TestEnvironmentsService", "$log", "$rootScope", "$scope", "COMPONENT", testEnvironmentsController]);

    function testEnvironmentsController($uibModal, TestEnvironmentsService, $log, $rootScope, $scope, COMPONENT) {
        var vm = this;

        var toggleValue;

        var init = function() {
            vm.loadAAIestEnvironments();
        };

        vm.loadAAIestEnvironments = function() {
            TestEnvironmentsService.loadAAIestEnvironments("VNF")
                .then(function(response) {
                    vm.environments = response.operationalEnvironment;
                    vm.connectError = false;
                    if(!vm.environments.length) {
                        vm.emptyData = true;
                    }
                })
                .catch(function (error) {
                    vm.connectError = error.message || "Unknown error";
                    $log.error(error);
                });
        };

        function handleEnvActionComplete(result) {
            if (result.isSuccessful) {
                vm.loadAAIestEnvironments();
            }
            $scope.popup.isVisible = false;
        }

        vm.onTestEnvActivateClick = function(testEnv) {
            var modalInstance = $uibModal.open({
                templateUrl: 'app/vid/scripts/modals/attach-test-env-manifest/attach-test-env-manifest.html',
                controller: 'attachTestEnvManifestController',
                controllerAs: 'vm',
                resolve: {}
            });

            modalInstance.result.then(function (result) {
                if (result) {

                    var relatedEcompEnv = _.find(testEnv.relationshipList.relationship, { relatedTo: "operational-environment" });

                    var manifest = result;
                    var envId = testEnv.operationalEnvironmentId;
                    var relatedInstanceId =
                        _.find(relatedEcompEnv.relationshipData, {"relationshipKey": "operational-environment.operational-environment-id"})
                            .relationshipValue;
                    var relatedInstanceName =
                        _.find(relatedEcompEnv.relatedToProperty, {"propertyKey": "operational-environment.operational-environment-name"})
                            .propertyValue;
                    var workloadContext = testEnv.workloadContext;

                    $rootScope.$broadcast(COMPONENT.MSO_ACTIVATE_ENVIRONMENT, {
                        url: COMPONENT.MSO_ACTIVATE_ENVIRONMENT,
                        envId: envId,
                        relatedInstanceId: relatedInstanceId,
                        relatedInstanceName: relatedInstanceName,
                        workloadContext: workloadContext,
                        manifest: manifest,
                        callbackFunction: handleEnvActionComplete
                    });

                }
            });
        };

        vm.onTestEnvDeactivateClick = function(testEnv) {
            var envId = testEnv.operationalEnvironmentId;
            $rootScope.$broadcast(COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, {
                url : COMPONENT.MSO_DEACTIVATE_ENVIRONMENT,
                envId : envId,
                callbackFunction: handleEnvActionComplete
            });
        };

        vm.isEnvActive = function(testEnv) {
            return testEnv.operationalEnvironmentStatus==='Activate';
        };

        vm.getEnvStatus = function (testEnv) {
            return this.isEnvActive(testEnv) ? "Active" : "Inactive";
        };

        vm.createNewTestEnvironment = function() {
            var modalInstance = $uibModal.open({
                templateUrl: 'app/vid/scripts/modals/new-test-environment/new-test-environment.html',
                controller: 'newTestEnvironmentModalController',
                controllerAs: 'vm',
                resolve: {}
            });
        };

        init();
    }
})();