[UI] Common class for results
[validation.git] / ui / src / main / webapp / app / BluvalUI / GetMostRecent / GetMostRecentController.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('GetMostRecent');
18 app.controller('GetMostRecentController', function($scope, restAPISvc, $window,
19         appContext) {
20
21     initialize();
22
23     function initialize() {
24
25         $scope.loadingLabs = true;
26         $scope.loadingBlueprints = false;
27         $scope.loadingVersions = false;
28         $scope.loadingResults = false;
29         $scope.labs = [];
30         restAPISvc.getRestAPI("/api/v1/lab/", function(data) {
31             angular.forEach(data, function(lab) {
32                 $scope.labs.push(lab.lab);
33             });
34             $scope.loadingLabs = false;
35         });
36     }
37
38     $scope.selectedLabChange = function() {
39         $scope.loadingLabs = false;
40         $scope.loadingBlueprints = true;
41         $scope.loadingVersions = false;
42         $scope.blueprints = [];
43         $scope.versions = [];
44         $scope.selectedBlueprint = {};
45         $scope.selectedVersion = {};
46         restAPISvc.getRestAPI("/api/v1/results/getblueprintnamesoflab/"
47                 + $scope.selectedLab, function(data) {
48             $scope.blueprints = data;
49             $scope.loadingBlueprints = false;
50         });
51     }
52
53     $scope.selectedBlueprintChange = function() {
54         if (!$scope.selectedLab) {
55             return;
56         }
57         $scope.loadingLabs = false;
58         $scope.loadingBlueprints = false;
59         $scope.loadingVersions = true;
60         $scope.versions = [];
61         $scope.selectedVersion = {};
62         restAPISvc.getRestAPI("/api/v1/results/getblueprintversions/"
63                 + $scope.selectedBlueprint + "/" + $scope.selectedLab,
64                 function(data) {
65                     $scope.versions = data;
66                     $scope.loadingVersions = false;
67                 });
68     }
69
70     $scope.selectedVersionChange = function() {
71     }
72
73     $scope.get = function() {
74         if (!$scope.selectedLab || !$scope.selectedBlueprint
75                 || !$scope.selectedVersion) {
76             confirm("You must specify all data fields");
77             return;
78         }
79         $window.location.href = appContext + "/validationresults#?lab="
80                 + $scope.selectedLab + "&" + "blueprintName="
81                 + $scope.selectedBlueprint + "&" + "version="
82                 + $scope.selectedVersion;
83     }
84
85 });