]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2382 Highlight selected line in source panel
authorsimonbrandhof <simon.brandhof@gmail.com>
Wed, 27 Apr 2011 07:22:40 +0000 (09:22 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Wed, 27 Apr 2011 07:22:40 +0000 (09:22 +0200)
sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb

index c6ed7856961ad65360c1a3f9e4ec7c0d66be22e5..2d6ae9a3d142c4d82bfc41eca5f2242f0e1872c5 100644 (file)
@@ -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)
index bf7b8b55f2ea57e8c91131661cd02aa7f8cbe9b2..6b9ea44532b52e0025d22f24ab7a08559493461a 100644 (file)
         </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">
index fe339ed35d5f3af70d16a1a6b632215646c96dbf..d146d350da25ae5ba9a5b93ac0bd42312bfb3380 100644 (file)
@@ -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
       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 -%>">