8ca1e474ce0a9085a4b0fc3664d34d61c5c59d62
[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', 'TableFactory', function ($scope, $state, $stateParams, TableFactory) {
12
13         $scope.filterlist = [];
14         $scope.selection = [];
15         $scope.statusList = ["Success", "Warning", "Danger"];
16         $scope.projectList = ["Deployment", "Functest", "Yardstick"];
17         $scope.installerList = ["apex", "compass", "fuel", "joid"];
18         $scope.versionlist = ["Colorado", "Master"];
19         $scope.loopci = ["Daily", "Weekly", "Monthly"];
20         $scope.time = ["10 days", "1 Month"];
21         $scope.tableDataAll = {};
22         $scope.tableInfoAll = {};
23
24
25
26         $scope.scenario =
27             {
28                 "scenarios": {
29                     "os-nosdn-kvm-noha": {
30                         "status": "Success",
31                         "installers": {
32                             "apex": [
33                                 {
34                                     "project": "Deployment",
35                                     "score": "13/14",
36                                     "status": "SUCCESS",
37
38
39                                 },
40                                 {
41                                     "project": "Functest",
42                                     "score": "null",
43                                     "status": "SUCCESS"
44                                 },
45                                 {
46                                     "project": "Yardstick",
47                                     "score": "13/14",
48                                     "status": "SUCCESS"
49                                 }
50                             ],
51                             "compass": [
52                                 {
53                                     "project": "Deployment",
54                                     "score": "13/14",
55                                     "status": "SUCCESS"
56                                 },
57                                 {
58                                     "project": "Functest",
59                                     "score": "13/14",
60                                     "status": "SUCCESS"
61                                 },
62                                 {
63                                     "project": "Yardstick",
64                                     "score": "13/14",
65                                     "status": "SUCCESS"
66                                 }
67                             ],
68                             "fuel": [
69                                 {
70                                     "project": "Deployment",
71                                     "score": "13/14",
72                                     "status": "SUCCESS"
73                                 },
74                                 {
75                                     "project": "Functest",
76                                     "score": "13/14",
77                                     "status": "SUCCESS"
78                                 },
79                                 {
80                                     "project": "Yardstick",
81                                     "score": "13/14",
82                                     "status": "SUCCESS"
83                                 }
84                             ],
85                             "joid": [
86                                 {
87                                     "project": "Deployment",
88                                     "score": "13/14",
89                                     "status": "SUCCESS"
90                                 },
91                                 {
92                                     "project": "Functest",
93                                     "score": "13/14",
94                                     "status": "SUCCESS"
95                                 },
96                                 {
97                                     "project": "Yardstick",
98                                     "score": "13/14",
99                                     "status": "SUCCESS"
100                                 }
101                             ]
102                         }
103                     },
104                     "os-nosdn-ovs-ha": {
105                         "status": "Danger",
106                         "installers": {
107                             "apex": [
108                                 {
109                                     "project": "Deployment",
110                                     "score": "13/14",
111                                     "status": "SUCCESS",
112
113
114                                 },
115                                 {
116                                     "project": "Functest",
117                                     "score": "13/14",
118                                     "status": "SUCCESS"
119                                 },
120                                 {
121                                     "project": "Yardstick",
122                                     "score": "13/14",
123                                     "status": "SUCCESS"
124                                 }
125                             ],
126                             "compass": [
127                                 {
128                                     "project": "Deployment",
129                                     "score": "13/14",
130                                     "status": "SUCCESS"
131                                 },
132                                 {
133                                     "project": "Functest",
134                                     "score": "13/14",
135                                     "status": "SUCCESS"
136                                 },
137                                 {
138                                     "project": "Yardstick",
139                                     "score": "13/14",
140                                     "status": "SUCCESS"
141                                 }
142                             ],
143                             "fuel": [
144                                 {
145                                     "project": "Deployment",
146                                     "score": "13/14",
147                                     "status": "SUCCESS"
148                                 },
149                                 {
150                                     "project": "Functest",
151                                     "score": "13/14",
152                                     "status": "SUCCESS"
153                                 },
154                                 {
155                                     "project": "Yardstick",
156                                     "score": "13/14",
157                                     "status": "SUCCESS"
158                                 }
159                             ],
160                             "joid": [
161                                 {
162                                     "project": "Deployment",
163                                     "score": "13/14",
164                                     "status": "SUCCESS"
165                                 },
166                                 {
167                                     "project": "Functest",
168                                     "score": "13/14",
169                                     "status": "SUCCESS"
170                                 },
171                                 {
172                                     "project": "Yardstick",
173                                     "score": "13/14",
174                                     "status": "SUCCESS"
175                                 }
176                             ]
177                         }
178                     },
179                     "os-nosdn-ovs-noha": {
180                         "status": "Warning",
181                         "installers": {
182                             "apex": [
183                                 {
184                                     "project": "Deployment",
185                                     "score": "13/14",
186                                     "status": "SUCCESS",
187
188
189                                 },
190                                 {
191                                     "project": "Functest",
192                                     "score": "13/14",
193                                     "status": "SUCCESS"
194                                 },
195                                 {
196                                     "project": "Yardstick",
197                                     "score": "13/14",
198                                     "status": "SUCCESS"
199                                 }
200                             ],
201                             "compass": [
202                                 {
203                                     "project": "Deployment",
204                                     "score": "13/14",
205                                     "status": "SUCCESS"
206                                 },
207                                 {
208                                     "project": "Functest",
209                                     "score": "13/14",
210                                     "status": "SUCCESS"
211                                 },
212                                 {
213                                     "project": "Yardstick",
214                                     "score": "13/14",
215                                     "status": "SUCCESS"
216                                 }
217                             ],
218                             "fuel": [
219                                 {
220                                     "project": "Deployment",
221                                     "score": "13/14",
222                                     "status": "SUCCESS"
223                                 },
224                                 {
225                                     "project": "Functest",
226                                     "score": "13/14",
227                                     "status": "SUCCESS"
228                                 },
229                                 {
230                                     "project": "Yardstick",
231                                     "score": "13/14",
232                                     "status": "SUCCESS"
233                                 }
234                             ],
235                             "joid": [
236                                 {
237                                     "project": "Deployment",
238                                     "score": "13/14",
239                                     "status": "SUCCESS"
240                                 },
241                                 {
242                                     "project": "Functest",
243                                     "score": "13/14",
244                                     "status": "SUCCESS"
245                                 },
246                                 {
247                                     "project": "Yardstick",
248                                     "score": "13/14",
249                                     "status": "SUCCESS"
250                                 }
251                             ]
252                         }
253                     }
254                 }
255             };
256
257         // var headData = Object.keys($scope.scenario.scenarios.os_nosdn_kvm_noha.installers);
258         // $scope.headData = headData;
259         //construct json
260         function constructJson() {
261
262             var colspan;
263             var InstallerData;
264             var projectsInfo;
265             $scope.tableDataAll["scenario"] = [];
266
267
268             for (var item in $scope.scenario.scenarios) {
269
270
271
272
273                 var headData = Object.keys($scope.scenario.scenarios[item].installers);
274                 var scenarioStatus = $scope.scenario.scenarios[item].status;
275
276
277                 InstallerData = headData;
278                 var projectData = [];
279                 var datadisplay = [];
280                 var projects = [];
281
282
283                 for (var j = 0; j < headData.length; j++) {
284
285                     projectData.push($scope.scenario.scenarios[item].installers[headData[j]]);
286                 }
287                 for (var j = 0; j < projectData.length; j++) {
288
289                     for (var k = 0; k < projectData[j].length; k++) {
290                         projects.push(projectData[j][k].project);
291                         var temArray = [];
292                         temArray.push(projectData[j][k].score);
293                         temArray.push(projectData[j][k].project);
294                         temArray.push(headData[j]);
295                         datadisplay.push(temArray);
296
297                     }
298
299                 }
300
301                 colspan = projects.length / headData.length;
302
303                 var tabledata = {
304                     scenarioName: item, Installer: InstallerData, projectData: projectData, projects: projects,
305                     datadisplay: datadisplay, colspan: colspan, status: scenarioStatus
306                 };
307
308                 JSON.stringify(tabledata);
309                 $scope.tableDataAll.scenario.push(tabledata);
310
311             }
312
313
314             projectsInfo = $scope.tableDataAll.scenario[0].projects;
315
316             var tempHeadData = [];
317
318
319
320             for (var i = 0; i < InstallerData.length; i++) {
321                 for (var j = 0; j < colspan; j++) {
322                     tempHeadData.push(InstallerData[i]);
323                 }
324             }
325
326             console.log(tempHeadData);
327
328             var projectsInfoAll = [];
329
330             for (var i = 0; i < projectsInfo.length; i++) {
331                 var tempA = [];
332                 tempA.push(projectsInfo[i]);
333                 tempA.push(tempHeadData[i]);
334                 projectsInfoAll.push(tempA);
335
336             }
337             console.log(projectsInfoAll);
338
339             $scope.tableDataAll["colspan"] = colspan;
340             $scope.tableDataAll["Installer"] = InstallerData;
341             $scope.tableDataAll["Projects"] = projectsInfoAll;
342
343             console.log($scope.tableDataAll);
344
345         }
346
347         //get json element size
348         function getSize(jsondata) {
349             var size = 0;
350             for (var item in jsondata) {
351                 size++;
352             }
353             return size;
354         }
355
356         init();
357         function init() {
358             $scope.toggleSelection = toggleSelection;
359
360             constructJson();
361
362         }
363
364         // $scope.test=false;
365
366         var statusListString = $scope.statusList.toString();
367         var projectListString = $scope.projectList.toString();
368         var installerListString = $scope.installerList.toString();
369
370
371         $scope.colspan=$scope.tableDataAll.colspan;
372         //filter function
373         function filterData() {
374
375
376             $scope.selectInstallers = [];
377             $scope.selectProjects = [];
378             $scope.selectStatus = [];
379             for (var i = 0; i < $scope.selection.length; i++) {
380                 if (statusListString.indexOf($scope.selection[i]) > -1) {
381                     $scope.selectStatus.push($scope.selection[i]);
382                 }
383                 if (projectListString.indexOf($scope.selection[i]) > -1) {
384                     $scope.selectProjects.push($scope.selection[i]);
385                 }
386                 if (installerListString.indexOf($scope.selection[i]) > -1) {
387                     $scope.selectInstallers.push($scope.selection[i]);
388                 }
389             }
390
391             $scope.colspan=$scope.selectProjects.length;
392             //when some selection is empty, we set it full
393             if($scope.selectInstallers.length==0){
394                 $scope.selectInstallers=$scope.installerList;
395
396             }
397             if($scope.selectProjects.length==0){
398                 $scope.selectProjects=$scope.projectList;
399                 $scope.colspan=$scope.tableDataAll.colspan;
400             }
401             if($scope.selectStatus.length==0){
402                 $scope.selectStatus=$scope.statusList
403             }
404         }
405
406
407         //find all same element index
408         function getSameElementIndex(array, element) {
409             var indices = [];
410             var idx = array.indexOf(element);
411             while (idx != -1) {
412                 indices.push(idx);
413                 idx = array.indexOf(element, idx + 1);
414             }
415             //return indices;
416             var result = { element: element, index: indices };
417             JSON.stringify(result);
418             return result;
419         }
420
421         //delete element in array
422         function deletElement(array, index) {
423             array.splice(index, 1);
424
425         }
426
427
428         $scope.VersionOption = [
429             { title: 'Colorado' },
430             { title: 'Master' }
431         ];
432         $scope.VersionConfig = {
433             create: true,
434             valueField: 'title',
435             labelField: 'title',
436             delimiter: '|',
437             maxItems: 1,
438             placeholder: 'Version',
439             onChange: function (value) {
440                 checkElementArrayValue($scope.selection, $scope.VersionOption);
441                 $scope.selection.push(value);
442                 // console.log($scope.selection);
443
444             }
445
446         }
447
448         $scope.LoopOption = [
449             { title: 'Daily' },
450             { title: 'Weekly' },
451             { title: 'Monthly' }
452         ];
453         $scope.LoopConfig = {
454             create: true,
455             valueField: 'title',
456             labelField: 'title',
457             delimiter: '|',
458             maxItems: 1,
459             placeholder: 'Loop',
460             onChange: function (value) {
461                 checkElementArrayValue($scope.selection, $scope.LoopOption);
462                 $scope.selection.push(value);
463                 // console.log($scope.selection);
464
465             }
466         }
467
468         $scope.TimeOption = [
469             { title: '10 days' },
470             { title: '1 month' }
471         ];
472         $scope.TimeConfig = {
473             create: true,
474             valueField: 'title',
475             labelField: 'title',
476             delimiter: '|',
477             maxItems: 1,
478             placeholder: 'Time',
479             onChange: function (value) {
480                 checkElementArrayValue($scope.selection, $scope.TimeOption);
481                 $scope.selection.push(value);
482                 // console.log($scope.selection)
483
484             }
485         }
486
487         //remove element in the array
488         function removeArrayValue(arr, value) {
489             for (var i = 0; i < arr.length; i++) {
490                 if (arr[i] == value) {
491                     arr.splice(i, 1);
492                     break;
493                 }
494             }
495         }
496
497         //check if exist element
498         function checkElementArrayValue(arrayA, arrayB) {
499             for (var i = 0; i < arrayB.length; i++) {
500                 if (arrayA.indexOf(arrayB[i].title) > -1) {
501                     removeArrayValue(arrayA, arrayB[i].title);
502                 }
503             }
504         }
505
506         function toggleSelection(status) {
507             var idx = $scope.selection.indexOf(status);
508
509             if (idx > -1) {
510                 $scope.selection.splice(idx, 1);
511             }
512             else {
513                 $scope.selection.push(status);
514             }
515             console.log($scope.selection);
516             filterData();
517
518         }
519
520     }]);