From f1a4e314f167782aee1dfff803290eab7745c9ca Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Mon, 21 Aug 2017 08:51:05 +0000 Subject: Landing page adoption Since testapi have done some changes on scenarios api, so landing page should do some adoption. Change-Id: Ib5d1df03e2c50c7d6c038200d97f2057b90e48af Signed-off-by: chenjiankun --- .../app/scripts/controllers/table.controller.js | 504 ++++++++------------- 1 file changed, 188 insertions(+), 316 deletions(-) (limited to 'utils/test/reporting/pages/app/scripts/controllers') diff --git a/utils/test/reporting/pages/app/scripts/controllers/table.controller.js b/utils/test/reporting/pages/app/scripts/controllers/table.controller.js index 44d9441de..8d494c3ae 100644 --- a/utils/test/reporting/pages/app/scripts/controllers/table.controller.js +++ b/utils/test/reporting/pages/app/scripts/controllers/table.controller.js @@ -11,396 +11,268 @@ angular.module('opnfvApp') .controller('TableController', ['$scope', '$state', '$stateParams', '$http', 'TableFactory', '$timeout', function($scope, $state, $stateParams, $http, TableFactory, $timeout) { - $scope.filterlist = []; - $scope.selection = []; - $scope.statusList = []; - $scope.projectList = []; - $scope.installerList = []; - $scope.versionlist = []; - $scope.loopci = []; - $scope.time = []; - $scope.tableDataAll = {}; - $scope.tableInfoAll = {}; - $scope.scenario = {}; - // $scope.selectProjects = []; - - - $scope.VersionConfig = { - create: true, - valueField: 'title', - labelField: 'title', - delimiter: '|', - maxItems: 1, - placeholder: 'Version', - onChange: function(value) { - checkElementArrayValue($scope.selection, $scope.VersionOption); - $scope.selection.push(value); - // console.log($scope.selection); - getScenarioData(); + init(); - } - } + function init() { + $scope.filterlist = []; + $scope.selection = []; - $scope.LoopConfig = { - create: true, - valueField: 'title', - labelField: 'title', - delimiter: '|', - maxItems: 1, - placeholder: 'Loop', - onChange: function(value) { - checkElementArrayValue($scope.selection, $scope.LoopOption); - $scope.selection.push(value); - // console.log($scope.selection); - getScenarioData(); + $scope.statusList = []; + $scope.projectList = []; + $scope.installerList = []; + $scope.versionlist = []; + $scope.loopList = []; + $scope.timeList = []; - } - } + $scope.selectStatus = []; + $scope.selectProjects = []; + $scope.selectInstallers = []; + $scope.selectVersion = null; + $scope.selectLoop = null; + $scope.selectTime = null; + + $scope.statusClicked = false; + $scope.installerClicked = false; + $scope.projectClicked = false; - $scope.TimeConfig = { - create: true, - valueField: 'title', - labelField: 'title', - delimiter: '|', - maxItems: 1, - placeholder: 'Time', - onChange: function(value) { - checkElementArrayValue($scope.selection, $scope.TimeOption); - $scope.selection.push(value); - // console.log($scope.selection) - getScenarioData(); + $scope.scenarios = {}; + $scope.VersionConfig = { + create: true, + valueField: 'title', + labelField: 'title', + delimiter: '|', + maxItems: 1, + placeholder: 'Version', + onChange: function(value) { + $scope.selectVersion = value; + getScenarioData(); + + } } - } + $scope.LoopConfig = { + create: true, + valueField: 'title', + labelField: 'title', + delimiter: '|', + maxItems: 1, + placeholder: 'Loop', + onChange: function(value) { + $scope.selectLoop = value; - init(); + getScenarioData(); + + } + } + + $scope.TimeConfig = { + create: true, + valueField: 'title', + labelField: 'title', + delimiter: '|', + maxItems: 1, + placeholder: 'Time', + onChange: function(value) { + $scope.selectTime = value; + + getScenarioData(); + } + } - function init() { - $scope.toggleSelection = toggleSelection; - getScenarioData(); getFilters(); } function getFilters() { TableFactory.getFilter().get({ - }).$promise.then(function(response) { if (response != null) { $scope.statusList = response.filters.status; $scope.projectList = response.filters.projects; $scope.installerList = response.filters.installers; - $scope.versionlist = response.filters.version; - $scope.loopci = response.filters.loops; - $scope.time = response.filters.time; - - $scope.statusListString = $scope.statusList.toString(); - $scope.projectListString = $scope.projectList.toString(); - $scope.installerListString = $scope.installerList.toString(); - $scope.VersionSelected = $scope.versionlist[1]; - $scope.LoopCiSelected = $scope.loopci[0]; - $scope.TimeSelected = $scope.time[0]; - radioSetting($scope.versionlist, $scope.loopci, $scope.time); + $scope.versionList = toSelectList(response.filters.version); + $scope.loopList = toSelectList(response.filters.loops); + $scope.timeList = toSelectList(response.filters.time); + + $scope.selectStatus = copy($scope.statusList); + $scope.selectInstallers = copy($scope.installerList); + $scope.selectProjects = copy($scope.projectList); + $scope.selectVersion = response.filters.version[0]; + $scope.selectLoop = response.filters.loops[0]; + $scope.selectTime = response.filters.time[0]; + + getScenarioData(); } else { - alert("网络错误"); } - }) + }); + } + + function toSelectList(arr){ + var tempList = []; + angular.forEach(arr, function(ele){ + tempList.push({'title': ele}); + }); + return tempList; + } + + function copy(arr){ + var tempList = []; + angular.forEach(arr, function(ele){ + tempList.push(ele); + }); + return tempList; } function getScenarioData() { - // var utl = BASE_URL + '/scenarios'; var data = { - 'status': ['success', 'danger', 'warning'], - 'projects': ['functest', 'yardstick'], - 'installers': ['apex', 'compass', 'fuel', 'joid'], - 'version': $scope.VersionSelected, - 'loops': $scope.LoopCiSelected, - 'time': $scope.TimeSelected + 'status': $scope.selectStatus, + 'projects': $scope.selectProjects, + 'installers': $scope.selectInstallers, + 'version': $scope.selectVersion, + 'loops': $scope.selectLoop, + 'time': $scope.selectTime }; TableFactory.getScenario(data).then(function(response) { if (response.status == 200) { - $scope.scenario = response.data; - - reSettingcolspan(); + $scope.scenarios = response.data.scenarios; + getScenario(); } }, function(error) { - - }) + }); } - function reSettingcolspan() { - if ($scope.selectProjects == undefined || $scope.selectProjects == null) { - constructJson(); - $scope.colspan = $scope.tableDataAll.colspan; + function getScenario(){ - } else { - constructJson(); - $scope.colspan = $scope.tempColspan; - } - // console.log("test") - } - - //construct json - function constructJson(selectProject) { + $scope.project_row = []; + angular.forEach($scope.selectInstallers, function(installer){ + angular.forEach($scope.selectProjects, function(project){ + var temp = { + 'installer': installer, + 'project': project + } + $scope.project_row.push(temp); - var colspan; - var InstallerData; - var projectsInfo; - $scope.tableDataAll["scenario"] = []; + }); + }); - for (var item in $scope.scenario.scenarios) { + $scope.scenario_rows = []; + angular.forEach($scope.scenarios, function(scenario, name){ + var scenario_row = { + 'name': null, + 'status': null, + 'statusDisplay': null, + 'datadisplay': [], + }; + scenario_row.name = name; + scenario_row.status = scenario.status; - var headData = Object.keys($scope.scenario.scenarios[item].installers).sort(); - var scenarioStatus = $scope.scenario.scenarios[item].status; var scenarioStatusDisplay; - if (scenarioStatus == "success") { + if (scenario.status == "success") { scenarioStatusDisplay = "navy"; - } else if (scenarioStatus == "danger") { + } else if (scenario.status == "danger") { scenarioStatusDisplay = "danger"; - } else if (scenarioStatus == "warning") { + } else if (scenario.status == "warning") { scenarioStatusDisplay = "warning"; } - - InstallerData = headData; - var projectData = []; - var datadisplay = []; - var projects = []; - - for (var j = 0; j < headData.length; j++) { - - projectData.push($scope.scenario.scenarios[item].installers[headData[j]]); - } - for (var j = 0; j < projectData.length; j++) { - - for (var k = 0; k < projectData[j].length; k++) { - projects.push(projectData[j][k].project); - var temArray = []; - if (projectData[j][k].score == null) { - temArray.push("null"); - temArray.push(projectData[j][k].project); - temArray.push(headData[j]); - } else { - temArray.push(projectData[j][k].score); - temArray.push(projectData[j][k].project); - temArray.push(headData[j]); - } - - - if (projectData[j][k].status == "platinium") { - temArray.push("primary"); - temArray.push("P"); - } else if (projectData[j][k].status == "gold") { - temArray.push("danger"); - temArray.push("G"); - } else if (projectData[j][k].status == "silver") { - temArray.push("warning"); - temArray.push("S"); - } else if (projectData[j][k].status == null) { - temArray.push("null"); + scenario_row.statusDisplay = scenarioStatusDisplay; + + angular.forEach($scope.selectInstallers, function(installer){ + angular.forEach($scope.selectProjects, function(project){ + var datadisplay = { + 'installer': null, + 'project': null, + 'value': null, + 'label': null, + 'label_value': null + }; + datadisplay.installer = installer; + datadisplay.project = project; + datadisplay.value = scenario.installers[installer][project].score; + + var single_status = scenario.installers[installer][project].status; + if (single_status == "platinium") { + datadisplay.label = 'primary'; + datadisplay.label_value = 'P'; + } else if (single_status == "gold") { + datadisplay.label = 'danger'; + datadisplay.label_value = 'G'; + } else if (single_status == "silver") { + datadisplay.label = 'warning'; + datadisplay.label_value = 'S'; + } else if (single_status == null) { } + scenario_row.datadisplay.push(datadisplay); - datadisplay.push(temArray); - - } - - } - - colspan = projects.length / headData.length; - - var tabledata = { - scenarioName: item, - Installer: InstallerData, - projectData: projectData, - projects: projects, - datadisplay: datadisplay, - colspan: colspan, - status: scenarioStatus, - statusDisplay: scenarioStatusDisplay - }; - - JSON.stringify(tabledata); - $scope.tableDataAll.scenario.push(tabledata); - - - // console.log(tabledata); - - } - - - projectsInfo = $scope.tableDataAll.scenario[0].projects; - - var tempHeadData = []; - - for (var i = 0; i < InstallerData.length; i++) { - for (var j = 0; j < colspan; j++) { - tempHeadData.push(InstallerData[i]); - } - } - - //console.log(tempHeadData); - - var projectsInfoAll = []; - - for (var i = 0; i < projectsInfo.length; i++) { - var tempA = []; - tempA.push(projectsInfo[i]); - tempA.push(tempHeadData[i]); - projectsInfoAll.push(tempA); - - } - //console.log(projectsInfoAll); - - $scope.tableDataAll["colspan"] = colspan; - $scope.tableDataAll["Installer"] = InstallerData; - $scope.tableDataAll["Projects"] = projectsInfoAll; - - // console.log($scope.tableDataAll); - $scope.colspan = $scope.tableDataAll.colspan; - console.log($scope.tableDataAll); - - } - - //get json element size - function getSize(jsondata) { - var size = 0; - for (var item in jsondata) { - size++; - } - return size; + }); + }); + $scope.scenario_rows.push(scenario_row); + }); } - // console.log($scope.colspan); - - - //find all same element index - function getSameElementIndex(array, element) { - var indices = []; - var idx = array.indexOf(element); - while (idx != -1) { - indices.push(idx); - idx = array.indexOf(element, idx + 1); + function clickBase(eleList, ele){ + var idx = eleList.indexOf(ele); + if(idx > -1){ + eleList.splice(idx, 1); + }else{ + eleList.push(ele); } - //return indices; - var result = { element: element, index: indices }; - JSON.stringify(result); - return result; } - //delete element in array - function deletElement(array, index) { - array.splice(index, 1); + $scope.clickStatus = function(status){ + if($scope.selectStatus.length == $scope.statusList.length && $scope.statusClicked == false){ + $scope.selectStatus = []; + $scope.statusClicked = true; + } - } + clickBase($scope.selectStatus, status); - function radioSetting(array1, array2, array3) { - var tempVersion = []; - var tempLoop = []; - var tempTime = []; - for (var i = 0; i < array1.length; i++) { - var temp = { - title: array1[i] - }; - tempVersion.push(temp); - } - for (var i = 0; i < array2.length; i++) { - var temp = { - title: array2[i] - }; - tempLoop.push(temp); + if($scope.selectStatus.length == 0 && $scope.statusClicked == true){ + $scope.selectStatus = copy($scope.statusList); + $scope.statusClicked = false; } - for (var i = 0; i < array3.length; i++) { - var temp = { - title: array3[i] - }; - tempTime.push(temp); - } - $scope.VersionOption = tempVersion; - $scope.LoopOption = tempLoop; - $scope.TimeOption = tempTime; - } - //remove element in the array - function removeArrayValue(arr, value) { - for (var i = 0; i < arr.length; i++) { - if (arr[i] == value) { - arr.splice(i, 1); - break; - } - } + getScenarioData(); } - //check if exist element - function checkElementArrayValue(arrayA, arrayB) { - for (var i = 0; i < arrayB.length; i++) { - if (arrayA.indexOf(arrayB[i].title) > -1) { - removeArrayValue(arrayA, arrayB[i].title); - } + $scope.clickInstaller = function(installer){ + if($scope.selectInstallers.length == $scope.installerList.length && $scope.installerClicked == false){ + $scope.selectInstallers = []; + $scope.installerClicked = true; } - } - function toggleSelection(status) { - var idx = $scope.selection.indexOf(status); + clickBase($scope.selectInstallers, installer); - if (idx > -1) { - $scope.selection.splice(idx, 1); - filterData($scope.selection) - } else { - $scope.selection.push(status); - filterData($scope.selection) + if($scope.selectInstallers.length == 0 && $scope.installerClicked == true){ + $scope.selectInstallers = copy($scope.installerList); + $scope.installerClicked = false; } - // console.log($scope.selection); + getScenarioData(); } - //filter function - function filterData(selection) { - - $scope.selectInstallers = []; - $scope.selectProjects = []; - $scope.selectStatus = []; - for (var i = 0; i < selection.length; i++) { - if ($scope.statusListString.indexOf(selection[i]) > -1) { - $scope.selectStatus.push(selection[i]); - } - if ($scope.projectListString.indexOf(selection[i]) > -1) { - $scope.selectProjects.push(selection[i]); - } - if ($scope.installerListString.indexOf(selection[i]) > -1) { - $scope.selectInstallers.push(selection[i]); - } + $scope.clickProject = function(project){ + if($scope.selectProjects.length == $scope.projectList.length && $scope.projectClicked == false){ + $scope.selectProjects = []; + $scope.projectClicked = true; } + clickBase($scope.selectProjects, project); - // $scope.colspan = $scope.selectProjects.length; - //when some selection is empty, we set it full - if ($scope.selectInstallers.length == 0) { - $scope.selectInstallers = $scope.installerList; - - } - if ($scope.selectProjects.length == 0) { - $scope.selectProjects = $scope.projectList; - $scope.colspan = $scope.tableDataAll.colspan; - } else { - $scope.colspan = $scope.selectProjects.length; - $scope.tempColspan = $scope.colspan; - } - if ($scope.selectStatus.length == 0) { - $scope.selectStatus = $scope.statusList + if($scope.selectProjects.length == 0 && $scope.projectClicked == true){ + $scope.selectProjects = copy($scope.projectList); + $scope.projectClicked = false; } - // console.log($scope.selectStatus); - // console.log($scope.selectProjects); - + getScenarioData(); } - } - ]); \ No newline at end of file + ]); -- cgit 1.2.3-korg