[UI] Common class for results
[validation.git] / ui / src / main / webapp / app / BluvalUI / GetByTimestamp / GetByTimestampController.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('GetByTimestamp');
18 app.controller('GetByTimestampController',
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.selectedBlueprint = {};
43         $scope.selectedVersion = {};
44         restAPISvc.getRestAPI("/api/v1/results/getblueprintnamesoflab/"
45                 + $scope.selectedLab, function(data) {
46             $scope.blueprints = data;
47             $scope.loadingBlueprints = false;
48         });
49     }
50
51     $scope.selectedBlueprintChange = function() {
52         if (!$scope.selectedLab) {
53             return;
54         }
55         $scope.loadingLabs = false;
56         $scope.loadingBlueprints = false;
57         $scope.loadingVersions = true;
58         $scope.versions = [];
59         $scope.selectedVersion = {};
60         restAPISvc.getRestAPI("/api/v1/results/getblueprintversions/"
61                 + $scope.selectedBlueprint + "/" + $scope.selectedLab,
62                 function(data) {
63                     $scope.versions = data;
64                     $scope.loadingVersions = false;
65                 });
66     }
67
68     $scope.selectedVersionChange = function() {
69         $scope.loadingLabs = false;
70         $scope.loadingBlueprints = false;
71         $scope.loadingVersions = false;
72         $scope.loadingResults = false;
73     }
74
75     $scope.get = function() {
76         if (!$scope.selectedLab || !$scope.selectedBlueprint
77                 || !$scope.selectedVersion || !$scope.definedTimestamp) {
78             confirm("You must specify all data fields");
79             return;
80         }
81
82         $window.location.href = appContext
83                 + "/validationresults#?blueprintName="
84                 + $scope.selectedBlueprint + "&" + "version="
85                 + $scope.selectedVersion + "&" + "lab=" + $scope.selectedLab
86                 + "&" + "timestamp=" + $scope.definedTimestamp;
87     }
88
89 });