From: Jean-Baptiste Vilain Date: Mon, 22 Apr 2013 09:19:21 +0000 (+0200) Subject: SONAR-3893 Introduced unique partial for source display X-Git-Tag: 3.6~608 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0529e50d73518b10a9e042967d9fb5ca14fd0f8f;p=sonarqube.git SONAR-3893 Introduced unique partial for source display --- 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 716d387f35e..8cce4f6448b 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 @@ -787,4 +787,56 @@ module ApplicationHelper html end + + def prepare_colspans(display_violation_form, scm_available, display_coverage) + + colspan=2 + gray_colspan=1 + white_colspan=0 + if display_violation_form + colspan+=1 + gray_colspan+=1 + end + if scm_available + colspan+=1 + gray_colspan+=1 + end + if display_coverage + colspan+=2 + white_colspan+=2 + end + + {:base => colspan, :gray => gray_colspan, :white => white_colspan} + end + + + def compute_statuses(line, display_coverage, display_violations) + + status=hits_status=conditions_status='' + + if line.highlighted? + if display_coverage && line.hits + hits_status=(line.hits>0 ? 'ok' : 'ko') + if line.conditions && line.conditions>0 && line.covered_conditions + if line.covered_conditions==0 + status='ko' + conditions_status='ko' + elsif line.covered_conditions==line.conditions + status='' + conditions_status='ok' + else + conditions_status='warn' + status='warn' + end + elsif line.hits + status=(line.hits>0 ? '' : 'ko') + end + elsif display_violations && line.violations? + status="ko" + end + end + + {:base => status, :hits => hits_status, :conditions => conditions_status} + end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb index bebaa63d462..d0b5a57c2d5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb @@ -59,8 +59,22 @@ module SourceHelper end panel.filter_min_date(options[:min_date]) if options[:min_date] - - render :partial => 'source/source', :locals => {:panel => panel} + + unless panel.empty? + + render :partial => "shared/source_display", :locals => { :display_manual_violation_form => false, \ + :scm_available => options[:display_scm], \ + :display_coverage => options[:display_coverage], \ + :lines => panel.html_lines, \ + :expanded => options[:expand], \ + :display_violations => options[:display_violations], \ + :resource => nil, \ + :snapshot => nil, \ + :review_screens_by_vid => false, \ + :filtered => panel.filtered } + + end + end def load_distribution(snapshot, metric_key) @@ -171,5 +185,10 @@ module SourceHelper end end end + + def highlighted? + # highlighted if the @highlighted has not been set or has been set to true + !hidden? && @highlighted!=false + end end end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb index f6fd0e25332..2d4e1bf0aa7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb @@ -101,7 +101,6 @@ item.scrollIntoView(true); }); <% end %> - $j("#content").on("click", "span[class|='symbol']", highlight_usages);
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index.html.erb index 4ba68cf8d0a..407adaa5b67 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index.html.erb @@ -9,7 +9,10 @@ <% @global_violations.each do |violation| %> - + <% end %>
<%= render :partial => 'violation', :locals => {:violation => violation, :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%> + <%= render :partial => 'violation', :locals => {:violation => violation, \ + :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%> +
@@ -17,139 +20,17 @@ <% if @lines && @lines.size>0 %> - - <% - colspan=2 - gray_colspan=1 - white_colspan=0 - if @display_manual_violation_form - colspan+=1 - gray_colspan+=1 - end - if @scm_available - colspan+=1 - gray_colspan+=1 - end - if @display_coverage - colspan+=2 - white_colspan+=2 - end - - current_revision=nil - previous_hidden=false - first_section=true - has_displayed_lines=false - @lines.each_with_index do |line, index| - if line.hidden? && !@expanded - previous_hidden=true - next - end - - if previous_hidden && !first_section - current_revision=nil - %> - - - - <% - end - previous_hidden=false - first_section=false - - status=hits_status=conditions_status='' - if line.highlighted? - has_displayed_lines=true - if @display_coverage && line.hits - hits_status=(line.hits>0 ? 'ok' : 'ko') - if line.conditions && line.conditions>0 && line.covered_conditions - if line.covered_conditions==0 - status='ko' - conditions_status='ko' - elsif line.covered_conditions==line.conditions - status='' - conditions_status='ok' - else - conditions_status='warn' - status='warn' - end - elsif line.hits - status=(line.hits>0 ? '' : 'ko') - end - elsif @display_violations && line.violations? - status="ko" - end - end - %> - - <% if @display_manual_violation_form %> - - <% - end - if @scm_available - if current_revision!=line.revision - current_revision=line.revision - title = "Revision #{h(line.revision)}" - %> - - <% else %> - - <% end - end - %> - - - <% if @display_coverage %> - <% if line.highlighted? %> - - - <% else %> - - - <% end %> - <% end %> - - - <% if @display_violations && line.violations? %> - - <% if @display_manual_violation_form %> - - <% end - if @scm_available %> - - <% end %> - - - - <% end %> - <% end %> -
- <%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%> - <%= h(line.author) -%><%= index + 1 -%> - - <% if line.covered_lines > 0 %> - <%= line.covered_lines -%> - <% end %> - - <% if line.deprecated_conditions_label -%> - <%= line.deprecated_conditions_label -%> - <% elsif line.conditions && line.conditions>0 -%> - <%= line.covered_conditions -%>/<%= line.conditions -%> - <% end %> - -
<%= line.source -%>
-
- <% line.violations.each_with_index do |violation, index| %> - <%= render :partial => 'violation', :locals => {:violation => violation, :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%> - <% if index < line.violations.size-1 %> -   - <% end %> - <% end %> -
- - <% if @filtered && !has_displayed_lines %> -

<%= message('no_lines_match_your_filter_criteria') -%>

- <% end %> + <%= render :partial => "shared/source_display", :locals => { :display_manual_violation_form => @display_manual_violation_form, \ + :scm_available => @scm_available, \ + :display_coverage => @display_coverage, \ + :lines => @lines, \ + :expanded => @expanded, \ + :display_violations => @display_violations, \ + :resource => @resource, \ + :snapshot => @snapshot, \ + :review_screens_by_vid => @review_screens_by_vid, \ + :filtered => @filtered} + %> <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb index 752923d18c4..f1ba5bc0a8c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb @@ -6,5 +6,4 @@ \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_code.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_code.html.erb new file mode 100644 index 00000000000..76ffc41c72b --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_code.html.erb @@ -0,0 +1,3 @@ + +
<%= code -%>
+ \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb new file mode 100644 index 00000000000..c17d488768a --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb @@ -0,0 +1,19 @@ +<% if line.highlighted? %> + + <% if line.covered_lines > 0 %> + <%= line.covered_lines -%> + <% end %> + + + <% if line.deprecated_conditions_label -%> + <%= line.deprecated_conditions_label -%> + <% elsif line.conditions && line.conditions>0 -%> + <%= line.covered_conditions -%> + /<%= line.conditions -%> + <% end %> + +<% else %> + + +<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb new file mode 100644 index 00000000000..b672b1bca80 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb @@ -0,0 +1,72 @@ + +<%= current_display_id = "sources_#{rand(100)}" %> + + + + + + <% + colspans = prepare_colspans(display_manual_violation_form, scm_available, display_coverage) + first_section = true + %> + + <% + lines.each_with_index do |line, index| + if line.hidden? && !expanded + previous_hidden = true + next + end + if previous_hidden && !first_section + current_revision = nil + %> + <%= render :partial => "shared/source_new_section", :locals => {:colspan => colspans[:base]} %> + <% + end + + previous_hidden=false + first_section=false + statuses = compute_statuses(line, display_coverage, display_violations) + has_displayed_lines = line.highlighted? + %> + + + + <% if display_manual_violation_form %> + <%= render :partial => "shared/source_violation_form", :locals => {:resource_id => resource.id, :index => index, :colspans => colspans} %> + <% end %> + + <% if scm_available %> + render :partial => "shared/source_scm", :locals => {:line => line, :current_revision => current_revision} + <% end %> + + <%= render :partial => "shared/source_line_numbers", :locals => {:index => index} %> + + <% if display_coverage %> + <%= render :partial => "shared/source_coverage", :locals => {:line => line, \ + :statuses => statuses, \ + :index => index, \ + :resource_key => snapshot.resource.key} %> + <% end %> + + <%= render :partial => "shared/source_code", :locals => {:code => line.source, :status => statuses[:base]} %> + + + + <% if display_violations && line.violations? %> + <%= render :partial => "shared/source_violations", :locals => {:line => line, \ + :display_violation_form => display_manual_violation_form, \ + :scm_available => scm_available, \ + :review_screens_by_vid => review_screens_by_vid} %> + <% end %> + + <% end %> +
+ +<% if filtered && !has_displayed_lines %> +

<%= message('no_lines_match_your_filter_criteria') -%>

+<% end %> + + + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_line_numbers.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_line_numbers.erb new file mode 100644 index 00000000000..08471241ba0 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_line_numbers.erb @@ -0,0 +1 @@ +<%= index + 1 -%> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_new_section.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_new_section.html.erb new file mode 100644 index 00000000000..21a7dfb9d1e --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_new_section.html.erb @@ -0,0 +1,4 @@ + + + + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_scm.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_scm.html.erb new file mode 100644 index 00000000000..90f0a4a7cc3 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_scm.html.erb @@ -0,0 +1,11 @@ +<% + if current_revision!=line.revision + current_revision=line.revision + title = "Revision #{h(line.revision)}" + %> + + <%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%> + <%= h(line.author) -%> + <% else %> + +<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb new file mode 100644 index 00000000000..e0a0996c1f9 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb @@ -0,0 +1,3 @@ + + + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violations.html.erb new file mode 100644 index 00000000000..b71e5144955 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violations.html.erb @@ -0,0 +1,17 @@ + + <% if @display_manual_violation_form %> + + <% end + if @scm_available %> + + <% end %> + + + <% line.violations.each_with_index do |violation, index| %> + <%= render :partial => 'violation', :locals => {:violation => violation, :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%> + <% if index < line.violations.size-1 %> +   + <% end %> + <% end %> + + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb deleted file mode 100644 index 690513754ff..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb +++ /dev/null @@ -1,63 +0,0 @@ -<% if !panel.empty? %> - - <% - current_revision=nil - colspan=2 - colspan+=1 if panel.display_scm -# colspan+=2 if @display_coverage - previous_hidden=false - first_section=true - has_displayed_lines=false - panel.html_lines.each do |line| - if line.hidden? && panel.expanded - previous_hidden=true - next - end - - if previous_hidden && !first_section - current_revision=nil -%> - - - -<% - end - previous_hidden=false - first_section=false - - status=hits_status=conditions_status='' - if line.selected? - has_displayed_lines=true - if line.highlighted - status='ko' - end - end - %> - - <% - if panel.display_scm - if current_revision!=line.revision - current_revision=line.revision - title = "Revision #{h(line.revision)}" - %> - - <% else %> - - <% end - end - %> - - - - - - - <% end %> -
<%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%> <%= h(line.author) -%><%= line.id -%> -
<%= line.source -%>
-
- - <% if panel.filtered && !has_displayed_lines %> -

<%= message('no_lines_match_your_filter_criteria') -%>

- <% end %> -<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/javascripts/resource.js b/sonar-server/src/main/webapp/javascripts/resource.js index 33adf56b94a..8c1dcc8179b 100644 --- a/sonar-server/src/main/webapp/javascripts/resource.js +++ b/sonar-server/src/main/webapp/javascripts/resource.js @@ -203,8 +203,8 @@ function collapseTests(index, elt){ } /* Source decoration functions */ -function highlight_usages(){ +function highlight_usages(event){ var selectedClass = $j(this).attr("class").split(" ")[0]; - $j(".highlighted").removeClass("highlighted"); - $j("." + selectedClass).toggleClass("highlighted"); + $j("#" + event.data.id + " span.highlighted").removeClass("highlighted"); + $j("#" + event.data.id + " span." + selectedClass).toggleClass("highlighted"); } \ No newline at end of file