[UI] Common class for results
[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.filterWithTimestamp = generalValidationResultsSvc.filterWithTimestamp;
29
30                     initialize();
31
32                     function initialize() {
33                         $scope.loadingResults = true;
34                         $scope.validationDbTestResults = [];
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                                                 $scope.loadingResults = false;
81                                                 if (!Array.isArray(resultData)) {
82                                                     $scope.validationDbTestResults
83                                                             .push(resultData);
84                                                 } else {
85                                                     $scope.validationDbTestResults = resultData;
86                                                 }
87                                             } else {
88                                                 confirm("No data was found");
89                                                 $scope.loadingResults = false;
90                                             }
91                                         });
92                         $scope.descending = true;
93                     }
94
95                     $scope.dateTimeSort = function(validationDbTestResult) {
96                         return new Date(validationDbTestResult.dateStorage)
97                                 .getTime();
98                     }
99
100                     $scope.descendingOrder = function() {
101                         $scope.descending = true;
102                     }
103
104                     $scope.ascendingOrder = function() {
105                         $scope.descending = false;
106                     }
107
108                     $scope.refreshValidationResults = function() {
109                         initialize();
110                     }
111
112                     $scope.getTestSuiteResults = function(
113                             validationDbTestResult) {
114                         if (!generalValidationResultsSvc
115                                 .mapResult(validationDbTestResult)) {
116                             return;
117                         }
118                         var scope = $rootScope.$new();
119                         scope.params = validationDbTestResult;
120                         $modal
121                                 .open({
122                                     scope : scope,
123                                     templateUrl : 'app/BluvalUI/ValidationResults/TestSuiteResults/TestSuiteResultsModal.html',
124                                     controller : 'TestSuiteResultsController'
125                                 });
126                     }
127
128                 });