|
3 | 3 | sonarADFWidget. |
4 | 4 | controller('sonarIssueCtrl', sonarIssueCtrl); |
5 | 5 |
|
6 | | -function sonarIssueCtrl(data) { |
| 6 | +function sonarIssueCtrl(data, config) { |
7 | 7 | var vm = this; |
8 | 8 |
|
| 9 | + if (data.length != 0) { |
9 | 10 |
|
10 | | - angular.forEach(data, function (issue) { |
11 | | - issue.subProject = issue.subProject.slice(issue.component.search(":") + 1).replace(":", " "); |
12 | | - issue.project = issue.project.slice(issue.component.search(":") + 1).replace(":", " "); //eig wird noch "parent" abgeschnitten, aber keine Ahnung warum! |
13 | | - issue.component = issue.component.slice(issue.component.lastIndexOf(":") + 1); |
14 | | - |
15 | | - issue.status = issue.status.toLowerCase(); |
16 | | - issue.severity = issue.severity.toLowerCase(); |
17 | | - issue.type = issue.type.toLowerCase().replace("_", " "); |
18 | | - |
19 | | - for(var i=0; i<issue.tags.length; i++){ |
20 | | - if(i==0) |
21 | | - issue.tag= issue.tags[i]; |
22 | | - else { |
23 | | - issue.tag = issue.tag + ", "; |
24 | | - issue.tag = issue.tag + issue.tags[i]; |
25 | | - } |
| 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 | + } |
26 | 68 | } |
27 | | - }); |
28 | | - |
29 | | - // sorting the elements by project, subProject and component |
30 | | - // has the structure: projects [project, subProject, component, projectIssues] |
31 | | - vm.projects = new Array(); |
32 | | - vm.projects[0] = new Object(); |
33 | | - vm.projects[0].project = data[0].project; |
34 | | - vm.projects[0].subProject = data[0].subProject; |
35 | | - vm.projects[0].component = data[0].component; |
36 | | - vm.projects[0].projectIssue = new Array(); |
37 | | - vm.projects[0].projectIssue[0] = data[0]; |
38 | | - |
39 | | - var counter = 0; //counting the projects |
40 | | - var counter2 = 1; //counting the projectIssues per project |
41 | | - for (var i = 1; i < data.length; i++) { |
42 | | - if (data[i].project == vm.projects[counter].project |
43 | | - && data[i].subProject == vm.projects[counter].subProject |
44 | | - && data[i].component == vm.projects[counter].component) { |
45 | | - vm.projects[counter].projectIssue[counter2] = data[i]; |
46 | | - counter2 = counter2 + 1; |
47 | | - } else { |
48 | | - counter = counter + 1; |
49 | | - counter2 = 1; |
50 | | - vm.projects[counter] = new Object(); |
51 | | - vm.projects[counter].project = data[i].project; |
52 | | - vm.projects[counter].subProject = data[i].subProject; |
53 | | - vm.projects[counter].component = data[i].component; |
54 | | - vm.projects[counter].projectIssue = new Array; |
55 | | - vm.projects[counter].projectIssue[0] = data[i]; |
| 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; |
56 | 90 | } |
| 91 | + return -severity; |
| 92 | + }; |
57 | 93 |
|
58 | | - } |
59 | | - |
60 | | - |
61 | | - console.log(vm); |
| 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 | + }; |
62 | 102 | } |
0 commit comments