diff options
author | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-23 12:25:34 +0200 |
---|---|---|
committer | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-23 12:25:34 +0200 |
commit | 2f0816eb1d12429be7cb875cddc34ab3cd879886 (patch) | |
tree | 94a0b8188ddc7c88c74e37c73c48577223c9cc8c | |
parent | e8edf3d35c87e31da947b9f4052d91f125cfc01f (diff) | |
download | sonarqube-2f0816eb1d12429be7cb875cddc34ab3cd879886.tar.gz sonarqube-2f0816eb1d12429be7cb875cddc34ab3cd879886.zip |
SONAR-3893 Code display refactoring
10 files changed, 234 insertions, 382 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 e8b6d713333..85b20025986 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 @@ -21,7 +21,7 @@ require "rexml/document" class ResourceController < ApplicationController - include REXML + include REXML, SourceHelper SECTION=Navigation::SECTION_RESOURCE helper :dashboard @@ -161,34 +161,15 @@ class ResourceController < ApplicationController @expanded=(params[:expand]=='true') @display_manual_violation_form=(current_user && has_role?(:user, @snapshot)) - if @snapshot.has_source - source_lines = @snapshot.highlighting_data || @snapshot.source.syntax_highlighted_lines() - init_scm() - - @lines=[] - source_lines.each_with_index do |source, index| - line=Line.new(source) - @lines<<line - - line.revision=@revisions_by_line[index+1] - line.author=@authors_by_line[index+1] - - date_string=@dates_by_line[index+1] - line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string) : nil) - end - end + panel = get_html_source_panel(@snapshot, {:display_scm => true}) + @lines = panel.html_lines end def init_scm @scm_available=(@snapshot.measure('last_commit_datetimes_by_line')!=nil) - @authors_by_line=load_distribution('authors_by_line') - @revisions_by_line=load_distribution('revisions_by_line') - @dates_by_line=load_distribution('last_commit_datetimes_by_line') - end - - def load_distribution(metric_key) - m=@snapshot.measure(metric_key) - m ? m.data_as_line_distribution() : {} + @authors_by_line=load_distribution(@snapshot, 'authors_by_line') + @revisions_by_line=load_distribution(@snapshot, 'revisions_by_line') + @dates_by_line=load_distribution(@snapshot, 'last_commit_datetimes_by_line') end def render_coverage @@ -207,9 +188,9 @@ class ResourceController < ApplicationController it_prefix = 'it_' if (@coverage_filter.start_with?('it_') || @coverage_filter.start_with?('new_it_')) it_prefix = 'overall_' if (@coverage_filter.start_with?('overall_') || @coverage_filter.start_with?('new_overall_')) - @hits_by_line = load_distribution("#{it_prefix}coverage_line_hits_data") - @conditions_by_line = load_distribution("#{it_prefix}conditions_by_line") - @covered_conditions_by_line = load_distribution("#{it_prefix}covered_conditions_by_line") + @hits_by_line = load_distribution(@snapshot, "#{it_prefix}coverage_line_hits_data") + @conditions_by_line = load_distribution(@snapshot, "#{it_prefix}conditions_by_line") + @covered_conditions_by_line = load_distribution(@snapshot, "#{it_prefix}covered_conditions_by_line") @testable = java_facade.testable(@snapshot.id) @hits_by_line.each_pair do |line_id, hits| @@ -217,6 +198,7 @@ class ResourceController < ApplicationController if line line.index = line_id line.covered_lines = @testable ? @testable.countTestCasesOfLine(line_id) : 0 + puts "covered_lines for line #{line.index} has been set to #{line.covered_lines}" line.hits = hits.to_i line.conditions = @conditions_by_line[line_id].to_i line.covered_conditions = @covered_conditions_by_line[line_id].to_i @@ -225,7 +207,7 @@ class ResourceController < ApplicationController if @snapshot.measure("#{it_prefix}conditions_by_line").nil? # TODO remove this code when branch_coverage_hits_data is fully removed from CoreMetrics - deprecated_branches_by_line = load_distribution("#{it_prefix}branch_coverage_hits_data") + deprecated_branches_by_line = load_distribution(@snapshot, "#{it_prefix}branch_coverage_hits_data") deprecated_branches_by_line.each_pair do |line_id, label| line = @lines[line_id-1] if line @@ -236,7 +218,7 @@ class ResourceController < ApplicationController to = (@period && @snapshot.period_datetime(@period) ? Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000) : nil) @filtered = true - + puts "coverage filter is #{@coverage_filter}" if ('lines_to_cover'==@coverage_filter || 'coverage'==@coverage_filter || 'line_coverage'==@coverage_filter || 'new_lines_to_cover'==@coverage_filter || 'new_coverage'==@coverage_filter || 'new_line_coverage'==@coverage_filter || 'it_lines_to_cover'==@coverage_filter || 'it_coverage'==@coverage_filter || 'it_line_coverage'==@coverage_filter || @@ -244,7 +226,9 @@ class ResourceController < ApplicationController 'overall_lines_to_cover'==@coverage_filter || 'overall_coverage'==@coverage_filter || 'overall_line_coverage'==@coverage_filter || 'new_overall_lines_to_cover'==@coverage_filter || 'new_overall_coverage'==@coverage_filter || 'new_overall_line_coverage'==@coverage_filter) @coverage_filter = "#{it_prefix}lines_to_cover" - filter_lines { |line| line.hits && line.after(to) } + filtered_lines = filter_lines { |line| line.hits && line.after(to) } + puts "filtered lines length : #{filtered_lines.length}" + filtered_lines elsif ('uncovered_lines'==@coverage_filter || 'new_uncovered_lines'==@coverage_filter || 'it_uncovered_lines'==@coverage_filter || 'new_it_uncovered_lines'==@coverage_filter || @@ -531,11 +515,11 @@ class ResourceController < ApplicationController @lines.each_with_index do |line, index| if yield(line) for i in index-4...index - @lines[i].flag_as_highlight_context() if i>=0 + @lines[i].flag_as_displayed_context if i>=0 end - line.flag_as_highlighted() + line.flag_as_displayed for i in index+1..index+4 - @lines[i].flag_as_highlight_context() if i<@lines.size + @lines[i].flag_as_displayed_context if i<@lines.size end else line.flag_as_hidden() @@ -543,103 +527,6 @@ class ResourceController < ApplicationController end end - class Line - attr_accessor :index, :source, :revision, :author, :datetime, :violations, :issues, :hits, :conditions, :covered_conditions, :hidden, :highlighted, - :deprecated_conditions_label, :covered_lines - - def initialize(source) - @source=source - end - - def add_violation(violation) - @violations||=[] - @violations<<violation - @visible=true - end - - def add_issue(issue) - @issues||=[] - @issues<<issue - @visible=true - end - - def violations? - @violations && @violations.size>0 - end - - def issues? - @issues && @issues.size>0 - end - - def violation_severity - if @violations && @violations.size>0 - @violations[0].failure_level - else - nil - end - end - - def issue_severity - if @issues && @issues.size>0 - @issues[0].severity - else - nil - end - end - - def after(date) - if date && @datetime - @datetime.after(date) - else - true - end - end - - def flag_as_highlighted - @highlighted=true - @hidden=false - end - - def flag_as_highlight_context - # do not force if highlighted has already been set to true - @highlighted=false if @highlighted.nil? - @hidden=false - end - - def flag_as_hidden - # do not force if it has already been flagged as visible - if @hidden.nil? - @hidden=true - @highlighted=false - end - end - - def hidden? - @hidden==true - end - - def highlighted? - # highlighted if the @highlighted has not been set or has been set to true - !hidden? && @highlighted!=false - end - - def deprecated_conditions_label=(label) - if label - @deprecated_conditions_label=label - if label=='0%' - @conditions=2 - @covered_conditions=0 - elsif label=='100%' - @conditions=2 - @covered_conditions=2 - else - @conditions=2 - @covered_conditions=1 - end - end - end - end - def render_extension() render :partial => 'extension' 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 8505c4241d3..bbb3aaf86da 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 @@ -814,7 +814,7 @@ module ApplicationHelper status=hits_status=conditions_status='' - if line.highlighted? + if line.displayed? if display_coverage && line.hits hits_status=(line.hits>0 ? 'ok' : 'ko') if line.conditions && line.conditions>0 && line.covered_conditions 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 d0b5a57c2d5..7de01cb0f8b 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 @@ -1,80 +1,95 @@ - # - # Sonar, entreprise quality control tool. - # Copyright (C) 2008-2013 SonarSource - # mailto:contact AT sonarsource DOT com - # - # SonarQube is free software; you can redistribute it and/or - # modify it under the terms of the GNU Lesser General Public - # License as published by the Free Software Foundation; either - # version 3 of the License, or (at your option) any later version. - # - # SonarQube is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - # Lesser General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public License - # along with this program; if not, write to the Free Software Foundation, - # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - # +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# module SourceHelper # # Options : # - display_scm : boolean (default is true) # - display_violations: boolean (default is false) + # - display_issues: boolean (default is false) # - display_coverage: boolean (default is false) # - expand: boolean (default is false). Only if display_violations or display_coverage is true # - min_date - # - line_range + # - line_range : range (default is complete lines range) + # - highlighted_lines : range (default is complete lines range) # def snapshot_source_to_html(snapshot, options={}) - return '' unless snapshot && snapshot.source - - panel=SourcePanel.new - revisions_by_line={} - authors_by_line={} - dates_by_line={} - unless options[:display_scm]==false - panel.display_scm=(snapshot.measure('last_commit_datetimes_by_line')!=nil) - authors_by_line=load_distribution(snapshot,'authors_by_line') - revisions_by_line=load_distribution(snapshot,'revisions_by_line') - dates_by_line=load_distribution(snapshot,'last_commit_datetimes_by_line') - end - - panel.html_lines=[] - line_range=sanitize_line_range(options[:line_range]) - highlighted_lines=options[:highlighted_lines]||[] - source_lines = snapshot.highlighting_data || snapshot.source.syntax_highlighted_lines() - source_lines.each_with_index do |source, index| - if line_range.include?(index+1) - html_line=HtmlLine.new(source, index+1) - html_line.revision=revisions_by_line[index+1] - html_line.author=authors_by_line[index+1] - html_line.highlighted=(highlighted_lines.include?(index+1)) - date_string=dates_by_line[index+1] - html_line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string): nil) - panel.html_lines<<html_line - end - end - panel.filter_min_date(options[:min_date]) if options[:min_date] + panel = get_html_source_panel(snapshot, options) - unless panel.empty? + unless panel.nil? + panel.filter_min_date(options[:min_date]) if options[:min_date] - render :partial => "shared/source_display", :locals => { :display_manual_violation_form => false, \ + 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], \ + :display_issues => options[:display_issues], \ :resource => nil, \ :snapshot => nil, \ :review_screens_by_vid => false, \ - :filtered => panel.filtered } + :filtered => panel.filtered} + end + else + '' end + end + + def get_html_source_panel(snapshot, options={}) + if snapshot && snapshot.has_source + + panel=SourcePanel.new + revisions_by_line={} + authors_by_line={} + dates_by_line={} + if options[:display_scm] + panel.display_scm=(snapshot.measure('last_commit_datetimes_by_line')!=nil) + authors_by_line=load_distribution(snapshot, 'authors_by_line') + revisions_by_line=load_distribution(snapshot, 'revisions_by_line') + dates_by_line=load_distribution(snapshot, 'last_commit_datetimes_by_line') + end + + panel.html_lines=[] + html_source_lines = snapshot.highlighting_data || snapshot.source.syntax_highlighted_lines() + line_range=sanitize_range(options[:line_range], 1..html_source_lines.length) + highlighted_lines=sanitize_range(options[:highlighted_lines], 1..html_source_lines.length) + + html_source_lines.each_with_index do |source, index| + if line_range.include?(index+1) + html_line=HtmlLine.new(source, index+1) + html_line.revision=revisions_by_line[index+1] + html_line.author=authors_by_line[index+1] + html_line.displayed=highlighted_lines.include?(index+1) + date_string=dates_by_line[index+1] + html_line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string) : nil) + panel.html_lines<<html_line + end + end + panel + end end def load_distribution(snapshot, metric_key) @@ -82,11 +97,13 @@ module SourceHelper m ? m.data_as_line_distribution() : {} end - def sanitize_line_range(range) + def sanitize_range(range, default_range) if range ([range.min, 1].max)..(range.max) + elsif default_range + default_range else - [0..-1] + 0..-1 end end @@ -109,11 +126,12 @@ module SourceHelper end class HtmlLine - attr_accessor :id, :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :selected, :highlighted, :deprecated_conditions_label + attr_accessor :index, :source, :revision, :author, :datetime, :violations, :issues, :hits, :conditions, + :covered_conditions, :hidden, :displayed, :deprecated_conditions_label, :covered_lines - def initialize(source, id) + def initialize(source, index) @source=source - @id=id + @index=index end def add_violation(violation) @@ -122,10 +140,20 @@ module SourceHelper @visible=true end + def add_issue(issue) + @issues||=[] + @issues<<issue + @visible=true + end + def violations? @violations && @violations.size>0 end + def issues? + @issues && @issues.size>0 + end + def violation_severity if @violations && @violations.size>0 @violations[0].failure_level @@ -134,6 +162,14 @@ module SourceHelper end end + def issue_severity + if @issues && @issues.size>0 + @issues[0].severity + else + nil + end + end + def after(date) if date && @datetime @datetime.after(date) @@ -142,22 +178,25 @@ module SourceHelper end end - def flag_as_selected - @selected=true + def flag_as_displayed + @displayed=true @hidden=false + puts "line #{index} will be displayed" end - def flag_as_selected_context + def flag_as_displayed_context # do not force if selected has already been set to true - @selected=false if @selected.nil? + @displayed=false if @displayed.nil? @hidden=false + puts "line #{index} will be displayed as context" end def flag_as_hidden # do not force if it has already been flagged as visible if @hidden.nil? @hidden=true - @selected=false + @displayed=false + puts "line #{index} will be hidden" end end @@ -165,30 +204,25 @@ module SourceHelper @hidden==true end - def selected? + def displayed? # selected if the @selected has not been set or has been set to true - !hidden? && @selected!=false + !hidden? && @displayed!=false end def deprecated_conditions_label=(label) if label @deprecated_conditions_label=label - if label=='0%' - @conditions=2 - @covered_conditions=0 - elsif label=='100%' - @conditions=2 - @covered_conditions=2 - else - @conditions=2 - @covered_conditions=1 + if label=='0%' + @conditions=2 + @covered_conditions=0 + elsif label=='100%' + @conditions=2 + @covered_conditions=2 + else + @conditions=2 + @covered_conditions=1 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/resource/_index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index.html.erb index 407adaa5b67..7837b010449 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 @@ -26,6 +26,7 @@ :lines => @lines, \ :expanded => @expanded, \ :display_violations => @display_violations, \ + :display_issues => @display_issues, \ :resource => @resource, \ :snapshot => @snapshot, \ :review_screens_by_vid => @review_screens_by_vid, \ diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index_issues.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index_issues.html.erb index 09df64a7341..778ed831a06 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index_issues.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index_issues.html.erb @@ -17,148 +17,18 @@ <% if @lines && @lines.size>0 %> - <table id="sources" class="sources2 code" cellpadding="0" cellspacing="0" border="0"> - <% - colspan=2 - gray_colspan=1 - white_colspan=0 - # TODO - #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 + <%= 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, \ + :display_issues => @display_issues, \ + :resource => @resource, \ + :snapshot => @snapshot, \ + :review_screens_by_vid => @review_screens_by_vid, \ + :filtered => @filtered} %> - <tr> - <td colspan="<%= colspan -%>" class="new_section"></td> - </tr> - <% - 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_issues && line.issues? - status="ko" - end - end - %> - <tr class="row pos<%= index+1 -%>"> - <% - # TODO - #if @display_manual_violation_form - if false - %> - <td class="plus"><a onclick="return sVF(this, <%= @resource.id -%>,<%= index + 1 -%>,<%= gray_colspan -%>,<%= white_colspan -%>)"></a></td> - <% - end - if @scm_available - if current_revision!=line.revision - current_revision=line.revision - title = "Revision #{h(line.revision)}" - %> - <td class="scm revision"> - <span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%></a></span> - <span class="author"><%= h(line.author) -%></span></td> - <% else %> - <td class="scm"></td> - <% end - end - %> - <td class="lid L<%= index+1 -%>"><a name="L<%= index+1 -%>" href="#L<%= index+1 -%>"><%= index + 1 -%></a> - </td> - - <% if @display_coverage %> - <% if line.highlighted? %> - <td class="ind <%= hits_status -%>" title="<%= message('coverage_viewer.line_covered_by_x_tests', {:params => line.covered_lines.to_s}) if line.covered_lines > 0 -%>"> - <% if line.covered_lines > 0 %> - <a href="<%= ApplicationController.root_context -%>/test/testable/<%= h @snapshot.resource.key -%>?line=<%= index+1 -%>" - class="sources-testable-link-<%= index+1 -%>" onclick="openAccordionItem(this.href, this); return false;"><%= line.covered_lines -%></a> - <% end %> - </td> - <td class="ind <%= conditions_status -%>"> - <% if line.deprecated_conditions_label -%> - <%= line.deprecated_conditions_label -%> - <% elsif line.conditions && line.conditions>0 -%> - <span title="<%= h message('coverage_viewer.x_covered_branches', {:params => line.covered_conditions.to_s})-%>"><%= line.covered_conditions -%>/<%= line.conditions -%></span> - <% end %> - </td> - <% else %> - <td class="ind"></td> - <td class="ind"></td> - <% end %> - <% end %> - <td class="line <%= status -%>"> - <pre><%= line.source -%></pre> - </td> - </tr> - <% if @display_issues && line.issues? %> - <tr> - <% - # TODO - #if @display_manual_violation_form - if false - %> - <td class="gray"></td> - <% end - if @scm_available %> - <td class="scm"></td> - <% end %> - <td class="lid"></td> - <td class="violations"> - <% line.issues.each_with_index do |issue, index| %> - <%= render :partial => 'issue', :locals => {:issue => issue} -%> - <% if index < line.issues.size-1 %> - - <% end %> - <% end %> - </td> - </tr> - <% end %> - <% end %> - </table> - - <% if @filtered && !has_displayed_lines %> - <p style="padding: 10px"><%= message('no_lines_match_your_filter_criteria') -%></p> - <% end %> <% end %> 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 index c17d488768a..17c5d47c5f6 100644 --- 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 @@ -1,4 +1,5 @@ -<% if line.highlighted? %> +<% if line.displayed? && line.covered_lines %> + <% puts "displaying coverage info #{line.covered_lines} for line #{line.index}" %> <td class="ind <%= statuses[:hits] -%>" title="<%= message('coverage_viewer.line_covered_by_x_tests', {:params => line.covered_lines.to_s}) if line.covered_lines > 0 -%>"> <% if line.covered_lines > 0 %> <a href="<%= ApplicationController.root_context -%>/test/testable/<%= h resource_key -%>?line=<%= index+1 -%>" @@ -9,8 +10,7 @@ <% if line.deprecated_conditions_label -%> <%= line.deprecated_conditions_label -%> <% elsif line.conditions && line.conditions>0 -%> - <span title="<%= h message('coverage_viewer.x_covered_branches', {:params => line.covered_conditions.to_s}) -%>"><%= line.covered_conditions -%> - /<%= line.conditions -%></span> + <span title="<%= h message('coverage_viewer.x_covered_branches', {:params => line.covered_conditions.to_s}) -%>"><%= line.covered_conditions -%>/<%= line.conditions -%></span> <% end %> </td> <% else %> 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 index c3ce284ed0a..6e34d9c1990 100644 --- 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 @@ -1,6 +1,5 @@ <% current_display_id = "sources_#{rand(100)}" - has_displayed_lines = false %> <table id="<%= current_display_id %>" class="sources2 code" cellpadding="0" cellspacing="0" border="0"> @@ -9,34 +8,76 @@ $j("#<%= current_display_id %>").on("click", "span[class|='symbol']", {id: "<%= current_display_id.to_s() %>"}, highlight_usages); </script> - <% - 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]} %> + <% + 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 + + %> + + <%= render :partial => "shared/source_new_section", :locals => {:colspan => colspan} %> <% end - previous_hidden=false first_section=false - statuses = compute_statuses(line, display_coverage, display_violations) - has_displayed_lines = line.highlighted? + + status=hits_status=conditions_status='' + if line.displayed? + 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 %> <tr class="row pos<%= index+1 -%>"> <% if display_manual_violation_form %> - <%= render :partial => "shared/source_violation_form", :locals => {:resource_id => resource.id, :index => index, :colspans => colspans} %> + <%= render :partial => "shared/source_violation_form", :locals => { :resource_id => resource.id, \ + :index => index, \ + :gray_colspan => gray_colspan, \ + :white_colspan => white_colspan} %> <% end %> <% if scm_available @@ -57,22 +98,27 @@ <% if display_coverage %> <%= render :partial => "shared/source_coverage", :locals => {:line => line, \ - :statuses => statuses, \ + :statuses => {:hits => hits_status, :conditions => conditions_status}, \ :index => index, \ :resource_key => snapshot.resource.key} %> <% end %> - <%= render :partial => "shared/source_code", :locals => {:code => line.source, :status => statuses[:base]} %> + <%= render :partial => "shared/source_code", :locals => {:code => line.source, :status => status} %> </tr> <% if display_violations && line.violations? %> <%= render :partial => "shared/source_violations", :locals => {:line => line, \ - :display_violation_form => display_manual_violation_form, \ + :display_manual_violation_form => display_manual_violation_form, \ :scm_available => scm_available, \ :review_screens_by_vid => review_screens_by_vid} %> <% end %> + <% if display_issues && line.issues? %> + <%= render :partial => "shared/source_issues", :locals => { :line => line, \ + :scm_available => scm_available} %> + <% end %> + <% end %> </table> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_issues.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_issues.html.erb new file mode 100644 index 00000000000..133141c2b67 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_issues.html.erb @@ -0,0 +1,14 @@ +<tr> + <% if scm_available %> + <td class="scm"></td> + <% end %> + <td class="lid"></td> + <td class="violations"> + <% line.issues.each_with_index do |issue, index| %> + <%= render :partial => 'issue', :locals => {:issue => issue} -%> + <% if index < line.issues.size-1 %> + + <% end %> + <% end %> + </td> +</tr>
\ 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 index e0a0996c1f9..fa297e8abca 100644 --- 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 @@ -1,3 +1,3 @@ <td class="plus"> - <a onclick="return sVF(this, <%= resource_id -%>,<%= index + 1 -%>,<%= colspans[:gray] -%>,<%= colspans[:white] -%>)"></a> + <a onclick="return sVF(this, <%= resource_id -%>,<%= index + 1 -%>,<%= gray_colspan -%>,<%= white_colspan -%>)"></a> </td> 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 index b71e5144955..4303b414221 100644 --- 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 @@ -1,17 +1,17 @@ <tr> - <% if @display_manual_violation_form %> + <% if display_manual_violation_form %> <td class="gray"></td> <% end - if @scm_available %> + if scm_available %> <td class="scm"></td> <% end %> <td class="lid"></td> <td class="violations"> <% 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) : []} -%> + <%= 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 %> </td> -</tr>
\ No newline at end of file +</tr> |