summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-10-28 14:44:43 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-10-28 14:44:43 +0200
commit27e7a99f95dd41a337cd6338ca3393483b658cac (patch)
treeac4ddf996f7c20022bdcb2c499fed84087935819 /sonar-server
parentab3820aa87b7843fc524765c22a1409901721aa1 (diff)
downloadsonarqube-27e7a99f95dd41a337cd6338ca3393483b658cac.tar.gz
sonarqube-27e7a99f95dd41a337cd6338ca3393483b658cac.zip
SONAR-2733 Fix bug that highlights 2 rows at the same time
=> occurs if a duplication is found in the same file + improves code for better performances
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb16
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications.html.erb6
2 files changed, 15 insertions, 7 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
index 6261b8333fe..339c1dd4daa 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
@@ -189,22 +189,30 @@ class ResourceController < ApplicationController
duplications_data = @snapshot.measure('duplications_data');
# create duplication groups
+ resource_by_id = {}
@duplication_groups = []
if duplications_data && duplications_data.measure_data && duplications_data.measure_data.data
dups = Document.new duplications_data.measure_data.data.to_s
dups.elements.each("duplications/duplication") do |dup|
group = []
+ target_id = dup.attributes['target-resource']
+ target_resource = resource_by_id[target_id]
+ unless target_resource
+ # we use the resource_by_id map for optimization
+ target_resource = Project.by_key(target_id)
+ resource_by_id[target_id] = target_resource
+ end
group << {:lines_count => dup.attributes['lines'], :from_line => dup.attributes['start'], :resource => @resource}
- group << {:lines_count => dup.attributes['lines'], :from_line => dup.attributes['target-start'], :resource => Project.by_key(dup.attributes['target-resource'])}
+ group << {:lines_count => dup.attributes['lines'], :from_line => dup.attributes['target-start'], :resource => target_resource}
@duplication_groups << group
end
end
# And sort them
# TODO => still needs to be sorted with inner dups before outer dups in a single block (can test only when new table available)
- @duplication_groups.each do |group|
- group.sort! {|dup1, dup2| dup1[:from_line].to_i <=> dup2[:from_line].to_i}
- end
+# @duplication_groups.each do |group|
+# group.sort! {|dup1, dup2| dup1[:from_line].to_i <=> dup2[:from_line].to_i}
+# end
@duplication_groups.sort! {|group1, group2| group1[0][:from_line].to_i <=> group2[0][:from_line].to_i}
render :action => 'index', :layout => !request.xhr?
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications.html.erb
index e55fb2f9e9b..a7233f8b48e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications.html.erb
@@ -43,13 +43,13 @@
%>
<tr class="hoverable <%= row_style -%>">
<td class="center group-item">
- <div class="<%= group_class -%> <%= group_row_class -%> clickable <%= 'selected' if resource==@resource -%>"
+ <div class="<%= group_class -%> <%= group_row_class -%> clickable <%= 'selected' if index==0 -%>"
onclick="<%= update_snippet_script -%>" style="border-right-width: 0px; margin-left: 2px;">
<%= lines_count -%>
<div>
</td>
<td class="center group-item">
- <div class="<%= group_class -%> <%= group_row_class -%> clickable <%= 'selected' if resource==@resource -%>"
+ <div class="<%= group_class -%> <%= group_row_class -%> clickable <%= 'selected' if index==0 -%>"
onclick="<%= update_snippet_script -%>" style="border-right-width: 0px;border-left-width: 0px;">
<%= from_line -%>
</div>
@@ -61,7 +61,7 @@
cell_content = link_to_resource(resource, resource.name, {:line => from_line})
end
%>
- <div class="<%= group_class -%> <%= group_row_class -%> clickable nowrap <%= 'selected' if resource==@resource -%>"
+ <div class="<%= group_class -%> <%= group_row_class -%> clickable nowrap <%= 'selected' if index==0 -%>"
onclick="<%= update_snippet_script -%>" style="padding-right: 20px; border-right-width: 0px;border-left-width: 0px;">
<%= cell_content -%>
<% if external %>