[UI] Support UI partial control
[validation.git] / ui / src / main / webapp / app / BluvalUI / GetLastRun / GetLastRunController.js
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 var app = angular.module('GetLastRun');
18 app.controller('GetLastRunController',
19
20 function($scope, restAPISvc, $window, appContext) {
21     initialize();
22
23     function initialize() {
24         $scope.loadingLabs = true;
25         $scope.loadingBlueprints = false;
26         $scope.loadingVersions = false;
27         restAPISvc.getRestAPI("/api/v1/results/getlabs/", function(data) {
28             $scope.labs = data;
29             $scope.loadingLabs = false;
30         });
31     }
32
33     $scope.selectedLabChange = function() {
34         $scope.loadingLabs = false;
35         $scope.loadingBlueprints = true;
36         $scope.loadingVersions = false;
37         $scope.blueprints = [];
38         $scope.versions = [];
39         $scope.layers = [];
40         $scope.optionals = [];
41         $scope.outcomes = [];
42         $scope.selectedBlueprint = {};
43         $scope.selectedVersion = {};
44         $scope.selectedLayer = {};
45         $scope.selectedOptional = {};
46         $scope.selectedOutcome = {};
47         restAPISvc.getRestAPI("/api/v1/results/getblueprintnamesoflab/"
48                 + $scope.selectedLab, function(data) {
49             $scope.blueprints = data;
50             $scope.loadingBlueprints = false;
51         });
52     }
53
54     $scope.selectedBlueprintChange = function() {
55         if (!$scope.selectedLab) {
56             return;
57         }
58         $scope.loadingLabs = false;
59         $scope.loadingBlueprints = false;
60         $scope.loadingVersions = true;
61         $scope.versions = [];
62         $scope.layers = [];
63         $scope.optionals = [];
64         $scope.outcomes = [];
65         $scope.selectedVersion = {};
66         $scope.selectedLayer = {};
67         $scope.selectedOptional = {};
68         $scope.selectedOutcome = {};
69         restAPISvc.getRestAPI("/api/v1/results/getblueprintversions/"
70                 + $scope.selectedBlueprint + "/" + $scope.selectedLab,
71                 function(data) {
72                     $scope.versions = data;
73                     $scope.loadingVersions = false;
74                 });
75     }
76
77     $scope.selectedVersionChange = function() {
78         $scope.layers = [];
79         $scope.optionals = [];
80         $scope.outcomes = [];
81         $scope.selectedLayer = {};
82         $scope.selectedOptional = {};
83         $scope.selectedOutcome = {};
84         $scope.loadingLabs = false;
85         $scope.loadingBlueprints = false;
86         $scope.loadingVersions = false;
87         $scope.loadingResults = false;
88         $scope.layers = [ 'all', 'hardware', 'os', 'k8s', 'openstack' ];
89     }
90
91     $scope.selectedLayerChange = function() {
92         $scope.optionals = [];
93         $scope.outcomes = [];
94         $scope.selectedOptional = {};
95         $scope.selectedOutcome = {};
96         $scope.loadingLabs = false;
97         $scope.loadingBlueprints = false;
98         $scope.loadingVersions = false;
99         $scope.loadingResults = false;
100         $scope.optionals = [ 'true', 'false' ];
101     }
102
103     $scope.selectedOptionalChange = function() {
104         $scope.outcomes = [];
105         $scope.selectedOutcome = {};
106         $scope.loadingLabs = false;
107         $scope.loadingBlueprints = false;
108         $scope.loadingVersions = false;
109         $scope.loadingResults = false;
110         $scope.outcomes = [ 'SUCCESS', 'FAILURE' ];
111     }
112
113     $scope.selectedOutcomeChange = function() {
114         $scope.loadingLabs = false;
115         $scope.loadingBlueprints = false;
116         $scope.loadingVersions = false;
117         $scope.loadingResults = false;
118     }
119
120     $scope.get = function() {
121         if (!$scope.selectedLab || !$scope.selectedBlueprint
122                 || !$scope.selectedVersion || !$scope.selectedLayer
123                 || !$scope.selectedOptional || !$scope.selectedOutcome) {
124             confirm("You must specify all data fields");
125             return;
126         }
127         var outcome = "";
128         if ($scope.selectedOutcome === 'SUCCESS') {
129             outcome = true;
130         } else {
131             outcome = false;
132         }
133         var allLayers = "";
134         var layer = "";
135         if ($scope.selectedLayer === 'all') {
136             allLayers = "true";
137         } else {
138             layer = $scope.selectedLayer;
139         }
140         $window.location.href = appContext
141                 + "/validationresults#?blueprintName="
142                 + $scope.selectedBlueprint + "&" + "version="
143                 + $scope.selectedVersion + "&" + "lab=" + $scope.selectedLab
144                 + "&" + "allLayers=" + allLayers + "&" + "layer=" + layer + "&"
145                 + "optional=" + $scope.selectedOptional + "&" + "outcome="
146                 + outcome;
147     }
148
149 });