From 5aad37958e2ab2bcff3b98a3cbd943598503f9f0 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 31 Oct 2011 18:59:29 +0100 Subject: [PATCH] Improve rendering of duplications tab and add support for IE6 --- .../app/controllers/resource_controller.rb | 2 +- .../app/views/resource/_duplications.html.erb | 118 ++++++++---------- .../_duplications_source_snippet.html.erb | 46 ++++--- .../main/webapp/javascripts/duplications.js | 29 ++--- .../src/main/webapp/stylesheets/style.css | 57 +++++---- 5 files changed, 124 insertions(+), 128 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 339c1dd4daa..339b8a0854b 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 @@ -61,7 +61,7 @@ class ResourceController < ApplicationController 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} + :group_index => params[:group_index], :external => (resource.root_id != original_resource.root_id)} else access_denied end 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 a7233f8b48e..7a37dca2c0d 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 @@ -4,7 +4,7 @@ <% else %> - +
@@ -12,85 +12,75 @@ - - + - <% + <% @duplication_groups.each_with_index do |group, group_index| - group_size = group.size() - row_style = cycle 'even','odd', :name => ('duplications') %> - - - - + + - <% - group.each_with_index do |dup, index| - resource = dup[:resource] - external = resource.root_id != @resource.root_id - lines_count = dup[:lines_count].to_i - from_line = dup[:from_line].to_i - to_line = from_line + (lines_count > 5 ? 5 : lines_count) - group_class = "group#{group_index}" - group_row_class = "row#{group_index}-#{index}" - source_div = "source-#{group_index}" - update_snippet_script = "updateDuplicationLines('#{url_for :action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => @resource.id, :from_line => from_line, :lines_count => lines_count, :source_div => source_div}}','#{group_class}', '#{group_row_class}', '#{source_div}', #{lines_count}, #{from_line}, #{to_line});" - %> - - + - + + - - - <% if index==0 %> - - <% end %> - - <% - end - %> - - - - + + + + <% - end + end %> -
<%= message('duplications.blocks') -%><%= message('duplications.from_line') -%> <%= message('duplications.file') -%> <%= message('duplications.details') -%>
-
<%= group_size -%> -
-
- <%= lines_count -%> -
+
+

<%= group.size() -%>

-
- <%= from_line -%> -
+ +
+ <% group.each_with_index do |dup, index| %> +

<%= dup[:lines_count].to_i -%>

+ <% end %> +
+ <% group.each_with_index do |dup, index| %> +

<%= dup[:from_line].to_i -%>

+ <% end %>
- <% if resource==@resource - cell_content = resource.name - else - cell_content = link_to_resource(resource, resource.name, {:line => from_line}) - end + + + <% group.each_with_index do |dup, index| + resource = dup[:resource] + external = resource.root_id != @resource.root_id + lines_count = dup[:lines_count].to_i + from_line = dup[:from_line].to_i + to_line = from_line + (lines_count > 5 ? 5 : lines_count) + lines_count = dup[:lines_count].to_i + update_snippet_script = "updateDuplicationLines('#{url_for :action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => @resource.id}}',#{group_index}, #{index}, #{lines_count}, #{from_line}, #{to_line});" %> -
- <%= cell_content -%> - <% if external %> - <%= image_tag "links/external.png" -%> - <% end %> -
+

+ <%= resource.name -%> + <%= image_tag "links/external.png" if external -%> +

+ <% end %> +
-
- <%= render :partial => 'duplications_source_snippet', :locals => {:resource => resource, :original_resource => @resource, :from_line => from_line, :to_line => to_line, :lines_count => lines_count, :source_div => source_div, :external => external} -%> + +
+ <% + duplication = group[0] + resource = duplication[:resource] + from_line = duplication[:from_line].to_i + lines_count = duplication[:lines_count].to_i + external = resource.root_id != @resource.root_id + to_line = from_line + (lines_count > 5 ? 5 : lines_count) + %> +
+ <%= render :partial => 'duplications_source_snippet', :locals => {:resource => resource, :original_resource => @resource, :from_line => from_line, :to_line => to_line, :lines_count => lines_count, :external => external, :group_index => group_index} -%>
+ + <% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications_source_snippet.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications_source_snippet.html.erb index 511cc1c1f3c..eb3d0cc4b89 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications_source_snippet.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications_source_snippet.html.erb @@ -1,22 +1,30 @@
-
- <% - if external - parent_project = resource.project + <% + if external + parent_project = resource.project %> - <%= link_to_resource(parent_project, parent_project.path_name, {:dashboard => true}) -%> - <%= image_tag "links/external.png" -%> -
- <% - end +

+ <%= qualifier_icon(parent_project) -%> + <%= link_to_resource(parent_project, parent_project.path_name, {:dashboard => true}) -%> +    + <%= qualifier_icon(resource) -%> + <%= link_to_resource(resource, resource.name(true), {:line => from_line}) -%> + +

+ <% + else %> - <%= resource.name(true) -%> -
- +

+ <%= qualifier_icon(resource) -%> + <%= link_to_resource(resource, resource.name(true), {:line => from_line}) -%> + +

+ <% end %> + <%= snapshot_source_to_html(resource.last_snapshot, {:line_range => (from_line)..(to_line)}) -%> <% if lines_count > 5 %> -
+

<% if to_line < from_line + lines_count link_text = message('duplications.expand') @@ -25,12 +33,12 @@ link_text = message('duplications.collapse') to_line = from_line + 5 end - %> + %> <%= link_to_remote link_text, - :url => {:action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => original_resource.id, :from_line => from_line, :to_line => to_line, :lines_count => lines_count, :source_div => source_div}}, - :update => source_div, - :before => "$('#{source_div}').addClassName('loading');", - :complete => "$('#{source_div}').removeClassName('loading');" -%> -

+ :url => {:action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => original_resource.id, :from_line => from_line, :to_line => to_line, :lines_count => lines_count, :group_index => group_index}}, + :update => "source-#{group_index}", + :before => "$('expanding-#{group_index}').addClassName('loading')" -%> + +

<% end %>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/javascripts/duplications.js b/sonar-server/src/main/webapp/javascripts/duplications.js index 642ca55f5d4..94f122f2fd7 100644 --- a/sonar-server/src/main/webapp/javascripts/duplications.js +++ b/sonar-server/src/main/webapp/javascripts/duplications.js @@ -1,25 +1,16 @@ // JS scripts used in the duplication tab of the resource viewer -function updateDuplicationLines(url, groupClass, groupRowClass, sourceDivId, linesCount, fromLine, toLine) { - // handle first the style of the selectable rows - divs = $$('.'+groupClass); - for ( i = 0; i < divs.size(); i++) { - divs[i].removeClassName('selected'); - } - divs = $$('.'+groupRowClass); - for ( i = 0; i < divs.size(); i++) { - divs[i].addClassName('selected'); - } - - // then show that a request is pending - $(sourceDivId).addClassName('loading'); - - // and send the Ajax request - if ($(sourceDivId).childElements()[0].hasClassName('expanded')) { - toLine = fromLine + linesCount; +function updateDuplicationLines(url, groupId, itemId, linesCount, fromLine, toLine) { + $$('#duplGroup_' + groupId + ' p.selected').invoke('removeClassName', 'selected'); + $('duplCount-' + groupId + '-' + itemId).addClassName('selected'); + $('duplFrom-' + groupId + '-' + itemId).addClassName('selected'); + $('duplName-' + groupId + '-' + itemId).addClassName('selected'); + $('duplLoading-' + groupId).addClassName('loading'); + + if ($('source-' + groupId).childElements()[0].hasClassName('expanded')) { + toLine = fromLine + linesCount; } - new Ajax.Updater(sourceDivId, url + "&to_line=" + toLine, {asynchronous:true, evalScripts:true, onComplete:function(request){$(sourceDivId).removeClassName('loading');}}); - + new Ajax.Updater('source-' + groupId, url + "&to_line=" + toLine + "&from_line=" + fromLine + "&lines_count=" + linesCount + "&group_index=" + groupId, {asynchronous:true, evalScripts:true}); return false; } \ No newline at end of file diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 598a30fc699..c7cf810ded2 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -724,6 +724,7 @@ ul.operations li img { border-top: 1px solid #DDD; border-bottom: 1px solid #DDD; margin: 0; + background-color: #FFF; } .sources2 td.lid { background-color: #ECECEC; @@ -928,40 +929,46 @@ span.rulename a:hover { /* DUPLICATIONS */ -#duplicationsTable > tbody > tr { - padding-top: 2px; +#duplications { + max-width: 100%; } - -#duplicationsTable td.group-item { - padding: 0px; - height: 1px; +#duplications td.item { + text-align: right; + vertical-align: top; + padding: 0; } - -#duplicationsTable td.group-item > div { - padding: 3px; - margin: 2px 0px; +#duplications td.item p { + padding: 3px 10px; } -#duplicationsTable td.group-item > div.selected { - background-color: #fff; - border: 1px solid #DDDDDD; +#duplications td.fileItem { + text-align: left; + vertical-align: top; + padding: 0; + white-space: nowrap; } - -#duplicationsTable td.source-snippet { - background-color: #ddd; - border: 1px solid #DDDDDD; - padding: 0px; +#duplications td.fileItem p { + padding: 3px 10px; } - -#duplicationsTable td.source-snippet > div { - padding: 2px; - background-color: #fff; +#duplications td.item p.selected, #duplications td.fileItem p.selected { + background-color: #EFEFEF; + border-top: 1px solid #DDD; + border-bottom: 1px solid #DDD; + padding: 3px 10px; } - -.clickable { - cursor: pointer; +#duplications td.fileItem p.selected a { + text-decoration: none; } +#duplications td.sourceItem { + padding: 0 10px; + background-color: #EFEFEF; + border: 1px solid #DDD; + border-left: none; +} +#duplications td.sourceItem p { + padding: 3px; +} /* REVIEWS */ -- 2.39.5