[UI] Ignore malformed results
[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         $scope.labs = [];
28         restAPISvc.getRestAPI("/api/v1/lab/", function(data) {
29             angular.forEach(data, function(lab) {
30                 $scope.labs.push(lab.lab);
31             });
32             $scope.loadingLabs = false;
33         });
34     }
35
36     $scope.selectedLabChange = function() {
37         $scope.loadingLabs = false;
38         $scope.loadingBlueprints = true;
39         $scope.loadingVersions = false;
40         $scope.blueprints = [];
41         $scope.versions = [];
42         $scope.layers = [];
43         $scope.optionals = [];
44         $scope.outcomes = [];
45         $scope.selectedBlueprint = {};
46         $scope.selectedVersion = {};
47         $scope.selectedLayer = {};
48         $scope.selectedOptional = {};
49         $scope.selectedOutcome = {};
50         restAPISvc.getRestAPI("/api/v1/results/getblueprintnamesoflab/"
51                 + $scope.selectedLab, function(data) {
52             $scope.blueprints = data;
53             $scope.loadingBlueprints = false;
54         });
55     }
56
57     $scope.selectedBlueprintChange = function() {
58         if (!$scope.selectedLab) {
59             return;
60         }
61         $scope.loadingLabs = false;
62         $scope.loadingBlueprints = false;
63         $scope.loadingVersions = true;
64         $scope.versions = [];
65         $scope.layers = [];
66         $scope.optionals = [];
67         $scope.outcomes = [];
68         $scope.selectedVersion = {};
69         $scope.selectedLayer = {};
70         $scope.selectedOptional = {};
71         $scope.selectedOutcome = {};
72         restAPISvc.getRestAPI("/api/v1/results/getblueprintversions/"
73                 + $scope.selectedBlueprint + "/" + $scope.selectedLab,
74                 function(data) {
75                     $scope.versions = data;
76                     $scope.loadingVersions = false;
77                 });
78     }
79
80     $scope.selectedVersionChange = function() {
81         $scope.layers = [];
82         $scope.optionals = [];
83         $scope.outcomes = [];
84         $scope.selectedLayer = {};
85         $scope.selectedOptional = {};
86         $scope.selectedOutcome = {};
87         $scope.loadingLabs = false;
88         $scope.loadingBlueprints = false;
89         $scope.loadingVersions = false;
90         $scope.loadingResults = false;
91         $scope.layers = [ 'all', 'hardware', 'os', 'k8s', 'openstack' ];
92     }
93
94     $scope.selectedLayerChange = function() {
95         $scope.optionals = [];
96         $scope.outcomes = [];
97         $scope.selectedOptional = {};
98         $scope.selectedOutcome = {};
99         $scope.loadingLabs = false;
100         $scope.loadingBlueprints = false;
101         $scope.loadingVersions = false;
102         $scope.loadingResults = false;
103         $scope.optionals = [ 'true', 'false' ];
104     }
105
106     $scope.selectedOptionalChange = function() {
107         $scope.outcomes = [];
108         $scope.selectedOutcome = {};
109         $scope.loadingLabs = false;
110         $scope.loadingBlueprints = false;
111         $scope.loadingVersions = false;
112         $scope.loadingResults = false;
113         $scope.outcomes = [ 'SUCCESS', 'FAILURE' ];
114     }
115
116     $scope.selectedOutcomeChange = function() {
117         $scope.loadingLabs = false;
118         $scope.loadingBlueprints = false;
119         $scope.loadingVersions = false;
120         $scope.loadingResults = false;
121     }
122
123     $scope.get = function() {
124         if (!$scope.selectedLab || !$scope.selectedBlueprint
125                 || !$scope.selectedVersion || !$scope.selectedLayer
126                 || !$scope.selectedOptional || !$scope.selectedOutcome) {
127             confirm("You must specify all data fields");
128             return;
129         }
130         var outcome = "";
131         if ($scope.selectedOutcome === 'SUCCESS') {
132             outcome = true;
133         } else {
134             outcome = false;
135         }
136         var allLayers = "";
137         var layer = "";
138         if ($scope.selectedLayer === 'all') {
139             allLayers = "true";
140         } else {
141             layer = $scope.selectedLayer;
142         }
143         $window.location.href = appContext
144                 + "/validationresults#?blueprintName="
145                 + $scope.selectedBlueprint + "&" + "version="
146                 + $scope.selectedVersion + "&" + "lab=" + $scope.selectedLab
147                 + "&" + "allLayers=" + allLayers + "&" + "layer=" + layer + "&"
148                 + "optional=" + $scope.selectedOptional + "&" + "outcome="
149                 + outcome;
150     }
151
152 });