diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-03-27 17:41:47 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-03-27 17:54:41 +0100 |
commit | acb6b765bdccda53a39d9c2562922f5ad854f1f6 (patch) | |
tree | 191a1c7d2eb4f6b35f62babeffa3b4406c68b18a | |
parent | 829d5b8d58690097727465868ddc5037b4397528 (diff) | |
download | sonarqube-acb6b765bdccda53a39d9c2562922f5ad854f1f6.tar.gz sonarqube-acb6b765bdccda53a39d9c2562922f5ad854f1f6.zip |
fix display of overlapping duplications
3 files changed, 63 insertions, 52 deletions
diff --git a/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs b/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs index 79947f601c6..c046f4889c9 100644 --- a/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs +++ b/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs @@ -1,42 +1,45 @@ <div class="bubble-popup-container"> - <div class="bubble-popup-title">{{t 'component_viewer.transition.duplication'}}</div> - {{#each duplications}} - <div class="bubble-popup-section"> - <div class="component-name"> - {{#notEqComponents file ../component}} - <div class="component-name-parent"> - <i class="icon-qualifier-trk"></i> <a href="{{dashboardUrl file.project}}">{{file.projectName}}</a> - </div> - {{#if file.subProjectName}} + {{#if inRemovedComponent}} + <div class="alert alert-warning spacer-bottom">{{t 'duplications.dups_found_on_deleted_resource'}}</div> + {{/if}} + {{#notEmpty duplications}} + <div class="bubble-popup-title">{{t 'component_viewer.transition.duplication'}}</div> + {{#each duplications}} + <div class="bubble-popup-section"> + <div class="component-name"> + {{#notEqComponents file ../component}} <div class="component-name-parent"> - <i class="icon-qualifier-trk"></i> <a - href="{{dashboardUrl file.subProject}}">{{file.subProjectName}}</a> + <i class="icon-qualifier-trk"></i> <a href="{{dashboardUrl file.project}}">{{file.projectName}}</a> + </div> + {{#if file.subProjectName}} + <div class="component-name-parent"> + <i class="icon-qualifier-trk"></i> <a + href="{{dashboardUrl file.subProject}}">{{file.subProjectName}}</a> + </div> + {{/if}} + {{/notEqComponents}} + + {{#notEq file.key ../component.key}} + <div class="component-name-path"> + <a class="link-action" data-key="{{file.key}}" title="{{file.name}}"> + <span>{{collapsedDirFromPath file.name}}</span><span + class="component-name-file">{{fileFromPath file.name}}</span> + </a> </div> - {{/if}} - {{/notEqComponents}} + {{/notEq}} - {{#notEq file.key ../component.key}} <div class="component-name-path"> - <a class="link-action" data-key="{{file.key}}" title="{{file.name}}"> - <span>{{collapsedDirFromPath file.name}}</span><span - class="component-name-file">{{fileFromPath file.name}}</span> - </a> + Lines: + {{#joinEach blocks ','}} + <a class="link-action" data-key="{{../file.key}}" data-line="{{from}}"> + {{from}} – {{sum from size -1}} + </a> + {{/joinEach}} </div> - {{/notEq}} - - <div class="component-name-path"> - Lines: - {{#joinEach blocks ','}} - <a class="link-action" data-key="{{../file.key}}" data-line="{{from}}"> - {{from}} – {{sum from size -1}} - </a> - {{/joinEach}} </div> </div> - </div> - {{else}} - {{t 'duplications.block_was_duplicated_by_a_deleted_resource'}} - {{/each}} + {{/each}} + {{/notEmpty}} </div> <div class="bubble-popup-arrow"></div> diff --git a/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js b/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js index a00749fcedc..9ebc88122dc 100644 --- a/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js +++ b/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js @@ -40,27 +40,25 @@ define([ }, serializeData: function () { - var duplications, files, groupedBlocks; - files = this.model.get('duplicationFiles'); - groupedBlocks = _.groupBy(this.collection.toJSON(), '_ref'); - duplications = _.map(groupedBlocks, function (blocks, fileRef) { - return { - blocks: blocks, - file: files[fileRef] - }; + var that = this, + files = this.model.get('duplicationFiles'), + groupedBlocks = _.groupBy(this.collection.toJSON(), '_ref'), + duplications = _.map(groupedBlocks, function (blocks, fileRef) { + return { + blocks: blocks, + file: files[fileRef] + }; + }); + duplications = _.sortBy(duplications, function (d) { + var a = d.file.projectName !== that.model.get('projectName'), + b = d.file.subProjectName !== that.model.get('subProjectName'), + c = d.file.key !== that.model.get('key'); + return '' + a + b + c; }); - duplications = _.sortBy(duplications, (function (_this) { - return function (d) { - var a, b, c; - a = d.file.projectName !== _this.model.get('projectName'); - b = d.file.subProjectName !== _this.model.get('subProjectName'); - c = d.file.key !== _this.model.get('key'); - return '' + a + b + c; - }; - })(this)); return { component: this.model.toJSON(), - duplications: duplications + duplications: duplications, + inRemovedComponent: this.options.inRemovedComponent }; } }); diff --git a/server/sonar-web/src/main/js/source-viewer/viewer.js b/server/sonar-web/src/main/js/source-viewer/viewer.js index 84f635b9ae9..9046b567eae 100644 --- a/server/sonar-web/src/main/js/source-viewer/viewer.js +++ b/server/sonar-web/src/main/js/source-viewer/viewer.js @@ -429,14 +429,24 @@ define([ this.clearTooltips(); var index = $(e.currentTarget).data('index'), line = $(e.currentTarget).data('line-number'), - blocks = this.model.get('duplications')[index - 1].blocks; + blocks = this.model.get('duplications')[index - 1].blocks, + inRemovedComponent = _.some(blocks, function (b) { + return b._ref == null; + }), + foundOne = false; blocks = _.filter(blocks, function (b) { - var outOfBounds = b.from > line || b.from + b.size < line; - return (b._ref !== '1') || (b._ref === '1' && outOfBounds); + var outOfBounds = b.from > line || b.from + b.size < line, + currentFile = b._ref === '1', + isOk = (b._ref != null) && (!currentFile || (currentFile && (outOfBounds || foundOne))); + if (b._ref === '1' && !outOfBounds) { + foundOne = true; + } + return isOk; }); var popup = new DuplicationPopupView({ triggerEl: $(e.currentTarget), model: this.model, + inRemovedComponent: inRemovedComponent, collection: new Backbone.Collection(blocks) }); popup.render(); |