From a679de21723b04cbb6ed1e1b02bb1726125cc855 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Thu, 27 Oct 2011 17:51:55 +0200 Subject: SONAR-2733 Display duplicated blocks by group in the resource viewer Now waiting for the new table to feed the data that is displayed by this new duplication tab. --- .../main/resources/org/sonar/l10n/core.properties | 2 ++ sonar-server/pom.xml | 3 +- .../WEB-INF/app/controllers/resource_controller.rb | 17 ++++++++-- .../WEB-INF/app/helpers/application_helper.rb | 5 ++- .../WEB-INF/app/views/layouts/_head.html.erb | 1 + .../app/views/resource/_duplications.html.erb | 36 +++++++++++--------- .../resource/_duplications_source_snippet.html.erb | 38 ++++++++++++++++++++-- .../src/main/webapp/javascripts/duplications.js | 25 ++++++++++++++ sonar-server/src/main/webapp/stylesheets/style.css | 6 +++- 9 files changed, 110 insertions(+), 23 deletions(-) create mode 100644 sonar-server/src/main/webapp/javascripts/duplications.js diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index 33f4ff2e83e..c8b954cb92a 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -603,6 +603,8 @@ duplications.number_of_lines=Nb Lines duplications.from_line=From line duplications.file=File duplications.details=Details +duplications.expand=Expand +duplications.collapse=Collapse #------------------------------------------------------------------------------ diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index 2681bcd9229..e2ec8b14892 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -256,6 +256,7 @@ **/dashboard-min.js **/protovis-min.js **/protovis-sonar-min.js + **/duplications-min.js ${project.build.directory}/${project.build.finalName}/javascripts/sonar.js @@ -301,7 +302,7 @@ maven-war-plugin - **/*.log,*.iml,WEB-INF/script/,WEB-INF/test/,javascripts/application*.js,javascripts/prototype*.js,javascripts/scriptaculous*.js,javascripts/tablekit*.js,javascripts/tablekit*.js,javascripts/prototip*.js,javascripts/dashboard*.js,javascripts/protovis.js,javascripts/protovis-min.js + **/*.log,*.iml,WEB-INF/script/,WEB-INF/test/,javascripts/application*.js,javascripts/prototype*.js,javascripts/scriptaculous*.js,javascripts/tablekit*.js,javascripts/tablekit*.js,javascripts/prototip*.js,javascripts/dashboard*.js,javascripts/protovis.js,javascripts/protovis-min.js,javascripts/duplications.js,javascripts/duplications-min.js **/* 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 61c30b9aee9..6261b8333fe 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 @@ -56,9 +56,12 @@ class ResourceController < ApplicationController end def show_duplication_snippet - @resource = Project.by_key(params[:id]) - if (@resource && has_role?(:user, @resource)) - render :partial => 'duplications_source_snippet', :locals => {:resource => @resource, :from_line => params[:from_line].to_i, :to_line => params[:to_line].to_i} + resource = Project.by_key(params[:id]) + if (resource && has_role?(:user, resource)) + original_resource = Project.by_key(params[:original_resource_id]) + render :partial => 'duplications_source_snippet', + :locals => {:resource => resource, :original_resource => original_resource, :from_line => params[:from_line].to_i, :to_line => params[:to_line].to_i, :lines_count => params[:lines_count].to_i, + :source_div => params[:source_div], :external => resource.root_id != original_resource.root_id} else access_denied end @@ -185,6 +188,7 @@ class ResourceController < ApplicationController def render_duplications duplications_data = @snapshot.measure('duplications_data'); + # create duplication groups @duplication_groups = [] if duplications_data && duplications_data.measure_data && duplications_data.measure_data.data dups = Document.new duplications_data.measure_data.data.to_s @@ -196,6 +200,13 @@ class ResourceController < ApplicationController 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.sort! {|group1, group2| group1[0][:from_line].to_i <=> group2[0][:from_line].to_i} + render :action => 'index', :layout => !request.xhr? end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index 659920e9c2e..1745af879e9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -333,7 +333,10 @@ module ApplicationHelper link_to(name || resource.name, {:overwrite_params => {:id => (resource.copy_resource_id||resource.id), :period => period_index, :tab => options[:tab], :rule => options[:rule]}}, :title => options[:title]) end else - link_to(name || resource.name, {:controller => 'resource', :action => 'index', :id => resource.id, :period => period_index, :tab => options[:tab], :rule => options[:rule]}, :popup => ['resource', 'height=800,width=900,scrollbars=1,resizable=1'], :title => options[:title]) + if options[:line] + anchor= 'L' + options[:line].to_s + end + link_to(name || resource.name, {:controller => 'resource', :action => 'index', :anchor => anchor, :id => resource.id, :period => period_index, :tab => options[:tab], :rule => options[:rule]}, :popup => ['resource', 'height=800,width=900,scrollbars=1,resizable=1'], :title => options[:title]) end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb index 50ee96547cb..9aabe2e583a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb @@ -29,6 +29,7 @@ <%= javascript_include_tag 'dashboard' %> <%= javascript_include_tag 'protovis' %> <%= javascript_include_tag 'protovis-sonar' %> +<%= javascript_include_tag 'duplications' %> <% end %>