[UI] Support UI partial control
[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         restAPISvc.getRestAPI("/api/v1/results/getlabs/", function(data) {
30             $scope.labs = data;
31             $scope.loadingLabs = false;
32         });
33     }
34
35     $scope.selectedLabChange = function() {
36         $scope.loadingLabs = false;
37         $scope.loadingBlueprints = true;
38         $scope.loadingVersions = false;
39         $scope.blueprints = [];
40         $scope.versions = [];
41         $scope.selectedBlueprint = {};
42         $scope.selectedVersion = {};
43         restAPISvc.getRestAPI("/api/v1/results/getblueprintnamesoflab/"
44                 + $scope.selectedLab, function(data) {
45             $scope.blueprints = data;
46             $scope.loadingBlueprints = false;
47         });
48     }
49
50     $scope.selectedBlueprintChange = function() {
51         if (!$scope.selectedLab) {
52             return;
53         }
54         $scope.loadingLabs = false;
55         $scope.loadingBlueprints = false;
56         $scope.loadingVersions = true;
57         $scope.versions = [];
58         $scope.selectedVersion = {};
59         restAPISvc.getRestAPI("/api/v1/results/getblueprintversions/"
60                 + $scope.selectedBlueprint + "/" + $scope.selectedLab,
61                 function(data) {
62                     $scope.versions = data;
63                     $scope.loadingVersions = false;
64                 });
65     }
66
67     $scope.selectedVersionChange = function() {
68     }
69
70     $scope.get = function() {
71         if (!$scope.selectedLab || !$scope.selectedBlueprint
72                 || !$scope.selectedVersion) {
73             confirm("You must specify all data fields");
74             return;
75         }
76         $window.location.href = appContext + "/validationresults#?lab="
77                 + $scope.selectedLab + "&" + "blueprintName="
78                 + $scope.selectedBlueprint + "&" + "version="
79                 + $scope.selectedVersion;
80     }
81
82 });