]> source.dussan.org Git - sonarqube.git/commitdiff
fix display of overlapping duplications
authorStas Vilchik <vilchiks@gmail.com>
Fri, 27 Mar 2015 16:41:47 +0000 (17:41 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 27 Mar 2015 16:54:41 +0000 (17:54 +0100)
server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs
server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js
server/sonar-web/src/main/js/source-viewer/viewer.js

index 79947f601c6ee135bc9d72b4e0974bb52122ef66..c046f4889c96b881a5297e65c767ca2ea4dc13e4 100644 (file)
@@ -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>&nbsp;<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>&nbsp;<a
-                href="{{dashboardUrl file.subProject}}">{{file.subProjectName}}</a>
+              <i class="icon-qualifier-trk"></i>&nbsp;<a href="{{dashboardUrl file.project}}">{{file.projectName}}</a>
+            </div>
+            {{#if file.subProjectName}}
+              <div class="component-name-parent">
+                <i class="icon-qualifier-trk"></i>&nbsp;<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>
index a00749fcedcc4f9074676b56fbcd26c71e5f24a4..9ebc88122dc99d24f7b4576eb5e294171a6e4070 100644 (file)
@@ -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
       };
     }
   });
index 84f635b9ae9179536afb505e68275bb797bcbcc1..9046b567eae848d40284f51f176cb134c1d22e50 100644 (file)
@@ -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();