5 * @name opnfvdashBoardAngularApp.controller:TableController
8 * Controller of the opnfvdashBoardAngularApp
10 angular.module('opnfvApp')
11 .controller('TableController', ['$scope', '$state', '$stateParams', 'TableFactory', function ($scope, $state, $stateParams, TableFactory) {
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 = {};
29 "os-nosdn-kvm-noha": {
34 "project": "Deployment",
41 "project": "Functest",
46 "project": "Yardstick",
53 "project": "Deployment",
58 "project": "Functest",
63 "project": "Yardstick",
70 "project": "Deployment",
75 "project": "Functest",
80 "project": "Yardstick",
87 "project": "Deployment",
92 "project": "Functest",
97 "project": "Yardstick",
109 "project": "Deployment",
116 "project": "Functest",
121 "project": "Yardstick",
128 "project": "Deployment",
133 "project": "Functest",
138 "project": "Yardstick",
145 "project": "Deployment",
150 "project": "Functest",
155 "project": "Yardstick",
162 "project": "Deployment",
167 "project": "Functest",
172 "project": "Yardstick",
179 "os-nosdn-ovs-noha": {
184 "project": "Deployment",
191 "project": "Functest",
196 "project": "Yardstick",
203 "project": "Deployment",
208 "project": "Functest",
213 "project": "Yardstick",
220 "project": "Deployment",
225 "project": "Functest",
230 "project": "Yardstick",
237 "project": "Deployment",
242 "project": "Functest",
247 "project": "Yardstick",
257 // var headData = Object.keys($scope.scenario.scenarios.os_nosdn_kvm_noha.installers);
258 // $scope.headData = headData;
260 function constructJson() {
265 $scope.tableDataAll["scenario"] = [];
268 for (var item in $scope.scenario.scenarios) {
273 var headData = Object.keys($scope.scenario.scenarios[item].installers);
274 var scenarioStatus = $scope.scenario.scenarios[item].status;
277 InstallerData = headData;
278 var projectData = [];
279 var datadisplay = [];
283 for (var j = 0; j < headData.length; j++) {
285 projectData.push($scope.scenario.scenarios[item].installers[headData[j]]);
287 for (var j = 0; j < projectData.length; j++) {
289 for (var k = 0; k < projectData[j].length; k++) {
290 projects.push(projectData[j][k].project);
292 temArray.push(projectData[j][k].score);
293 temArray.push(projectData[j][k].project);
294 temArray.push(headData[j]);
295 datadisplay.push(temArray);
301 colspan = projects.length / headData.length;
304 scenarioName: item, Installer: InstallerData, projectData: projectData, projects: projects,
305 datadisplay: datadisplay, colspan: colspan, status: scenarioStatus
308 JSON.stringify(tabledata);
309 $scope.tableDataAll.scenario.push(tabledata);
314 projectsInfo = $scope.tableDataAll.scenario[0].projects;
316 var tempHeadData = [];
320 for (var i = 0; i < InstallerData.length; i++) {
321 for (var j = 0; j < colspan; j++) {
322 tempHeadData.push(InstallerData[i]);
326 console.log(tempHeadData);
328 var projectsInfoAll = [];
330 for (var i = 0; i < projectsInfo.length; i++) {
332 tempA.push(projectsInfo[i]);
333 tempA.push(tempHeadData[i]);
334 projectsInfoAll.push(tempA);
337 console.log(projectsInfoAll);
339 $scope.tableDataAll["colspan"] = colspan;
340 $scope.tableDataAll["Installer"] = InstallerData;
341 $scope.tableDataAll["Projects"] = projectsInfoAll;
343 console.log($scope.tableDataAll);
347 //get json element size
348 function getSize(jsondata) {
350 for (var item in jsondata) {
358 $scope.toggleSelection = toggleSelection;
364 // $scope.test=false;
366 var statusListString = $scope.statusList.toString();
367 var projectListString = $scope.projectList.toString();
368 var installerListString = $scope.installerList.toString();
371 $scope.colspan=$scope.tableDataAll.colspan;
373 function filterData() {
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]);
383 if (projectListString.indexOf($scope.selection[i]) > -1) {
384 $scope.selectProjects.push($scope.selection[i]);
386 if (installerListString.indexOf($scope.selection[i]) > -1) {
387 $scope.selectInstallers.push($scope.selection[i]);
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;
397 if($scope.selectProjects.length==0){
398 $scope.selectProjects=$scope.projectList;
399 $scope.colspan=$scope.tableDataAll.colspan;
401 if($scope.selectStatus.length==0){
402 $scope.selectStatus=$scope.statusList
407 //find all same element index
408 function getSameElementIndex(array, element) {
410 var idx = array.indexOf(element);
413 idx = array.indexOf(element, idx + 1);
416 var result = { element: element, index: indices };
417 JSON.stringify(result);
421 //delete element in array
422 function deletElement(array, index) {
423 array.splice(index, 1);
428 $scope.VersionOption = [
429 { title: 'Colorado' },
432 $scope.VersionConfig = {
438 placeholder: 'Version',
439 onChange: function (value) {
440 checkElementArrayValue($scope.selection, $scope.VersionOption);
441 $scope.selection.push(value);
442 // console.log($scope.selection);
448 $scope.LoopOption = [
453 $scope.LoopConfig = {
460 onChange: function (value) {
461 checkElementArrayValue($scope.selection, $scope.LoopOption);
462 $scope.selection.push(value);
463 // console.log($scope.selection);
468 $scope.TimeOption = [
469 { title: '10 days' },
472 $scope.TimeConfig = {
479 onChange: function (value) {
480 checkElementArrayValue($scope.selection, $scope.TimeOption);
481 $scope.selection.push(value);
482 // console.log($scope.selection)
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) {
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);
506 function toggleSelection(status) {
507 var idx = $scope.selection.indexOf(status);
510 $scope.selection.splice(idx, 1);
513 $scope.selection.push(status);
515 console.log($scope.selection);