aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-27 09:22:40 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-27 09:22:40 +0200
commitd4b1a3c4fa3c06c32a8e9a5a9b635dbc232a33ea (patch)
tree9a5b9d87e023bec7ce2acc447e0e06a3c4ef2d3a /sonar-server
parent3416fc08bf2efbb28d377b0c6c2f371823370a39 (diff)
downloadsonarqube-d4b1a3c4fa3c06c32a8e9a5a9b635dbc232a33ea.tar.gz
sonarqube-d4b1a3c4fa3c06c32a8e9a5a9b635dbc232a33ea.zip
SONAR-2382 Highlight selected line in source panel
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb41
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb9
3 files changed, 33 insertions, 23 deletions
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 c6ed7856961..2d6ae9a3d14 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
@@ -44,13 +44,17 @@ module SourceHelper
panel.html_lines=[]
line_range=sanitize_line_range(options[:line_range])
- snapshot.source.syntax_highlighted_lines()[line_range].each_with_index do |source, index|
- html_line=HtmlLine.new(source)
- html_line.revision=revisions_by_line[index+1]
- html_line.author=authors_by_line[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
+ highlighted_lines=options[:highlighted_lines]||[]
+ snapshot.source.syntax_highlighted_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]
@@ -90,10 +94,11 @@ module SourceHelper
end
class HtmlLine
- attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :highlighted, :deprecated_conditions_label
+ attr_accessor :id, :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :selected, :highlighted, :deprecated_conditions_label
- def initialize(source)
+ def initialize(source, id)
@source=source
+ @id=id
end
def add_violation(violation)
@@ -122,14 +127,14 @@ module SourceHelper
end
end
- def flag_as_highlighted
- @highlighted=true
+ def flag_as_selected
+ @selected=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?
+ def flag_as_selected_context
+ # do not force if selected has already been set to true
+ @selected=false if @selected.nil?
@hidden=false
end
@@ -137,7 +142,7 @@ module SourceHelper
# do not force if it has already been flagged as visible
if @hidden.nil?
@hidden=true
- @highlighted=false
+ @selected=false
end
end
@@ -145,9 +150,9 @@ module SourceHelper
@hidden==true
end
- def highlighted?
- # highlighted if the @highlighted has not been set or has been set to true
- !hidden? && @highlighted!=false
+ def selected?
+ # selected if the @selected has not been set or has been set to true
+ !hidden? && @selected!=false
end
def deprecated_conditions_label=(label)
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb
index bf7b8b55f2e..6b9ea44532b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb
@@ -76,8 +76,10 @@
</tr>
</table>
- <% if review.rule_failure %>
-
+ <% if review.rule_failure && review.resource_line && review.rule_failure.snapshot %>
+ <div class="marginbottom10">
+ <%= snapshot_source_to_html(review.rule_failure.snapshot, {:line_range => (review.resource_line-5)..(review.resource_line+5), :highlighted_lines => [review.resource_line]}) -%>
+ </div>
<% end %>
<div class="discussion">
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
index fe339ed35d5..d146d350da2 100644
--- 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
@@ -9,7 +9,7 @@
previous_hidden=false
first_section=true
has_displayed_lines=false
- panel.html_lines.each_with_index do |line, index|
+ panel.html_lines.each do |line|
if line.hidden? && panel.expanded
previous_hidden=true
next
@@ -27,8 +27,11 @@
first_section=false
status=hits_status=conditions_status=''
- if line.highlighted?
+ if line.selected?
has_displayed_lines=true
+ if line.highlighted
+ status='ko'
+ end
# if @display_coverage && line.hits
# hits_status=(line.hits>0 ? 'ok' : 'ko')
# if line.conditions && line.conditions>0 && line.covered_conditions
@@ -63,7 +66,7 @@
<% end
end
%>
- <td class="lid <%= ' section' if line.violations? -%>" id="L<%= index+1 -%>"><a name="L<%= index+1 -%>" href="#L<%= index+1 -%>"><%= index + 1 -%></a></td>
+ <td class="lid <%= ' section' if line.violations? -%>" id="L<%= line.id -%>"><a name="L<%= line.id -%>" href="#L<%= line.id -%>"><%= line.id -%></a></td>
<td class="line <%= status -%>">