From 6b374d017959b404355bfb5f18b45b2cac581a11 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Tue, 15 Sep 2015 11:14:22 +0200 Subject: [PATCH] SONAR-6747 Display the number of issues on a line in the component viewer --- .../common/handlebars-extensions.js | 8 + .../source-viewer/templates/source-viewer.hbs | 7 +- .../src/main/less/components/source.less | 9 ++ .../several-issues-on-a-line.json | 143 ++++++++++++++++++ .../test/medium/source-viewer.spec.js | 14 ++ 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 server/sonar-web/src/test/json/source-viewer-spec/several-issues-on-a-line.json diff --git a/server/sonar-web/src/main/js/components/common/handlebars-extensions.js b/server/sonar-web/src/main/js/components/common/handlebars-extensions.js index fd1a7ddb74f..6e5d8e03a74 100644 --- a/server/sonar-web/src/main/js/components/common/handlebars-extensions.js +++ b/server/sonar-web/src/main/js/components/common/handlebars-extensions.js @@ -586,4 +586,12 @@ return cond ? options.fn(this) : options.inverse(this); }); + Handlebars.registerHelper('length', function (array) { + return _.size(array); + }); + + Handlebars.registerHelper('ifLengthGT', function (array, len, options) { + return _.size(array) > len ? options.fn(this) : options.inverse(this); + }); + })(); diff --git a/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs b/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs index 4600706741e..172a55504a5 100644 --- a/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs +++ b/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs @@ -35,14 +35,14 @@ {{#if ../hasDuplications}} + {{#if duplicated}}title="{{t 'source_viewer.tooltip.duplicated_line'}}" data-placement="right" data-toggle="tooltip"{{/if}}>
{{#each duplications}} + {{#if this}}title="{{t 'source_viewer.tooltip.duplicated_block'}}" data-placement="right" data-toggle="tooltip"{{/if}}>
{{/each}} @@ -53,6 +53,9 @@ {{#withFirst issues}} {{severityIcon severity}} {{/withFirst}} + {{#ifLengthGT issues 1}} + {{length issues}} + {{/ifLengthGT}} diff --git a/server/sonar-web/src/main/less/components/source.less b/server/sonar-web/src/main/less/components/source.less index 8df7809d9df..8809c7faf50 100644 --- a/server/sonar-web/src/main/less/components/source.less +++ b/server/sonar-web/src/main/less/components/source.less @@ -170,10 +170,19 @@ } .source-line-issues { + position: relative; padding: 0 2px; background-color: @barBackgroundColor; } +.source-line-issues-counter { + position: absolute; + top: -1px; + right: -1px; + line-height: 8px; + font-size: 8px; +} + .source-line-coverage { background-color: @barBackgroundColor; } diff --git a/server/sonar-web/src/test/json/source-viewer-spec/several-issues-on-a-line.json b/server/sonar-web/src/test/json/source-viewer-spec/several-issues-on-a-line.json new file mode 100644 index 00000000000..e4230fb77da --- /dev/null +++ b/server/sonar-web/src/test/json/source-viewer-spec/several-issues-on-a-line.json @@ -0,0 +1,143 @@ +{ + "total": 3, + "p": 1, + "ps": 500, + "paging": { + "pageIndex": 1, + "pageSize": 500, + "total": 3 + }, + "issues": [ + { + "key": "00c52e57-1e71-4079-aee3-19004bc30899", + "rule": "c:S1764", + "severity": "CRITICAL", + "component": "com.sonarsource.samples:multiple-issue-locations:src/main/c/identical-expressions.c", + "componentId": 1875, + "project": "com.sonarsource.samples:multiple-issue-locations", + "subProject": "com.sonarsource.samples:multiple-issue-locations", + "line": 3, + "textRange": { + "startLine": 3, + "endLine": 3, + "startOffset": 24, + "endOffset": 29 + }, + "flows": [], + "status": "OPEN", + "message": "Identical sub-expressions on both sides of operator \"||\"", + "debt": "2min", + "author": "", + "tags": [ + "bug", + "cert" + ], + "transitions": [ + "confirm", + "resolve", + "falsepositive", + "wontfix" + ], + "actions": [ + "comment", + "assign", + "set_tags", + "assign_to_me", + "plan", + "set_severity" + ], + "comments": [], + "creationDate": "2015-08-12T14:10:00+0200", + "updateDate": "2015-08-12T14:10:00+0200" + }, + { + "key": "62f1a1f9-b2d0-4003-a774-81ad8668b7ff", + "rule": "c:S1764", + "severity": "CRITICAL", + "component": "com.sonarsource.samples:multiple-issue-locations:src/main/c/identical-expressions.c", + "componentId": 1875, + "project": "com.sonarsource.samples:multiple-issue-locations", + "subProject": "com.sonarsource.samples:multiple-issue-locations", + "line": 3, + "textRange": { + "startLine": 9, + "endLine": 9, + "startOffset": 6, + "endOffset": 10 + }, + "flows": [], + "status": "OPEN", + "message": "Identical sub-expressions on both sides of operator \"||\"", + "debt": "2min", + "author": "", + "tags": [ + "bug", + "cert" + ], + "transitions": [ + "confirm", + "resolve", + "falsepositive", + "wontfix" + ], + "actions": [ + "comment", + "assign", + "set_tags", + "assign_to_me", + "plan", + "set_severity" + ], + "comments": [], + "creationDate": "2015-08-12T14:10:00+0200", + "updateDate": "2015-08-12T14:10:00+0200" + }, + { + "key": "4ea2b024-fc40-4050-ba36-1083bb09561a", + "rule": "c:S1764", + "severity": "CRITICAL", + "component": "com.sonarsource.samples:multiple-issue-locations:src/main/c/identical-expressions.c", + "componentId": 1875, + "project": "com.sonarsource.samples:multiple-issue-locations", + "subProject": "com.sonarsource.samples:multiple-issue-locations", + "line": 5, + "textRange": { + "startLine": 18, + "endLine": 19, + "startOffset": 13, + "endOffset": 9 + }, + "flows": [], + "status": "OPEN", + "message": "Identical sub-expressions on both sides of operator \"||\"", + "debt": "2min", + "author": "", + "tags": [ + "bug", + "cert" + ], + "transitions": [ + "confirm", + "resolve", + "falsepositive", + "wontfix" + ], + "actions": [ + "comment", + "assign", + "set_tags", + "assign_to_me", + "plan", + "set_severity" + ], + "comments": [], + "creationDate": "2015-08-12T14:10:00+0200", + "updateDate": "2015-08-12T14:10:00+0200" + } + ], + "components": [], + "rules": [], + "users": [], + "actionPlans": [], + "languages": [] +} diff --git a/server/sonar-web/test/medium/source-viewer.spec.js b/server/sonar-web/test/medium/source-viewer.spec.js index 5872dc7c0fe..e318f7f19e8 100644 --- a/server/sonar-web/test/medium/source-viewer.spec.js +++ b/server/sonar-web/test/medium/source-viewer.spec.js @@ -68,6 +68,20 @@ define(function (require) { .checkElementInclude('.source-line-code[data-line-number="8"] .source-line-code-secondary-issue', 'ense ') .checkElementInclude('.source-line-code[data-line-number="9"] .source-line-code-secondary-issue', 'sion'); }); + + bdd.it('should show the number of issues on a line', function () { + return this.remote + .open() + .mockFromFile('/api/components/app', 'source-viewer-spec/app.json', { data: { uuid: 'uuid' } }) + .mockFromFile('/api/sources/lines', 'source-viewer-spec/lines.json', { data: { uuid: 'uuid' } }) + .mockFromFile('/api/issues/search', 'source-viewer-spec/several-issues-on-a-line.json') + .startApp('source-viewer', { file: file }) + .checkElementExist('.source-line-issues[data-line-number="3"] .icon-severity-critical') + .checkElementExist('.source-line-issues[data-line-number="3"] .source-line-issues-counter') + .checkElementInclude('.source-line-issues[data-line-number="3"] .source-line-issues-counter', 2) + .checkElementExist('.source-line-issues[data-line-number="5"] .icon-severity-critical') + .checkElementNotExist('.source-line-issues[data-line-number="5"] .source-line-issues-counter'); + }); }); }); }); -- 2.39.5