]> source.dussan.org Git - sonarqube.git/commitdiff
The coverage tab must display block of codes, filtered by lines to cover,uncovered...
authorsimonbrandhof <simon.brandhof@gmail.com>
Thu, 17 Mar 2011 14:01:38 +0000 (15:01 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Thu, 17 Mar 2011 14:01:38 +0000 (15:01 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb

index 672eb3683a46ea8bf51d4af1da0077fbf936ff1d..40c1ccf4614252c9566632f96ab00bc6ac0b3df1 100644 (file)
@@ -90,7 +90,7 @@ class ResourceController < ApplicationController
         line.author=@authors_by_line[index+1]
 
         date_string=@dates_by_line[index+1]
-        line.datetime=(date_string ? DateTime::strptime(date_string): nil)
+        line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string): nil)
       end
     end
   end
@@ -110,6 +110,7 @@ class ResourceController < ApplicationController
   def render_coverage
     load_sources()
     @display_coverage=true
+    @expandable=(@lines!=nil)
     if @lines
       @hits_by_line=load_distribution('coverage_line_hits_data')
       @conditions_by_line=load_distribution('conditions_by_line')
@@ -125,6 +126,7 @@ class ResourceController < ApplicationController
       end
 
       if @snapshot.measure('conditions_by_line').nil?
+        # TODO remove this code when branch_coverage_hits_data is fully removed from CoreMetrics
         deprecated_branches_by_line=load_distribution('branch_coverage_hits_data')
         deprecated_branches_by_line.each_pair do |line_id,label|
           line=@lines[line_id-1]
@@ -134,7 +136,28 @@ class ResourceController < ApplicationController
         end
       end
 
-      filter_lines_by_date()
+      to=(@period ? Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000) : nil)
+      metric=Metric.by_key(params[:coverage_filter]||params[:metric])
+      @coverage_filter=(metric ? metric.key : 'coverage')
+      @filtered=true
+      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)
+        @coverage_filter='lines_to_cover'
+        filter_lines{|line| line.hits && line.after(to)}
+
+      elsif 'uncovered_lines'==@coverage_filter || 'new_uncovered_lines'==@coverage_filter
+        @coverage_filter='uncovered_lines'
+        filter_lines{|line| line.hits && line.hits==0 && line.after(to)}
+
+      elsif 'conditions_to_cover'==@coverage_filter || 'branch_coverage'==@coverage_filter ||
+            'new_conditions_to_cover'==@coverage_filter || 'new_branch_coverage'==@coverage_filter
+        @coverage_filter='conditions_to_cover'
+        filter_lines{|line| line.conditions && line.conditions>0 && line.after(to)}
+
+      elsif 'uncovered_conditions'==@coverage_filter || 'new_uncovered_conditions'==@coverage_filter
+        @coverage_filter='uncovered_conditions'
+        filter_lines{|line| line.conditions && line.covered_conditions && line.covered_conditions<line.conditions && line.after(to)}
+      end
     end
     render :action => 'index', :layout => !request.xhr?
   end
@@ -182,22 +205,12 @@ class ResourceController < ApplicationController
     end
 
     if !@expanded && @lines
-      @lines.each_with_index do |line,index|
-        if line.violations?
-          for i in index-4..index+4
-            @lines[i].hidden=false if i>=0 && i<@lines.size
-          end
-        elsif line.hidden==nil
-          line.hidden=true
-        end
-      end
+      filter_lines{|line| line.violations?}
     end
     render :action => 'index', :layout => !request.xhr?
   end
   
   
-  
-
   def render_source
     load_sources()
     filter_lines_by_date()
@@ -208,17 +221,33 @@ class ResourceController < ApplicationController
   def filter_lines_by_date
     if @period
       @filtered=true
-      to=@snapshot.period_datetime(@period)
+      to=Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000)
       if to
         @lines.each do |line|
-          line.hidden=true if line.datetime==nil || line.datetime<to
+          line.flag_as_hidden() if !line.after(to)
         end
       end
     end
   end
 
+  def filter_lines(&block)
+    @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
+        end
+        line.flag_as_highlighted()
+        for i in index+1..index+4
+          @lines[i].flag_as_highlight_context() if i<@lines.size
+        end
+      else
+        line.flag_as_hidden()
+      end
+    end
+  end
+
   class Line
-    attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :deprecated_conditions_label
+    attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :highlighted, :deprecated_conditions_label
 
     def initialize(source)
       @source=source
@@ -242,8 +271,39 @@ class ResourceController < ApplicationController
       end
     end
 
-    def date
-      @datetime ? @datetime.to_date : nil
+    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?
+      !hidden? && @highlighted==true
     end
 
     def deprecated_conditions_label=(label)
@@ -263,14 +323,11 @@ class ResourceController < ApplicationController
     end
   end
 
-  
-  
-
   def render_extension()
     render :action => 'extension', :layout => !request.xhr?
   end
 
-def render_nothing()
+  def render_nothing()
     render :action => 'nothing', :layout => !request.xhr?
   end
 end
\ No newline at end of file
index 1e86caee7c8f4b2048d55482f8bf573a653b3cd7..3cb70e0395f52a320e65c3ed91b5cab7886173d0 100644 (file)
@@ -33,7 +33,7 @@
       <%   first=false
          end %>
       
-      <% if @snapshot.project_snapshot.periods? && !@display_violations %>
+      <% if @scm_available && !@display_violations && @snapshot.project_snapshot.periods?  %>
         <td class="<%= 'first' if first -%>">
           <select id="period" name="period" onchange="applyOptions()">
             <option value="">Time changes...</option>
         </td>
 
         <td class="<%= 'first' if first -%>"><%= render :partial => 'rules_filter' -%></td>
-      <% end %>
+      <%   first=false
+         end %>
+
+        <% if @display_coverage %>
+        <td class="<%= 'first' if first -%>">
+          <select id="coverage_filter" name="coverage_filter" onchange="applyOptions()">
+            <option value="lines_to_cover" <%= 'selected' if @coverage_filter=='lines_to_cover' -%>>Lines to cover</option>
+            <option value="uncovered_lines" <%= 'selected' if @coverage_filter=='uncovered_lines' -%>>Uncovered lines</option>
+            <option value="conditions_to_cover" <%= 'selected' if @coverage_filter=='conditions_to_cover' -%>>Branches to cover</option>
+            <option value="uncovered_conditions" <%= 'selected' if @coverage_filter=='uncovered_conditions' -%>>Uncovered branches</option>
+          </select>
+        </td>
+      <%   first=false
+         end %>
       </tr>
     </table>
   </form>
index bc1af726fb110287190fbf6f14d95c14773c22bf..a2d0beedaa406f452e46a4cbf8010c6ff7191bbf 100644 (file)
@@ -27,7 +27,7 @@
   <% else %>
     <script>function loadTab(url) {$('resource-loading').show();document.location.href=url;return false;}</script>
     <% @extensions.each do |extension| %>
-      <li><a href="#" onClick="loadTab('<%= url_for(:overwrite_params => {:tab => extension.getId()}) -%>')" class="<%= 'selected' if @extension.getId()==extension.getId() -%>"><%= extension.getTitle() -%></a></li>
+      <li><a href="#" onClick="loadTab('<%= url_for(:overwrite_params => {:tab => extension.getId(), :metric => nil}) -%>')" class="<%= 'selected' if @extension.getId()==extension.getId() -%>"><%= extension.getTitle() -%></a></li>
     <% end %>
   <% end %>
   <li>
index 9036ceba9757b28b2d1ec08359bf1442f36d273b..56fa8892814379d7beba519d67722e84c0fbe5b3 100644 (file)
     first_section=true
     has_displayed_lines=false
     @lines.each_with_index do |line, index|
-      if line.hidden
+      if line.hidden? && !@expanded
         previous_hidden=true
         next
       end
-      has_displayed_lines=true
 
       if previous_hidden && !first_section
        current_revision=nil
       first_section=false
 
       status=hits_status=conditions_status=''
-      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'
+      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 line.hits
-          status=(line.hits>0 ? '' : 'ko')
+        elsif @display_violations
+          status="sev#{line.violation_severity}"
         end
-      elsif @display_violations
-        status="sev#{line.violation_severity}"
       end
   %>
   <tr>
     <%
          if current_revision!=line.revision
            current_revision=line.revision
-           title = "Revision #{h(line.revision)} ยป #{l(line.datetime) if line.datetime}"
+           title = "Revision #{h(line.revision)}"
     %>
-            <td class="scm revision"><span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= l(line.date) if line.date -%></a></span> <span class="author"><%= h(line.author) -%></span></td>
+            <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 %>
     <td class="lid <%= ' section' if line.violations? -%>" id="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 -%>"><%= line.hits -%></td>
       <td class="ind <%= conditions_status -%>">
         <% if line.deprecated_conditions_label -%>
           <%= line.covered_conditions -%>/<%= line.conditions -%>
         <% end %>
       </td>
+      <% else %>
+        <td class="ind"> </td>
+        <td class="ind"> </td>
+      <% end %>
     <% end %>
     <td class="line <%= status -%>">
       <pre><%= line.source -%></pre>