[UI] Support UI partial control
[validation.git] / ui / src / main / webapp / app / BluvalUI / ValidationResults / ValidationResultsController.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('ValidationResults');
18 app
19         .controller(
20                 'ValidationResultsController',
21                 function($scope, restAPISvc, generalValidationResultsSvc,
22                         $window, appContext, $location, $modal, $rootScope) {
23
24                     $scope.getBlueprintLayers = generalValidationResultsSvc.getBlueprintLayers;
25                     $scope.mapResult = generalValidationResultsSvc.mapResult;
26                     $scope.filterWithLayer = generalValidationResultsSvc.filterWithLayer;
27                     $scope.filterWithResult = generalValidationResultsSvc.filterWithResult;
28                     $scope.getLab = generalValidationResultsSvc.getLab;
29
30                     initialize();
31
32                     function initialize() {
33                         $scope.loadingResults = true;
34                         $scope.validationNexusTestResults = [];
35                         $scope.silos = [];
36                         var searchObject = $location.search();
37                         var submissionId = searchObject.submissionId;
38                         var blueprintName = searchObject.blueprintName;
39                         var version = searchObject.version;
40                         var lab = searchObject.lab;
41                         var allLayers = searchObject.allLayers;
42                         var layer = searchObject.layer;
43                         var optional = searchObject.optional;
44                         var outcome = searchObject.outcome;
45                         var timestamp = searchObject.timestamp;
46                         var date = searchObject.date;
47                         var reqUrl = "";
48                         if (submissionId) {
49                             reqUrl = "/api/v1/results/getbysubmissionid/"
50                                     + submissionId;
51                         } else if (outcome !== undefined && !layer) {
52                             reqUrl = "/api/v1/results/getlastrun/" + lab + "/"
53                                     + blueprintName + "/" + version + "/"
54                                     + allLayers + "/" + optional + "/"
55                                     + outcome;
56                         } else if (outcome !== undefined) {
57                             var layers = [];
58                             layers.push(layer);
59                             reqUrl = "/api/v1/results/getlastrunoflayers/"
60                                     + lab + "/" + blueprintName + "/" + version
61                                     + "/" + layers + "/" + optional + "/"
62                                     + outcome;
63                         } else if (timestamp) {
64                             reqUrl = "/api/v1/results/getbytimestamp/" + lab
65                                     + "/" + blueprintName + "/" + version + "/"
66                                     + timestamp;
67                         } else if (date) {
68                             reqUrl = "/api/v1/results/getbasedondate/" + lab
69                                     + "/" + blueprintName + "/" + version + "/"
70                                     + date;
71                         } else {
72                             reqUrl = "/api/v1/results/getmostrecent/"
73                                     + blueprintName + "/" + version + "/" + lab;
74                         }
75                         restAPISvc
76                                 .getRestAPI(
77                                         reqUrl,
78                                         function(resultData) {
79                                             if (resultData) {
80                                                 restAPISvc
81                                                         .getRestAPI(
82                                                                 "/api/v1/silo/",
83                                                                 function(
84                                                                         siloData) {
85                                                                     $scope.silos = siloData;
86                                                                     $scope.loadingResults = false;
87                                                                     if (!Array
88                                                                             .isArray(resultData)) {
89                                                                         $scope.validationNexusTestResults
90                                                                                 .push(resultData);
91                                                                     } else {
92                                                                         $scope.validationNexusTestResults = resultData;
93                                                                     }
94                                                                 });
95                                             } else {
96                                                 confirm("No data was found");
97                                                 $scope.loadingResults = false;
98                                             }
99                                         });
100                         $scope.descending = true;
101                     }
102
103                     $scope.dateTimeSort = function(validationNexusTestResult) {
104                         return new Date(validationNexusTestResult.dateOfStorage)
105                                 .getTime();
106                     }
107
108                     $scope.descendingOrder = function() {
109                         $scope.descending = true;
110                     }
111
112                     $scope.ascendingOrder = function() {
113                         $scope.descending = false;
114                     }
115
116                     $scope.refreshValidationResults = function() {
117                         initialize();
118                     }
119
120                     $scope.getTestSuiteResults = function(
121                             validationNexusTestResult) {
122                         if (!generalValidationResultsSvc
123                                 .mapResult(validationNexusTestResult)) {
124                             return;
125                         }
126                         var scope = $rootScope.$new();
127                         scope.params = validationNexusTestResult;
128                         $modal
129                                 .open({
130                                     scope : scope,
131                                     templateUrl : 'app/BluvalUI/ValidationResults/TestSuiteResults/TestSuiteResultsModal.html',
132                                     controller : 'TestSuiteResultsController'
133                                 });
134                     }
135
136                 });