Skip to content

Commit 95e4769

Browse files
author
Maren Süwer
committed
Adding Widget My Issues
1 parent 50fddb0 commit 95e4769

File tree

4 files changed

+162
-2
lines changed

4 files changed

+162
-2
lines changed

src/issues/issue.controller.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
sonarADFWidget.
4+
controller('sonarIssueCtrl', sonarIssueCtrl);
5+
6+
function sonarIssueCtrl(data) {
7+
var vm = this;
8+
9+
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+
}
26+
}
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];
56+
}
57+
58+
}
59+
60+
61+
console.log(vm);
62+
}

src/issues/view.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<style type="text/css">
2+
.content{
3+
text-align: left;
4+
color: black;
5+
}
6+
.linesOfCode {
7+
background-color:#F0F0F0;
8+
margin-bottom: 0.5%;
9+
border-radius: 1px;
10+
}
11+
.heading {
12+
color: #1874CD;
13+
font-size: small;
14+
margin-top: 1%;
15+
}
16+
</style>
17+
18+
<div>
19+
<div ng-if="!vm.projects" class="alert alert-info">
20+
You don't have any issues.
21+
</div>
22+
23+
<div ng-repeat="project in vm.projects">
24+
<div class="heading">
25+
<span class="glyphicon glyphicon-folder-open"></span>
26+
{{project.project}}
27+
<span class="glyphicon glyphicon-folder-open"></span>
28+
{{project.subProject}}
29+
<span class="glyphicon glyphicon-file"></span>
30+
{{project.component}}</br>
31+
</div>
32+
<div class="content col-md-20">
33+
<div class="col-md-20 linesOfCode" ng-repeat="issue in project.projectIssue track by $index">
34+
35+
<table width="1000">
36+
<tr>
37+
<td width=80% colspan="4"><b>{{issue.message}}</b></td>
38+
<td ng-if="issue.line">L{{issue.line}}</td>
39+
</tr>
40+
<tr>
41+
<td>{{issue.type}}</td>
42+
<td>
43+
<span ng-if="issue.severity == 'major'" class="glyphicon glyphicon-chevron-up"></span>
44+
<span ng-if="issue.severity == 'minor'" class="glyphicon glyphicon-chevron-down"></span>
45+
<span ng-if="issue.severity == 'info'" class="glyphicon glyphicon-arrow-down"></span>
46+
<span ng-if="issue.severity == 'critical'" class="glyphicon glyphicon-arrow-up"></span>
47+
<span ng-if="issue.severity == 'blocker'" class="glyphicon glyphicon-exclamation-sign"></span>
48+
{{issue.severity}}
49+
</td>
50+
<td>{{issue.status}}</td>
51+
<td ng-if="issue.effort" width="200"><span class="glyphicon glyphicon-time"></span> {{issue.effort}} effort</td>
52+
<td ng-if="!issue.effort" width="200"></td>
53+
<td><span ng-if="issue.tag" class="glyphicon glyphicon-tags"></span> {{issue.tag}}</td>
54+
</tr>
55+
</table>
56+
</div>
57+
</div>
58+
</div>
59+
60+
</div>

src/service.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function sonarApi($http, $q) {
1313
function createApiUrlAllProjectsStatistics(sonarUrl) {
1414
return sonarUrl + '/api/resources?metrics=ncloc,coverage';
1515
}
16+
17+
function createApiUrlAllMyIssues(sonarUrl) {
18+
return sonarUrl + '/api/issues/search?assignees=pczora';//___me__'; //--> nur zum Testen, eigentlich ist es __me__!
19+
}
1620

1721
function createApiUrlMetrics(sonarUrl, projectname) {
1822
return sonarUrl + '/api/measures/component?componentKey=' + projectname + '&metricKeys=open_issues,ncloc,public_documented_api_density,duplicated_lines_density,sqale_index';
@@ -227,13 +231,28 @@ function sonarApi($http, $q) {
227231
return generateArray(projects);
228232
});
229233
}
234+
235+
function getAllMyIssues(sonarUrl){
236+
var apiUrl = createApiUrlAllMyIssues(sonarUrl);
237+
238+
return $http({
239+
method: 'GET',
240+
url: apiUrl,
241+
headers: {
242+
'Accept': 'application/json'
243+
}
244+
}).then(function(response) {
245+
return response.data.issues;
246+
});
247+
}
230248

231249
return {
232250
getProjects: getProjects,
233251
getAllProjectsStatistics: getAllProjectsStatistics,
234252
getChartData: getChartData,
235253
getMetrics: getMetrics,
236-
getProjectTime: getProjectTime
254+
getProjectTime: getProjectTime,
255+
getAllMyIssues: getAllMyIssues
237256
};
238257

239258
}

src/sonar.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//app initialisation with dependencies
33
var sonarADFWidget = angular.module('adf.widget.sonar', ['adf.provider', 'chart.js', 'ui.bootstrap', 'ui.bootstrap.datepicker','angular-svg-round-progressbar'])
44
.constant("sonarEndpoint", {
5-
"url": "https://sonarqube.com"
5+
"url": "https://ecosystem.cloudogu.com/sonar"//https://sonarqube.com"
66
}).constant("METRIC_NAMES", {"open_issues":"Open Issues","ncloc":"Lines of Code",
77
"public_documented_api_density": "Public documented API density","duplicated_lines_density": "Duplicated Lines (%)",
88
"sqale_index":"SQALE index", "coverage": "Coverage (%)", "tests": "Tests" })
@@ -111,6 +111,25 @@ var sonarADFWidget = angular.module('adf.widget.sonar', ['adf.provider', 'chart.
111111
edit: {
112112
templateUrl: '{widgetsPath}/sonar/src/project-progress/edit.html'
113113
}
114+
})
115+
.widget('sonar-my-issues', {
116+
title: 'Sonar: My Issues',
117+
description: 'Displays all issues of yourself',
118+
templateUrl: '{widgetsPath}/sonar/src/issues/view.html',
119+
resolve: {
120+
data: function(sonarApi, config, sonarEndpoint) {
121+
if (config.apiUrl) {
122+
return sonarApi.getAllMyIssues(config.apiUrl);
123+
}
124+
else if (sonarEndpoint.url){
125+
return sonarApi.getAllMyIssues(sonarEndpoint.url);
126+
}
127+
return 'Error'; //hier noch vernuenftige Fehlermeldung!
128+
}
129+
},
130+
category: 'SonarQube',
131+
controller: 'sonarIssueCtrl',
132+
controllerAs: 'vm'
114133
});
115134

116135
});

0 commit comments

Comments
 (0)