1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function () {
'use strict';
angular
.module('testapiApp')
.controller('ResultsController', ResultsController);
angular
.module('testapiApp')
.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);
ResultsController.$inject = [
'$scope', '$http', '$filter', '$state', 'testapiApiUrl', 'raiseAlert',
'keepState'
];
/**
* TestAPI Results Controller
* This controller is for the '/results' page where a user can browse
* a listing of community uploaded results.
*/
function ResultsController($scope, $http, $filter, $state, testapiApiUrl,
raiseAlert, keepState) {
var ctrl = this;
ctrl.open = open;
ctrl.clearFilters = clearFilters;
ctrl.deleteTag = deleteTag;
ctrl.filterList= filterList;
ctrl.testFilter = testFilter
ctrl.viewResult = viewResult;
ctrl.filter = "pod"
ctrl.filterValue = "pod_name"
ctrl.encodeFilter = encodeFilter
ctrl.tagArray = {}
ctrl.filterOption=[]
/** Mappings of Interop WG components to marketing program names. */
ctrl.targetMappings = {
'platform': 'Openstack Powered Platform',
'compute': 'OpenStack Powered Compute',
'object': 'OpenStack Powered Object Storage'
};
/** Initial page to be on. */
ctrl.currentPage = 1;
/**
* How many results should display on each page. Since pagination
* is server-side implemented, this value should match the
* 'results_per_page' configuration of the TestAPI server which
* defaults to 20.
*/
ctrl.itemsPerPage = 20;
/**
* How many page buttons should be displayed at max before adding
* the '...' button.
*/
ctrl.maxSize = 5;
/** The upload date lower limit to be used in filtering results. */
ctrl.startDate = '';
/** The upload date upper limit to be used in filtering results. */
ctrl.endDate = '';
/** The date format for the date picker. */
ctrl.format = 'yyyy-MM-dd';
/** Check to see if this page should display user-specific results. */
// ctrl.isUserResults = $state.current.name === 'userResults';
// need auth to browse
// ctrl.isUserResults = $state.current.name === 'userResults';
// // Should only be on user-results-page if authenticated.
// if (ctrl.isUserResults && !$scope.auth.isAuthenticated) {
// $state.go('home');
// }
ctrl.pageHeader = "Test Results"
ctrl.pageParagraph = ctrl.isUserResults ?
'Your most recently uploaded test results are listed here.' :
'The most recently uploaded community test results are listed ' +
'here.';
// ctrl.uploadState = '';
ctrl.isPublic = false;
// if (ctrl.isUserResults) {
// ctrl.authRequest = $scope.auth.doSignCheck()
// .then(ctrl.filterList);
// // ctrl.getUserProducts();
// } else {
// ctrl.filterList();
// }
function encodeFilter(){
ctrl.filterText = ''
ctrl.filterOption=[]
if(ctrl.filter=="pod" || ctrl.filter=="project" || ctrl.filter=="scenario"){
var reqURL = testapiApiUrl +"/" + ctrl.filter + "s"
ctrl.datasRequest =
$http.get(reqURL).success(function (data) {
ctrl.filterData = data;
for(var index in ctrl.filterData[ctrl.filter + "s"]){
if( ctrl.filterOption.indexOf(ctrl.filterData[ctrl.filter + "s"][index]["name"]) < 0){
ctrl.filterOption.push(ctrl.filterData[ctrl.filter + "s"][index]["name"])
}
}
}).catch(function (data) {
ctrl.data = null;
ctrl.showError = true;
ctrl.error = data.statusText;
});
}
else if(ctrl.filter=="case"){
if("project" in ctrl.tagArray){
var reqURL = testapiApiUrl +"/projects/"+ctrl.tagArray["project"]+"/cases"
ctrl.dataRequest =
$http.get(reqURL).success(function (data) {
ctrl.filterData = data;
for(var index in ctrl.filterData.testcases){
if( ctrl.filterOption.indexOf(ctrl.filterData.testcases[index]["name"]) < 0){
ctrl.filterOption.push(ctrl.filterData.testcases[index]["name"])
}
}
}).catch(function (data) {
ctrl.data = null;
ctrl.showError = true;
ctrl.error = data.statusText;
});
}
else{
var reqURL = testapiApiUrl +"/projects"
ctrl.dataRequest =
$http.get(reqURL).success(function (data) {
ctrl.projectsData = data;
for(var indexP in ctrl.projectsData.projects){
reqURL = testapiApiUrl +"/projects/" + ctrl.projectsData.projects[indexP]["name"] +"/cases"
ctrl.datasRequest =
$http.get(reqURL).success(function (data) {
ctrl.filterData = data;
for(var index in ctrl.filterData.testcases){
if( ctrl.filterOption.indexOf(ctrl.filterData.testcases[index]["name"]) < 0){
ctrl.filterOption.push(ctrl.filterData.testcases[index]["name"])
}
}
}).catch(function (data) {
ctrl.data = null;
ctrl.showError = true;
ctrl.error = data.statusText;
});
}
}).catch(function (data) {
ctrl.data = null;
ctrl.showError = true;
ctrl.error = data.statusText;
});
}
}
}
function viewResult(_id){
$state.go('result', {'_id':_id}, {reload: true});
}
function deleteTag(index){
delete ctrl.tagArray[index];
ctrl.filterList();
}
function testFilter(text){
for (var filter in ctrl.tagArray){
if(text==filter){
return true;
}
}
return false;
}
/**
* This will contact the TestAPI API to get a listing of test run
* results.
*/
function filterList(){
if(ctrl.filter && ctrl.filterText!="" && ctrl.filterText!=undefined){
ctrl.tagArray[ctrl.filter] = ctrl.filterText;
if(!keepState.filter.resultFilter){
keepState.filter.resultFilter = {}
}
keepState.filter.resultFilter[ctrl.filter] = ctrl.filterText
}
else if(Object.keys(ctrl.tagArray).length==0){
if(keepState.filter.resultFilter){
ctrl.tagArray = keepState.filter.resultFilter
}
}
ctrl.showError = false;
var content_url = testapiApiUrl + '/results' +
'?page=' + ctrl.currentPage;
for(var key in ctrl.tagArray){
if(key=="start_date"){
var start = $filter('date')(ctrl.tagArray[key], 'yyyy-MM-dd');
if (start) {
content_url =
content_url + '&from=' + start + ' 00:00:00';
}
}
else if(key=="end_date"){
var end = $filter('date')(ctrl.tagArray[key], 'yyyy-MM-dd');
if (end) {
content_url = content_url + '&to=' + end + ' 23:59:59';
}
}
else{
content_url = content_url + "&" + key + "=" + ctrl.tagArray[key]
}
if (ctrl.isUserResults) {
content_url = content_url + '&signed';
}
}
ctrl.resultsRequest =
$http.get(content_url).success(function (data) {
ctrl.data = data;
ctrl.totalItems = ctrl.data.pagination.total_pages * ctrl.itemsPerPage;
ctrl.currentPage = ctrl.data.pagination.current_page;
ctrl.encodeFilter();
}).error(function (error) {
ctrl.data = null;
ctrl.totalItems = 0;
ctrl.showError = true;
ctrl.error =
'Error retrieving results listing from server: ' +
angular.toJson(error);
});
ctrl.filterText = ''
}
ctrl.filterList();
/**
* This is called when the date filter calendar is opened. It
* does some event handling, and sets a scope variable so the UI
* knows which calendar was opened.
* @param {Object} $event - The Event object
* @param {String} openVar - Tells which calendar was opened
*/
function open($event, openVar) {
$event.preventDefault();
$event.stopPropagation();
ctrl[openVar] = true;
}
/**
* This function will clear all filters and update the results
* listing.
*/
function clearFilters() {
ctrl.tagArray = {}
ctrl.filter = undefined
keepState.filter.resultFilter = {}
ctrl.filterList();
}
}
})();
|