bugfix: TestAPI auto deploy success but shown as fail
[releng.git] / utils / test / reporting / pages / app / scripts / controllers / table.controller.js
1 'use strict';
2
3 /**
4  * @ngdoc function
5  * @name opnfvdashBoardAngularApp.controller:TableController
6  * @description
7  * # TableController
8  * Controller of the opnfvdashBoardAngularApp
9  */
10 angular.module('opnfvApp')
11     .controller('TableController', ['$scope', '$state', '$stateParams', '$http', 'TableFactory', '$timeout',
12         function($scope, $state, $stateParams, $http, TableFactory, $timeout) {
13
14             $scope.filterlist = [];
15             $scope.selection = [];
16             $scope.statusList = [];
17             $scope.projectList = [];
18             $scope.installerList = [];
19             $scope.versionlist = [];
20             $scope.loopci = [];
21             $scope.time = [];
22             $scope.tableDataAll = {};
23             $scope.tableInfoAll = {};
24             $scope.scenario = {};
25             // $scope.selectProjects = [];
26
27
28             $scope.VersionConfig = {
29                 create: true,
30                 valueField: 'title',
31                 labelField: 'title',
32                 delimiter: '|',
33                 maxItems: 1,
34                 placeholder: 'Version',
35                 onChange: function(value) {
36                     checkElementArrayValue($scope.selection, $scope.VersionOption);
37                     $scope.selection.push(value);
38                     // console.log($scope.selection);
39                     getScenarioData();
40
41                 }
42             }
43
44             $scope.LoopConfig = {
45                 create: true,
46                 valueField: 'title',
47                 labelField: 'title',
48                 delimiter: '|',
49                 maxItems: 1,
50                 placeholder: 'Loop',
51                 onChange: function(value) {
52                     checkElementArrayValue($scope.selection, $scope.LoopOption);
53                     $scope.selection.push(value);
54                     // console.log($scope.selection);
55                     getScenarioData();
56
57                 }
58             }
59
60             $scope.TimeConfig = {
61                 create: true,
62                 valueField: 'title',
63                 labelField: 'title',
64                 delimiter: '|',
65                 maxItems: 1,
66                 placeholder: 'Time',
67                 onChange: function(value) {
68                     checkElementArrayValue($scope.selection, $scope.TimeOption);
69                     $scope.selection.push(value);
70                     // console.log($scope.selection)
71                     getScenarioData();
72
73
74                 }
75             }
76
77
78             init();
79
80             function init() {
81                 $scope.toggleSelection = toggleSelection;
82                 getScenarioData();
83                 getFilters();
84             }
85
86             function getFilters() {
87                 TableFactory.getFilter().get({
88
89                 }).$promise.then(function(response) {
90                     if (response != null) {
91                         $scope.statusList = response.filters.status;
92                         $scope.projectList = response.filters.projects;
93                         $scope.installerList = response.filters.installers;
94                         $scope.versionlist = response.filters.version;
95                         $scope.loopci = response.filters.loops;
96                         $scope.time = response.filters.time;
97
98                         $scope.statusListString = $scope.statusList.toString();
99                         $scope.projectListString = $scope.projectList.toString();
100                         $scope.installerListString = $scope.installerList.toString();
101                         $scope.VersionSelected = $scope.versionlist[1];
102                         $scope.LoopCiSelected = $scope.loopci[0];
103                         $scope.TimeSelected = $scope.time[0];
104                         radioSetting($scope.versionlist, $scope.loopci, $scope.time);
105
106                     } else {
107                         alert("网络错误");
108                     }
109                 })
110             }
111
112             function getScenarioData() {
113
114                 // var utl = BASE_URL + '/scenarios';
115                 var data = {
116                     'status': ['success', 'danger', 'warning'],
117                     'projects': ['functest', 'yardstick'],
118                     'installers': ['apex', 'compass', 'fuel', 'joid'],
119                     'version': $scope.VersionSelected,
120                     'loops': $scope.LoopCiSelected,
121                     'time': $scope.TimeSelected
122                 };
123
124                 TableFactory.getScenario(data).then(function(response) {
125                     if (response.status == 200) {
126                         $scope.scenario = response.data;
127
128                         reSettingcolspan();
129                     }
130
131                 }, function(error) {
132
133                 })
134
135             }
136
137             function reSettingcolspan() {
138                 if ($scope.selectProjects == undefined || $scope.selectProjects == null) {
139                     constructJson();
140                     $scope.colspan = $scope.tableDataAll.colspan;
141
142                 } else {
143                     constructJson();
144                     $scope.colspan = $scope.tempColspan;
145                 }
146                 // console.log("test")
147             }
148
149             //construct json 
150             function constructJson(selectProject) {
151
152                 var colspan;
153                 var InstallerData;
154                 var projectsInfo;
155                 $scope.tableDataAll["scenario"] = [];
156
157
158                 for (var item in $scope.scenario.scenarios) {
159
160                     var headData = Object.keys($scope.scenario.scenarios[item].installers).sort();
161                     var scenarioStatus = $scope.scenario.scenarios[item].status;
162                     var scenarioStatusDisplay;
163                     if (scenarioStatus == "success") {
164                         scenarioStatusDisplay = "navy";
165                     } else if (scenarioStatus == "danger") {
166                         scenarioStatusDisplay = "danger";
167                     } else if (scenarioStatus == "warning") {
168                         scenarioStatusDisplay = "warning";
169                     }
170
171                     InstallerData = headData;
172                     var projectData = [];
173                     var datadisplay = [];
174                     var projects = [];
175
176                     for (var j = 0; j < headData.length; j++) {
177
178                         projectData.push($scope.scenario.scenarios[item].installers[headData[j]]);
179                     }
180                     for (var j = 0; j < projectData.length; j++) {
181
182                         for (var k = 0; k < projectData[j].length; k++) {
183                             projects.push(projectData[j][k].project);
184                             var temArray = [];
185                             if (projectData[j][k].score == null) {
186                                 temArray.push("null");
187                                 temArray.push(projectData[j][k].project);
188                                 temArray.push(headData[j]);
189                             } else {
190                                 temArray.push(projectData[j][k].score);
191                                 temArray.push(projectData[j][k].project);
192                                 temArray.push(headData[j]);
193                             }
194
195
196                             if (projectData[j][k].status == "platinium") {
197                                 temArray.push("primary");
198                                 temArray.push("P");
199                             } else if (projectData[j][k].status == "gold") {
200                                 temArray.push("danger");
201                                 temArray.push("G");
202                             } else if (projectData[j][k].status == "silver") {
203                                 temArray.push("warning");
204                                 temArray.push("S");
205                             } else if (projectData[j][k].status == null) {
206                                 temArray.push("null");
207                             }
208
209                             datadisplay.push(temArray);
210
211                         }
212
213                     }
214
215                     colspan = projects.length / headData.length;
216
217                     var tabledata = {
218                         scenarioName: item,
219                         Installer: InstallerData,
220                         projectData: projectData,
221                         projects: projects,
222                         datadisplay: datadisplay,
223                         colspan: colspan,
224                         status: scenarioStatus,
225                         statusDisplay: scenarioStatusDisplay
226                     };
227
228                     JSON.stringify(tabledata);
229                     $scope.tableDataAll.scenario.push(tabledata);
230
231
232                     // console.log(tabledata);
233
234                 }
235
236
237                 projectsInfo = $scope.tableDataAll.scenario[0].projects;
238
239                 var tempHeadData = [];
240
241                 for (var i = 0; i < InstallerData.length; i++) {
242                     for (var j = 0; j < colspan; j++) {
243                         tempHeadData.push(InstallerData[i]);
244                     }
245                 }
246
247                 //console.log(tempHeadData);
248
249                 var projectsInfoAll = [];
250
251                 for (var i = 0; i < projectsInfo.length; i++) {
252                     var tempA = [];
253                     tempA.push(projectsInfo[i]);
254                     tempA.push(tempHeadData[i]);
255                     projectsInfoAll.push(tempA);
256
257                 }
258                 //console.log(projectsInfoAll);
259
260                 $scope.tableDataAll["colspan"] = colspan;
261                 $scope.tableDataAll["Installer"] = InstallerData;
262                 $scope.tableDataAll["Projects"] = projectsInfoAll;
263
264                 // console.log($scope.tableDataAll);
265                 $scope.colspan = $scope.tableDataAll.colspan;
266                 console.log($scope.tableDataAll);
267
268             }
269
270             //get json element size
271             function getSize(jsondata) {
272                 var size = 0;
273                 for (var item in jsondata) {
274                     size++;
275                 }
276                 return size;
277             }
278
279
280             // console.log($scope.colspan);
281
282
283             //find all same element index 
284             function getSameElementIndex(array, element) {
285                 var indices = [];
286                 var idx = array.indexOf(element);
287                 while (idx != -1) {
288                     indices.push(idx);
289                     idx = array.indexOf(element, idx + 1);
290                 }
291                 //return indices;
292                 var result = { element: element, index: indices };
293                 JSON.stringify(result);
294                 return result;
295             }
296
297             //delete element in array
298             function deletElement(array, index) {
299                 array.splice(index, 1);
300
301             }
302
303             function radioSetting(array1, array2, array3) {
304                 var tempVersion = [];
305                 var tempLoop = [];
306                 var tempTime = [];
307                 for (var i = 0; i < array1.length; i++) {
308                     var temp = {
309                         title: array1[i]
310                     };
311                     tempVersion.push(temp);
312                 }
313                 for (var i = 0; i < array2.length; i++) {
314                     var temp = {
315                         title: array2[i]
316                     };
317                     tempLoop.push(temp);
318                 }
319                 for (var i = 0; i < array3.length; i++) {
320                     var temp = {
321                         title: array3[i]
322                     };
323                     tempTime.push(temp);
324                 }
325                 $scope.VersionOption = tempVersion;
326                 $scope.LoopOption = tempLoop;
327                 $scope.TimeOption = tempTime;
328             }
329
330             //remove element in the array
331             function removeArrayValue(arr, value) {
332                 for (var i = 0; i < arr.length; i++) {
333                     if (arr[i] == value) {
334                         arr.splice(i, 1);
335                         break;
336                     }
337                 }
338             }
339
340             //check if exist element
341             function checkElementArrayValue(arrayA, arrayB) {
342                 for (var i = 0; i < arrayB.length; i++) {
343                     if (arrayA.indexOf(arrayB[i].title) > -1) {
344                         removeArrayValue(arrayA, arrayB[i].title);
345                     }
346                 }
347             }
348
349             function toggleSelection(status) {
350                 var idx = $scope.selection.indexOf(status);
351
352                 if (idx > -1) {
353                     $scope.selection.splice(idx, 1);
354                     filterData($scope.selection)
355                 } else {
356                     $scope.selection.push(status);
357                     filterData($scope.selection)
358                 }
359                 // console.log($scope.selection);
360
361             }
362
363             //filter function
364             function filterData(selection) {
365
366                 $scope.selectInstallers = [];
367                 $scope.selectProjects = [];
368                 $scope.selectStatus = [];
369                 for (var i = 0; i < selection.length; i++) {
370                     if ($scope.statusListString.indexOf(selection[i]) > -1) {
371                         $scope.selectStatus.push(selection[i]);
372                     }
373                     if ($scope.projectListString.indexOf(selection[i]) > -1) {
374                         $scope.selectProjects.push(selection[i]);
375                     }
376                     if ($scope.installerListString.indexOf(selection[i]) > -1) {
377                         $scope.selectInstallers.push(selection[i]);
378                     }
379                 }
380
381
382                 // $scope.colspan = $scope.selectProjects.length;
383                 //when some selection is empty, we set it full
384                 if ($scope.selectInstallers.length == 0) {
385                     $scope.selectInstallers = $scope.installerList;
386
387                 }
388                 if ($scope.selectProjects.length == 0) {
389                     $scope.selectProjects = $scope.projectList;
390                     $scope.colspan = $scope.tableDataAll.colspan;
391                 } else {
392                     $scope.colspan = $scope.selectProjects.length;
393                     $scope.tempColspan = $scope.colspan;
394                 }
395                 if ($scope.selectStatus.length == 0) {
396                     $scope.selectStatus = $scope.statusList
397                 }
398
399                 // console.log($scope.selectStatus);
400                 // console.log($scope.selectProjects);
401
402             }
403
404
405         }
406     ]);