Merge "Add qtip job to pod zte-virtual6"
[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             init();
15
16             function init() {
17                 $scope.filterlist = [];
18                 $scope.selection = [];
19
20                 $scope.statusList = [];
21                 $scope.projectList = [];
22                 $scope.installerList = [];
23                 $scope.versionlist = [];
24                 $scope.loopList = [];
25                 $scope.timeList = [];
26
27                 $scope.selectStatus = [];
28                 $scope.selectProjects = [];
29                 $scope.selectInstallers = [];
30                 $scope.selectVersion = null;
31                 $scope.selectLoop = null;
32                 $scope.selectTime = null;
33
34                 $scope.statusClicked = false;
35                 $scope.installerClicked = false;
36                 $scope.projectClicked = false;
37
38                 $scope.scenarios = {};
39
40                 $scope.VersionConfig = {
41                     create: true,
42                     valueField: 'title',
43                     labelField: 'title',
44                     delimiter: '|',
45                     maxItems: 1,
46                     placeholder: 'Version',
47                     onChange: function(value) {
48                         $scope.selectVersion = value;
49
50                         getScenarioData();
51
52                     }
53                 }
54
55                 $scope.LoopConfig = {
56                     create: true,
57                     valueField: 'title',
58                     labelField: 'title',
59                     delimiter: '|',
60                     maxItems: 1,
61                     placeholder: 'Loop',
62                     onChange: function(value) {
63                         $scope.selectLoop = value;
64
65                         getScenarioData();
66
67                     }
68                 }
69
70                 $scope.TimeConfig = {
71                     create: true,
72                     valueField: 'title',
73                     labelField: 'title',
74                     delimiter: '|',
75                     maxItems: 1,
76                     placeholder: 'Time',
77                     onChange: function(value) {
78                         $scope.selectTime = value;
79
80                         getScenarioData();
81                     }
82                 }
83
84                 getFilters();
85             }
86
87             function getFilters() {
88                 TableFactory.getFilter().get({
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 = toSelectList(response.filters.version);
95                         $scope.loopList = toSelectList(response.filters.loops);
96                         $scope.timeList = toSelectList(response.filters.time);
97
98                         $scope.selectStatus = copy($scope.statusList);
99                         $scope.selectInstallers = copy($scope.installerList);
100                         $scope.selectProjects = copy($scope.projectList);
101                         $scope.selectVersion = response.filters.version[0];
102                         $scope.selectLoop = response.filters.loops[0];
103                         $scope.selectTime = response.filters.time[0];
104
105                         getScenarioData();
106
107                     } else {
108                     }
109                 });
110             }
111
112             function toSelectList(arr){
113                 var tempList = [];
114                 angular.forEach(arr, function(ele){
115                     tempList.push({'title': ele});
116                 });
117                 return tempList;
118             }
119
120             function copy(arr){
121                 var tempList = [];
122                 angular.forEach(arr, function(ele){
123                     tempList.push(ele);
124                 });
125                 return tempList;
126             }
127
128             function getScenarioData() {
129
130                 var data = {
131                     'status': $scope.selectStatus,
132                     'projects': $scope.selectProjects,
133                     'installers': $scope.selectInstallers,
134                     'version': $scope.selectVersion,
135                     'loops': $scope.selectLoop,
136                     'time': $scope.selectTime
137                 };
138
139                 TableFactory.getScenario(data).then(function(response) {
140                     if (response.status == 200) {
141                         $scope.scenarios = response.data.scenarios;
142                         getScenario();
143                     }
144
145                 }, function(error) {
146                 });
147
148             }
149
150             function getScenario(){
151
152                 $scope.project_row = [];
153                 angular.forEach($scope.selectInstallers, function(installer){
154                     angular.forEach($scope.selectProjects, function(project){
155                         var temp = {
156                             'installer': installer,
157                             'project': project
158                         }
159                         $scope.project_row.push(temp);
160
161                     });
162                 });
163
164
165                 $scope.scenario_rows = [];
166                 angular.forEach($scope.scenarios, function(scenario, name){
167                     var scenario_row = {
168                         'name': null,
169                         'status': null,
170                         'statusDisplay': null,
171                         'datadisplay': [],
172                     };
173                     scenario_row.name = name;
174                     scenario_row.status = scenario.status;
175
176                     var scenarioStatusDisplay;
177                     if (scenario.status == "success") {
178                         scenarioStatusDisplay = "navy";
179                     } else if (scenario.status == "danger") {
180                         scenarioStatusDisplay = "danger";
181                     } else if (scenario.status == "warning") {
182                         scenarioStatusDisplay = "warning";
183                     }
184                     scenario_row.statusDisplay = scenarioStatusDisplay;
185
186                     angular.forEach($scope.selectInstallers, function(installer){
187                         angular.forEach($scope.selectProjects, function(project){
188                             var datadisplay = {
189                                 'installer': null,
190                                 'project': null,
191                                 'value': null,
192                                 'label': null,
193                                 'label_value': null
194                             };
195                             datadisplay.installer = installer;
196                             datadisplay.project = project;
197                             datadisplay.value = scenario.installers[installer][project].score;
198
199                             var single_status = scenario.installers[installer][project].status;
200                             if (single_status == "platinium") {
201                                 datadisplay.label = 'primary';
202                                 datadisplay.label_value = 'P';
203                             } else if (single_status == "gold") {
204                                 datadisplay.label = 'danger';
205                                 datadisplay.label_value = 'G';
206                             } else if (single_status == "silver") {
207                                 datadisplay.label = 'warning';
208                                 datadisplay.label_value = 'S';
209                             } else if (single_status == null) {
210                             }
211                             scenario_row.datadisplay.push(datadisplay);
212
213                         });
214                     });
215                     $scope.scenario_rows.push(scenario_row);
216                 });
217             }
218
219
220             function clickBase(eleList, ele){
221                 var idx = eleList.indexOf(ele);
222                 if(idx > -1){
223                     eleList.splice(idx, 1);
224                 }else{
225                     eleList.push(ele);
226                 }
227             }
228
229             $scope.clickStatus = function(status){
230                 if($scope.selectStatus.length == $scope.statusList.length && $scope.statusClicked == false){
231                     $scope.selectStatus = [];
232                     $scope.statusClicked = true;
233                 }
234
235                 clickBase($scope.selectStatus, status);
236
237                 if($scope.selectStatus.length == 0 && $scope.statusClicked == true){
238                     $scope.selectStatus = copy($scope.statusList);
239                     $scope.statusClicked = false;
240                 }
241
242                 getScenarioData();
243             }
244
245             $scope.clickInstaller = function(installer){
246                 if($scope.selectInstallers.length == $scope.installerList.length && $scope.installerClicked == false){
247                     $scope.selectInstallers = [];
248                     $scope.installerClicked = true;
249                 }
250
251                 clickBase($scope.selectInstallers, installer);
252
253                 if($scope.selectInstallers.length == 0 && $scope.installerClicked == true){
254                     $scope.selectInstallers = copy($scope.installerList);
255                     $scope.installerClicked = false;
256                 }
257
258                 getScenarioData();
259             }
260
261             $scope.clickProject = function(project){
262                 if($scope.selectProjects.length == $scope.projectList.length && $scope.projectClicked == false){
263                     $scope.selectProjects = [];
264                     $scope.projectClicked = true;
265                 }
266
267                 clickBase($scope.selectProjects, project);
268
269                 if($scope.selectProjects.length == 0 && $scope.projectClicked == true){
270                     $scope.selectProjects = copy($scope.projectList);
271                     $scope.projectClicked = false;
272                 }
273
274                 getScenarioData();
275             }
276
277         }
278     ]);