5 * @name opnfvdashBoardAngularApp.controller:TableController
8 * Controller of the opnfvdashBoardAngularApp
10 angular.module('opnfvApp')
11 .controller('TableController', ['$scope', '$state', '$stateParams', '$http', 'TableFactory', '$timeout',
12 function($scope, $state, $stateParams, $http, TableFactory, $timeout) {
14 $scope.filterlist = [];
15 $scope.selection = [];
16 $scope.statusList = [];
17 $scope.projectList = [];
18 $scope.installerList = [];
19 $scope.versionlist = [];
22 $scope.tableDataAll = {};
23 $scope.tableInfoAll = {};
25 // $scope.selectProjects = [];
28 $scope.VersionConfig = {
34 placeholder: 'Version',
35 onChange: function(value) {
36 checkElementArrayValue($scope.selection, $scope.VersionOption);
37 $scope.selection.push(value);
38 // console.log($scope.selection);
51 onChange: function(value) {
52 checkElementArrayValue($scope.selection, $scope.LoopOption);
53 $scope.selection.push(value);
54 // console.log($scope.selection);
67 onChange: function(value) {
68 checkElementArrayValue($scope.selection, $scope.TimeOption);
69 $scope.selection.push(value);
70 // console.log($scope.selection)
81 $scope.toggleSelection = toggleSelection;
86 function getFilters() {
87 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 = response.filters.version;
95 $scope.loopci = response.filters.loops;
96 $scope.time = response.filters.time;
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);
112 function getScenarioData() {
114 // var utl = BASE_URL + '/scenarios';
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
124 TableFactory.getScenario(data).then(function(response) {
125 if (response.status == 200) {
126 $scope.scenario = response.data;
137 function reSettingcolspan() {
138 if ($scope.selectProjects == undefined || $scope.selectProjects == null) {
140 $scope.colspan = $scope.tableDataAll.colspan;
144 $scope.colspan = $scope.tempColspan;
146 // console.log("test")
150 function constructJson(selectProject) {
155 $scope.tableDataAll["scenario"] = [];
158 for (var item in $scope.scenario.scenarios) {
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";
171 InstallerData = headData;
172 var projectData = [];
173 var datadisplay = [];
176 for (var j = 0; j < headData.length; j++) {
178 projectData.push($scope.scenario.scenarios[item].installers[headData[j]]);
180 for (var j = 0; j < projectData.length; j++) {
182 for (var k = 0; k < projectData[j].length; k++) {
183 projects.push(projectData[j][k].project);
185 if (projectData[j][k].score == null) {
186 temArray.push("null");
187 temArray.push(projectData[j][k].project);
188 temArray.push(headData[j]);
190 temArray.push(projectData[j][k].score);
191 temArray.push(projectData[j][k].project);
192 temArray.push(headData[j]);
196 if (projectData[j][k].status == "platinium") {
197 temArray.push("primary");
199 } else if (projectData[j][k].status == "gold") {
200 temArray.push("danger");
202 } else if (projectData[j][k].status == "silver") {
203 temArray.push("warning");
205 } else if (projectData[j][k].status == null) {
206 temArray.push("null");
209 datadisplay.push(temArray);
215 colspan = projects.length / headData.length;
219 Installer: InstallerData,
220 projectData: projectData,
222 datadisplay: datadisplay,
224 status: scenarioStatus,
225 statusDisplay: scenarioStatusDisplay
228 JSON.stringify(tabledata);
229 $scope.tableDataAll.scenario.push(tabledata);
232 // console.log(tabledata);
237 projectsInfo = $scope.tableDataAll.scenario[0].projects;
239 var tempHeadData = [];
241 for (var i = 0; i < InstallerData.length; i++) {
242 for (var j = 0; j < colspan; j++) {
243 tempHeadData.push(InstallerData[i]);
247 //console.log(tempHeadData);
249 var projectsInfoAll = [];
251 for (var i = 0; i < projectsInfo.length; i++) {
253 tempA.push(projectsInfo[i]);
254 tempA.push(tempHeadData[i]);
255 projectsInfoAll.push(tempA);
258 //console.log(projectsInfoAll);
260 $scope.tableDataAll["colspan"] = colspan;
261 $scope.tableDataAll["Installer"] = InstallerData;
262 $scope.tableDataAll["Projects"] = projectsInfoAll;
264 // console.log($scope.tableDataAll);
265 $scope.colspan = $scope.tableDataAll.colspan;
266 console.log($scope.tableDataAll);
270 //get json element size
271 function getSize(jsondata) {
273 for (var item in jsondata) {
280 // console.log($scope.colspan);
283 //find all same element index
284 function getSameElementIndex(array, element) {
286 var idx = array.indexOf(element);
289 idx = array.indexOf(element, idx + 1);
292 var result = { element: element, index: indices };
293 JSON.stringify(result);
297 //delete element in array
298 function deletElement(array, index) {
299 array.splice(index, 1);
303 function radioSetting(array1, array2, array3) {
304 var tempVersion = [];
307 for (var i = 0; i < array1.length; i++) {
311 tempVersion.push(temp);
313 for (var i = 0; i < array2.length; i++) {
319 for (var i = 0; i < array3.length; i++) {
325 $scope.VersionOption = tempVersion;
326 $scope.LoopOption = tempLoop;
327 $scope.TimeOption = tempTime;
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) {
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);
349 function toggleSelection(status) {
350 var idx = $scope.selection.indexOf(status);
353 $scope.selection.splice(idx, 1);
354 filterData($scope.selection)
356 $scope.selection.push(status);
357 filterData($scope.selection)
359 // console.log($scope.selection);
364 function filterData(selection) {
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]);
373 if ($scope.projectListString.indexOf(selection[i]) > -1) {
374 $scope.selectProjects.push(selection[i]);
376 if ($scope.installerListString.indexOf(selection[i]) > -1) {
377 $scope.selectInstallers.push(selection[i]);
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;
388 if ($scope.selectProjects.length == 0) {
389 $scope.selectProjects = $scope.projectList;
390 $scope.colspan = $scope.tableDataAll.colspan;
392 $scope.colspan = $scope.selectProjects.length;
393 $scope.tempColspan = $scope.colspan;
395 if ($scope.selectStatus.length == 0) {
396 $scope.selectStatus = $scope.statusList
399 // console.log($scope.selectStatus);
400 // console.log($scope.selectProjects);