[UI] Support UI partial control
[validation.git] / ui / src / main / webapp / app / BluvalUI / GetBasedOnDate / GetBasedOnDateController.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('GetBasedOnDate');
18 app.controller('GetBasedOnDateController', function($scope, restAPISvc,
19         $window, appContext, $filter) {
20
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.selectedBlueprint = {};
40         $scope.selectedVersion = {};
41         restAPISvc.getRestAPI("/api/v1/results/getblueprintnamesoflab/"
42                 + $scope.selectedLab, function(data) {
43             $scope.blueprints = data;
44             $scope.loadingBlueprints = false;
45         });
46     }
47
48     $scope.selectedBlueprintChange = function() {
49         if (!$scope.selectedLab) {
50             return;
51         }
52         $scope.loadingLabs = false;
53         $scope.loadingBlueprints = false;
54         $scope.loadingVersions = true;
55         $scope.versions = [];
56         $scope.selectedVersion = {};
57         restAPISvc.getRestAPI("/api/v1/results/getblueprintversions/"
58                 + $scope.selectedBlueprint + "/" + $scope.selectedLab,
59                 function(data) {
60                     $scope.versions = data;
61                     $scope.loadingVersions = false;
62                 });
63     }
64
65     $scope.selectedVersionChange = function() {
66     }
67
68     $scope.get = function() {
69         if (!$scope.selectedLab || !$scope.selectedBlueprint
70                 || !$scope.selectedVersion || !$scope.selectedDate) {
71             confirm("You must specify all data fields");
72             return;
73         }
74         var selectedDate = $filter('date')($scope.selectedDate, "MM-dd-yyyy");
75
76         $window.location.href = appContext
77                 + "/validationresults#?blueprintName="
78                 + $scope.selectedBlueprint + "&" + "version="
79                 + $scope.selectedVersion + "&" + "lab=" + $scope.selectedLab
80                 + "&" + "date=" + selectedDate;
81     }
82
83 });