From acb6b765bdccda53a39d9c2562922f5ad854f1f6 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 27 Mar 2015 17:41:47 +0100 Subject: [PATCH] fix display of overlapping duplications --- .../source-viewer-duplication-popup.hbs | 65 ++++++++++--------- .../source-viewer/popups/duplication-popup.js | 34 +++++----- .../src/main/js/source-viewer/viewer.js | 16 ++++- 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 @@
-
{{t 'component_viewer.transition.duplication'}}
- {{#each duplications}} -
-
- {{#notEqComponents file ../component}} - - {{#if file.subProjectName}} + {{#if inRemovedComponent}} +
{{t 'duplications.dups_found_on_deleted_resource'}}
+ {{/if}} + {{#notEmpty duplications}} +
{{t 'component_viewer.transition.duplication'}}
+ {{#each duplications}} +
+
+ {{#notEqComponents file ../component}} + {{#if file.subProjectName}} + + {{/if}} + {{/notEqComponents}} + + {{#notEq file.key ../component.key}} + - {{/if}} - {{/notEqComponents}} + {{/notEq}} - {{#notEq file.key ../component.key}} - {{/notEq}} - -
- Lines: - {{#joinEach blocks ','}} - - {{from}} – {{sum from size -1}} - - {{/joinEach}}
-
- {{else}} - {{t 'duplications.block_was_duplicated_by_a_deleted_resource'}} - {{/each}} + {{/each}} + {{/notEmpty}}
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(); -- 2.39.5