5 * @name opnfvdashBoardAngularApp.controller:TableController
8 * Controller of the opnfvdashBoardAngularApp
10 angular.module('opnfvApp')
11 .controller('TableController', ['$scope', '$state', '$stateParams', '$http', 'TableFactory', function($scope, $state, $stateParams, $http, TableFactory) {
13 $scope.filterlist = [];
14 $scope.selection = [];
15 $scope.statusList = [];
16 $scope.projectList = [];
17 $scope.installerList = [];
18 $scope.versionlist = [];
21 $scope.tableDataAll = {};
22 $scope.tableInfoAll = {};
25 $scope.VersionConfig = {
31 placeholder: 'Version',
32 onChange: function(value) {
33 checkElementArrayValue($scope.selection, $scope.VersionOption);
34 $scope.selection.push(value);
35 // console.log($scope.selection);
48 onChange: function(value) {
49 checkElementArrayValue($scope.selection, $scope.LoopOption);
50 $scope.selection.push(value);
51 // console.log($scope.selection);
64 onChange: function(value) {
65 checkElementArrayValue($scope.selection, $scope.TimeOption);
66 $scope.selection.push(value);
67 // console.log($scope.selection)
78 $scope.toggleSelection = toggleSelection;
84 function getFilters() {
85 TableFactory.getFilter().get({
88 }).$promise.then(function(response) {
89 if (response != null) {
90 $scope.statusList = response.filters.status;
91 $scope.projectList = response.filters.projects;
92 $scope.installerList = response.filters.installers;
93 $scope.versionlist = response.filters.version;
94 $scope.loopci = response.filters.loops;
95 $scope.time = response.filters.time;
97 $scope.statusListString = $scope.statusList.toString();
98 $scope.projectListString = $scope.projectList.toString();
99 $scope.installerListString = $scope.installerList.toString();
100 $scope.VersionSelected = $scope.versionlist[1];
101 $scope.LoopCiSelected = $scope.loopci[0];
102 $scope.TimeSelected = $scope.time[0];
103 radioSetting($scope.versionlist, $scope.loopci, $scope.time);
111 function getScenarioData() {
113 var utl = BASE_URL + '/scenarios';
115 'status': ['success', 'danger', 'warning'],
116 'projects': ['functest', 'yardstick'],
117 'installers': ['apex', 'compass', 'fuel', 'joid'],
118 'version': $scope.VersionSelected,
119 'loops': $scope.LoopCiSelected,
120 'time': $scope.TimeSelected
124 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
127 $http.post(utl, data, config).then(function(response) {
128 if (response.status == 200) {
129 $scope.scenario = response.data;
136 function constructJson() {
141 $scope.tableDataAll["scenario"] = [];
144 for (var item in $scope.scenario.scenarios) {
146 var headData = Object.keys($scope.scenario.scenarios[item].installers).sort();
147 var scenarioStatus = $scope.scenario.scenarios[item].status;
148 var scenarioStatusDisplay;
149 if (scenarioStatus == "success") {
150 scenarioStatusDisplay = "navy";
151 } else if (scenarioStatus == "danger") {
152 scenarioStatusDisplay = "danger";
153 } else if (scenarioStatus == "warning") {
154 scenarioStatusDisplay = "warning";
157 InstallerData = headData;
158 var projectData = [];
159 var datadisplay = [];
162 for (var j = 0; j < headData.length; j++) {
164 projectData.push($scope.scenario.scenarios[item].installers[headData[j]]);
166 for (var j = 0; j < projectData.length; j++) {
168 for (var k = 0; k < projectData[j].length; k++) {
169 projects.push(projectData[j][k].project);
171 if (projectData[j][k].score == null) {
172 temArray.push("null");
173 temArray.push(projectData[j][k].project);
174 temArray.push(headData[j]);
176 temArray.push(projectData[j][k].score);
177 temArray.push(projectData[j][k].project);
178 temArray.push(headData[j]);
182 if (projectData[j][k].status == "platinium") {
183 temArray.push("primary");
185 } else if (projectData[j][k].status == "gold") {
186 temArray.push("danger");
188 } else if (projectData[j][k].status == "silver") {
189 temArray.push("warning");
191 } else if (projectData[j][k].status == null) {
192 temArray.push("null");
195 datadisplay.push(temArray);
201 colspan = projects.length / headData.length;
205 Installer: InstallerData,
206 projectData: projectData,
208 datadisplay: datadisplay,
210 status: scenarioStatus,
211 statusDisplay: scenarioStatusDisplay
214 JSON.stringify(tabledata);
215 $scope.tableDataAll.scenario.push(tabledata);
217 // console.log(tabledata);
222 projectsInfo = $scope.tableDataAll.scenario[0].projects;
224 var tempHeadData = [];
226 for (var i = 0; i < InstallerData.length; i++) {
227 for (var j = 0; j < colspan; j++) {
228 tempHeadData.push(InstallerData[i]);
232 //console.log(tempHeadData);
234 var projectsInfoAll = [];
236 for (var i = 0; i < projectsInfo.length; i++) {
238 tempA.push(projectsInfo[i]);
239 tempA.push(tempHeadData[i]);
240 projectsInfoAll.push(tempA);
243 //console.log(projectsInfoAll);
245 $scope.tableDataAll["colspan"] = colspan;
246 $scope.tableDataAll["Installer"] = InstallerData;
247 $scope.tableDataAll["Projects"] = projectsInfoAll;
249 // console.log($scope.tableDataAll);
250 $scope.colspan = $scope.tableDataAll.colspan;
254 //get json element size
255 function getSize(jsondata) {
257 for (var item in jsondata) {
263 $scope.colspan = $scope.tableDataAll.colspan;
264 // console.log($scope.colspan);
267 //find all same element index
268 function getSameElementIndex(array, element) {
270 var idx = array.indexOf(element);
273 idx = array.indexOf(element, idx + 1);
276 var result = { element: element, index: indices };
277 JSON.stringify(result);
281 //delete element in array
282 function deletElement(array, index) {
283 array.splice(index, 1);
287 function radioSetting(array1, array2, array3) {
288 var tempVersion = [];
291 for (var i = 0; i < array1.length; i++) {
295 tempVersion.push(temp);
297 for (var i = 0; i < array2.length; i++) {
303 for (var i = 0; i < array3.length; i++) {
309 $scope.VersionOption = tempVersion;
310 $scope.LoopOption = tempLoop;
311 $scope.TimeOption = tempTime;
314 //remove element in the array
315 function removeArrayValue(arr, value) {
316 for (var i = 0; i < arr.length; i++) {
317 if (arr[i] == value) {
324 //check if exist element
325 function checkElementArrayValue(arrayA, arrayB) {
326 for (var i = 0; i < arrayB.length; i++) {
327 if (arrayA.indexOf(arrayB[i].title) > -1) {
328 removeArrayValue(arrayA, arrayB[i].title);
333 function toggleSelection(status) {
334 var idx = $scope.selection.indexOf(status);
337 $scope.selection.splice(idx, 1);
338 filterData($scope.selection)
340 $scope.selection.push(status);
341 filterData($scope.selection)
343 // console.log($scope.selection);
348 function filterData(selection) {
350 $scope.selectInstallers = [];
351 $scope.selectProjects = [];
352 $scope.selectStatus = [];
353 for (var i = 0; i < selection.length; i++) {
354 if ($scope.statusListString.indexOf(selection[i]) > -1) {
355 $scope.selectStatus.push(selection[i]);
357 if ($scope.projectListString.indexOf(selection[i]) > -1) {
358 $scope.selectProjects.push(selection[i]);
360 if ($scope.installerListString.indexOf(selection[i]) > -1) {
361 $scope.selectInstallers.push(selection[i]);
365 $scope.colspan = $scope.selectProjects.length;
366 //when some selection is empty, we set it full
367 if ($scope.selectInstallers.length == 0) {
368 $scope.selectInstallers = $scope.installerList;
371 if ($scope.selectProjects.length == 0) {
372 $scope.selectProjects = $scope.projectList;
373 $scope.colspan = $scope.tableDataAll.colspan;
375 if ($scope.selectStatus.length == 0) {
376 $scope.selectStatus = $scope.statusList
379 // console.log($scope.selectStatus);
380 // console.log($scope.selectProjects);