|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +sonarADFWidget. |
| 4 | + controller('sonarIssueCtrl', sonarIssueCtrl); |
| 5 | + |
| 6 | +function sonarIssueCtrl(data, config) { |
| 7 | + var vm = this; |
| 8 | + |
| 9 | + if (data.length != 0) { |
| 10 | + |
| 11 | + angular.forEach(data, function (issue) { |
| 12 | + |
| 13 | + // Preparing displaying of issue components |
| 14 | + if (issue.subProject) |
| 15 | + issue.subProject = issue.subProject.slice(issue.component.search(":") + 1).replace(":", " "); |
| 16 | + if (issue.project) |
| 17 | + issue.project = issue.project.slice(issue.component.search(":") + 1).replace(":", " "); //eig wird noch "parent" abgeschnitten, aber keine Ahnung warum! |
| 18 | + if (issue.component) |
| 19 | + issue.component = issue.component.slice(issue.component.lastIndexOf(":") + 1); |
| 20 | + |
| 21 | + if (issue.type) |
| 22 | + issue.type = issue.type.replace("_", " "); |
| 23 | + |
| 24 | + for (var i = 0; i < issue.tags.length; i++) { |
| 25 | + if (i == 0) |
| 26 | + issue.tag = issue.tags[i]; |
| 27 | + else |
| 28 | + issue.tag = issue.tag + ", " + issue.tags[i]; |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + // sorting the elements by project, subProject and component |
| 33 | + // has the structure: projects [project, subProject, component, projectIssues[]] |
| 34 | + vm.projects = new Array(); |
| 35 | + vm.projects[0] = new Object(); |
| 36 | + |
| 37 | + var counter = 0; //counting the projects |
| 38 | + var counter2 = 1; //counting the projectIssues per project |
| 39 | + for (var i = 0; i < data.length; i++) { |
| 40 | + |
| 41 | + if (data[i].status !== "CLOSED") { |
| 42 | + |
| 43 | + if (!vm.projects[counter].project) { //first initialisation of an object |
| 44 | + vm.projects[counter] = new Object(); |
| 45 | + vm.projects[counter].project = data[i].project; |
| 46 | + vm.projects[counter].subProject = data[i].subProject; |
| 47 | + vm.projects[counter].component = data[i].component; |
| 48 | + vm.projects[counter].projectIssue = new Array(); |
| 49 | + vm.projects[counter].projectIssue[0] = data[i]; |
| 50 | + } else { //if there is already an object in vm.projects |
| 51 | + if (data[i].project === vm.projects[counter].project |
| 52 | + && data[i].subProject === vm.projects[counter].subProject |
| 53 | + && data[i].component === vm.projects[counter].component) { |
| 54 | + vm.projects[counter].projectIssue[counter2] = data[i]; |
| 55 | + counter2 = counter2 + 1; |
| 56 | + } else { |
| 57 | + counter = counter + 1; |
| 58 | + counter2 = 1; |
| 59 | + vm.projects[counter] = new Object(); |
| 60 | + vm.projects[counter].project = data[i].project; |
| 61 | + vm.projects[counter].subProject = data[i].subProject; |
| 62 | + vm.projects[counter].component = data[i].component; |
| 63 | + vm.projects[counter].projectIssue = new Array; |
| 64 | + vm.projects[counter].projectIssue[0] = data[i]; |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + vm.sorting = function (issue) { |
| 72 | + if (config.sorting == "sortBySeverity") |
| 73 | + return vm.sortBySeverity(issue); |
| 74 | + else |
| 75 | + return vm.sortByEffort(issue); |
| 76 | + }; |
| 77 | + |
| 78 | + |
| 79 | + vm.sortBySeverity = function (issue) { |
| 80 | + var severity = 0; //4=blocker, 3=critical, 2=major, 1=minor, 0=info |
| 81 | + for (var i = 0; i < issue.projectIssue.length; i++) { |
| 82 | + if (issue.projectIssue[i].severity === "BLOCKER") |
| 83 | + severity = 4; |
| 84 | + else if (issue.projectIssue[i].severity === "CRITICAL" && severity < 3) |
| 85 | + severity = 3; |
| 86 | + else if (issue.projectIssue[i].severity === "MAJOR" && severity < 2) |
| 87 | + severity = 2; |
| 88 | + else if (issue.projectIssue[i].severity === "MINOR" && severity < 1) |
| 89 | + severity = 1; |
| 90 | + } |
| 91 | + return -severity; |
| 92 | + }; |
| 93 | + |
| 94 | + vm.sortByEffort = function (issue) { |
| 95 | + var effort = 0; |
| 96 | + for (var i = 0; i < issue.projectIssue.length; i++) { |
| 97 | + if (issue.projectIssue[i].effort && effort < parseInt(issue.projectIssue[i].effort.slice(0, issue.projectIssue[i].effort.search("m")))) |
| 98 | + effort = parseInt(issue.projectIssue[i].effort.slice(0, issue.projectIssue[i].effort.search("m"))); |
| 99 | + } |
| 100 | + return -effort; |
| 101 | + }; |
| 102 | +} |
0 commit comments