]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2218 improve drilldown page in order to display variations
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 1 Mar 2011 13:02:53 +0000 (14:02 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 1 Mar 2011 13:02:53 +0000 (14:02 +0100)
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/code_coverage.html.erb
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb

index 17a7f673f0fc645a78fb49e7983e0375476c326e..6110cdac682708cde0c5ac26ee2b123fbcc1684c 100644 (file)
         <% line_coverage=measure(Metric::LINE_COVERAGE)
           if line_coverage %>
           <p>
-            <%= format_measure(line_coverage, :suffix => ' line coverage', :url => url_for_drilldown(Metric::UNCOVERED_LINES, :highlight =>  Metric::LINE_COVERAGE)) %>
+            <%= format_measure(line_coverage, :suffix => ' line coverage', :url => url_for_drilldown('uncovered_lines', :highlight =>  'line_coverage')) %>
             <%= dashboard_configuration.selected_period? ? format_variation(line_coverage) : trend_icon(line_coverage) -%>
           </p>
         <% end %>
         <% branch_coverage=measure(Metric::BRANCH_COVERAGE)
           if branch_coverage %>
           <p>
-            <%= format_measure(branch_coverage, :suffix => ' branch coverage', :url => url_for_drilldown(Metric::UNCOVERED_CONDITIONS, :highlight =>  Metric::BRANCH_COVERAGE)) %>
+            <%= format_measure(branch_coverage, :suffix => ' branch coverage', :url => url_for_drilldown('uncovered_conditions', :highlight =>  'branch_coverage')) %>
             <%= dashboard_configuration.selected_period? ? format_variation(branch_coverage) : trend_icon(branch_coverage) -%>
           </p>
         <% end %>
@@ -85,9 +85,15 @@ if dashboard_configuration.selected_period?
 %>
     <h3>on changed code (<%= new_lines.to_i -%> new lines to cover)</h3>
     <p>
-      Coverage: <%= new_coverage.format_numeric_value(variation_value(new_coverage)) -%><br/>
-      Line coverage: <%= new_line_coverage.format_numeric_value(variation_value(new_line_coverage)) -%><br/>
-      Branch coverage: <%= new_branch_coverage.format_numeric_value(variation_value(new_branch_coverage)) -%>
+      <% if new_coverage %>
+        Coverage: <a href="<%= url_for_drilldown('new_coverage', :period => dashboard_configuration.period_index, :only_periods => true) -%>"><%= new_coverage.format_numeric_value(variation_value(new_coverage)) -%></a><br/>
+      <% end %>
+      <% if new_line_coverage %>
+        Line coverage: <a href="<%= url_for_drilldown('new_uncovered_lines', :highlight => 'new_line_coverage', :period => dashboard_configuration.period_index, :only_periods => true) -%>"><%= new_line_coverage.format_numeric_value(variation_value(new_line_coverage)) -%></a><br/>
+      <% end %>
+      <% if new_branch_coverage %>
+        Branch coverage: <a href="<%= url_for_drilldown('new_uncovered_conditions', :highlight => 'new_branch_coverage', :period => dashboard_configuration.period_index, :only_periods => true) -%>"><%= new_branch_coverage.format_numeric_value(variation_value(new_branch_coverage)) -%></a>
+      <% end %>
     </p>
 <%
     end
index 80f9451ec421bfb5956ebde07b75f56291de03ad..f6dac6dbf828ae9a2cffdef68455d674c7bfa33c 100644 (file)
@@ -259,6 +259,7 @@ public final class CoreMetrics {
       .setDescription("Coverage of new/changed code")
       .setDirection(Metric.DIRECTION_BETTER)
       .setQualitative(true)
+      .setHidden(true)
       .setDomain(DOMAIN_TESTS)
       .setWorstValue(0.0)
       .setBestValue(100.0)
@@ -293,6 +294,7 @@ public final class CoreMetrics {
       .setDescription("New uncovered lines")
       .setDirection(Metric.DIRECTION_WORST)
       .setDomain(DOMAIN_TESTS)
+      .setHidden(true)
       .setFormula(new SumChildValuesFormula(false))
       .create();
 
@@ -313,6 +315,7 @@ public final class CoreMetrics {
       .setQualitative(true)
       .setWorstValue(0.0)
       .setBestValue(100.0)
+      .setHidden(true)
       .setDomain(DOMAIN_TESTS)
       .create();
 
@@ -354,6 +357,7 @@ public final class CoreMetrics {
       .setDescription("New uncovered conditions")
       .setDirection(Metric.DIRECTION_WORST)
       .setDomain(DOMAIN_TESTS)
+      .setHidden(true)
       .setFormula(new SumChildValuesFormula(false))
       .create();
 
@@ -370,10 +374,11 @@ public final class CoreMetrics {
 
   public static final String NEW_BRANCH_COVERAGE_KEY = "new_branch_coverage";
   public static final Metric NEW_BRANCH_COVERAGE = new Metric.Builder(NEW_BRANCH_COVERAGE_KEY, Metric.ValueType.PERCENT)
-      .setName("NEw branch coverage")
+      .setName("New branch coverage")
       .setDescription("Branch coverage of new/changed code")
       .setDirection(Metric.DIRECTION_BETTER)
       .setQualitative(true)
+      .setHidden(true)
       .setDomain(DOMAIN_TESTS)
       .setWorstValue(0.0)
       .setBestValue(100.0)
index 5462e26496028a973b086bdece5016333c76b2f8..217766f759168cf794e283b755b04ba5628586c6 100644 (file)
@@ -48,7 +48,10 @@ class DrilldownController < ApplicationController
       @characteristic=Characteristic.find(:first, :select => 'id', :include => 'quality_model', :conditions => ['quality_models.name=? AND characteristics.kee=? AND characteristics.enabled=?', params[:model], params[:characteristic], true])
     end
     options[:characteristic]=@characteristic
-
+    if params[:period]
+      @period=params[:period].to_i
+      options[:period]=@period
+    end
 
     # load data
     @drilldown = Drilldown.new(@project, @metric, selected_rids, options)
@@ -66,10 +69,10 @@ class DrilldownController < ApplicationController
 
     # variation measures
     if params[:period].blank?
-      @period_index=nil
+      @period=nil
       metric_prefix = ''
     else
-      @period_index=params[:period].to_i
+      @period=params[:period].to_i
       metric_prefix = 'new_'
     end
 
@@ -93,7 +96,7 @@ class DrilldownController < ApplicationController
 
 
     # options for Drilldown
-    options={:exclude_zero_value => true, :period_index => @period_index}
+    options={:exclude_zero_value => true, :period => @period}
     if @rule
       params[:rule]=@rule.key  # workaround for SONAR-1767 : the javascript hash named "rp" in the HTML source must contain the rule key, but not the rule id
       options[:rule_id]=@rule.id
index 630cc6598c45092b7240eb1541eaed7fd2c0862c..fe1c0da82f044a59363e76df3b30a1a6a650c9e2 100644 (file)
@@ -199,13 +199,20 @@ module ApplicationHelper
   # * <tt>:resource</tt> - id or key of the selected resource
   # * <tt>:highlight</tt> - key of the metric to highlight, different than the metric to drilldown.
   #  *<tt>:viewer_plugin_key</tt> - the default GWT plugin to be used when clicking on a resource in the drilldown to view it's source
+  # * <tt>:period</tt> - period index
+  # * <tt>:only_periods</tt> - true if only v
   #
   # === Examples
   #
   #   url_for_drilldown('ncloc')
   #   url_for_drilldown('ncloc', {:resource => 'org.apache.struts:struts-parent', :highlight => 'lines'})
   #   url_for_drilldown('ncloc', {:resource => 'org.apache.struts:struts-parent', :viewer_plugin_key => 'org.sonar.plugins.core.violationsviewer.GwtViolationsViewer'})
+  #
   def url_for_drilldown(metric_or_measure, options={})
+    if options[:resource].nil? && !@project
+      return ''
+    end
+
     if metric_or_measure.is_a? ProjectMeasure
       metric_key = metric_or_measure.metric.key
     elsif metric_or_measure.is_a? Metric
@@ -214,16 +221,9 @@ module ApplicationHelper
       metric_key = metric_or_measure
     end
 
-    if options[:resource]
-      url_for(:controller => 'drilldown', :action => 'measures', :id => options[:resource], :metric => metric_key,
-        :highlight => options[:highlight], :viewer_plugin_key => options[:viewer_plugin_key], :model => options[:model], :characteristic => options[:characteristic])
-    elsif @project
-      url_for(:controller => 'drilldown', :action => 'measures', :id => @project.id, :metric => metric_key,
-        :highlight => options[:highlight], :viewer_plugin_key => options[:viewer_plugin_key],
-        :model => options[:model], :characteristic => options[:characteristic])
-    else
-      ''
-    end
+    url_params={:controller => 'drilldown', :action => 'measures', :metric => metric_key, :id => options[:resource]||@project.id}
+    
+    url_for(options.merge(url_params))
   end
 
   #
@@ -258,7 +258,9 @@ module ApplicationHelper
       link_rel=''
       show_link= !options[:url].blank?
 
-      if m.metric.val_type==Metric::VALUE_TYPE_LEVEL
+      if options[:period]
+        html=m.format_numeric_value(m.variation(options[:period].to_i))
+      elsif m.metric.val_type==Metric::VALUE_TYPE_LEVEL
         html=image_tag("levels/#{m.data.downcase}.png") unless m.data.blank?
       else
         html=m.formatted_value
@@ -456,7 +458,7 @@ module ApplicationHelper
   # === Examples
   # variation_value('ncloc')
   # variation_value(measure('ncloc'))
-  # variation_value('ncloc', :index => 3)
+  # variation_value('ncloc', :period => 3)
   #
   def variation_value(metric_or_measure, options={})
     if metric_or_measure.is_a?(ProjectMeasure)
@@ -465,7 +467,7 @@ module ApplicationHelper
       m = @snapshot.measure(metric_or_measure)
     end
 
-    index=options[:index]
+    index=options[:period]||options[:index]
     if index.nil? && defined?(@dashboard_configuration) && @dashboard_configuration.selected_period?
       index = @dashboard_configuration.period_index
     end
@@ -480,12 +482,12 @@ module ApplicationHelper
   #
   # === Optional parameters
   # * color: true|false. Default is true.
-  # * index: integer between 1 and 5. By default the index is defined by the dashboard variation select-box
+  # * period: integer between 1 and 5. By default the index is defined by the dashboard variation select-box
   # * style: light|normal. Default is normal (parenthesis + bold)
   #
   # === Examples
   # format_variation('ncloc')
-  # format_variation(measure('ncloc'), :index => 3, :color => true)
+  # format_variation(measure('ncloc'), :period => 3, :color => true)
   #
   def format_variation(metric_or_measure, options={})
     if metric_or_measure.is_a?(ProjectMeasure)
index ecfa0a7f6b06f4cbbad48fd37b261ef67f2b84d6..5fdeb5562d8a4bf50565a9a7c7d9ed18e9d06472 100644 (file)
@@ -45,7 +45,7 @@ class DrilldownColumn
     @scope=scope
     @snapshot = snapshot
 
-    value_column = (options[:period_index] ? "variation_value_#{options[:period_index]}" : 'value')
+    value_column = (options[:period] ? "variation_value_#{options[:period]}" : 'value')
     order="project_measures.#{value_column}"
     if metric.direction<0
       order += ' DESC'
index 4ecb2881b59f31d9c56e2ef2e7c4c5c3d1b3571b..6698666f014e37260237d0eb0372c2f83503daf5 100644 (file)
@@ -4,10 +4,12 @@
 <div class="dashbox">
   <% if @characteristic %>
     <h3><%= @highlighted_metric.short_name -%> / <%= h(@characteristic.name(true)) -%></h3>
-    <p class="big"><%= html_measure(@snapshot.characteristic_measure(@highlighted_metric, @characteristic), nil, true, nil, '', false) %></p>
+    <p class="big"><%= format_measure(@snapshot.characteristic_measure(@highlighted_metric, @characteristic)) %></p>
   <% else %>
     <h3><%= @highlighted_metric.short_name -%></h3>
-    <p class="big"><%= html_measure(@snapshot.measure(@highlighted_metric.key), nil, true, nil, '', false) %></p>
+    <p class="big">
+      <%= format_measure(@snapshot.measure(@highlighted_metric.key), :period => @period) %>
+    </p>
   <% end %>
 </div>
 &nbsp;<!-- keep &nbsp; for IE6 ! -->
@@ -15,7 +17,7 @@
 <table id="drilldown" class="width100">
 <% if @highlighted_metric!=@metric %>
 <tr>
-<td colspan="<%= @drilldown.columns.size -%>">Drilldown on <b><span id="m_<%= u @metric.key -%>"><%= @snapshot.f_measure(@metric.key) -%><span> <%= @metric.short_name -%></b></h3></td>
+<td colspan="<%= @drilldown.columns.size -%>">Drilldown on <b><span id="m_<%= u @metric.key -%>"><%= @snapshot.f_measure(@metric.key) -%></span> <%= @metric.short_name -%></b></td>
 </tr>
 <tr>
 <% end
@@ -49,7 +51,7 @@
           <% end %>
         </td>
         <td class="right last" >
-           <%= format_measure(measure, :skip_span_id => true) -%>
+            <%= format_measure(measure, :skip_span_id => true, :period => @period) -%>
            <!--[if IE]> &nbsp; &nbsp; <![endif]-->
         </td>
       </tr>
index 1161f1fbe0029f978b68105064d7c3698464194c..3b84bf7f90b22fa07e202aada6101c5c90f3e8a8 100644 (file)
@@ -20,7 +20,7 @@
 </h4>
 </div>
 
-<% if @period_index %>
+<% if @period %>
   <div class="warning">This service is experimental. <a target="faq"  href="http://docs.codehaus.org/display/SONAR/Frequently+Asked+Questions#FrequentlyAskedQuestions-Iamnotgettingexpectednewviolationsinthedifferentialviewsofdrilldown%3F">More</a>.</div>
 <% end %>
 
@@ -32,9 +32,9 @@
   <td align="left" width="1%" nowrap class="column first">
 
        <%
-         value_column = (@period_index ? "variation_value_#{@period_index}" : 'value')
+         value_column = (@period ? "variation_value_#{@period}" : 'value')
                max = 0
-               if @period_index
+               if @period
       blocker_violations=@snapshot.measure('new_blocker_violations')
       critical_violations=@snapshot.measure('new_critical_violations')
       major_violations=@snapshot.measure('new_major_violations')
@@ -67,7 +67,7 @@
    <div class="scrollable">
        <table class="spacedicon" width="100%" id="col_rules">
              <%
-               if @period_index
+               if @period
                  rule_measures=@snapshot.rule_measures(Metric.by_key('new_violations'), @priority_id)
                else
                  rule_measures=@snapshot.rule_measures(Metric.by_key('violations'), @priority_id)
                   %>
                <tr class="<%= clazz -%>">
                       <td width="1%" nowrap>
-                    <a id="<%= "rule#{rule_index}" -%>" title="Click for more on <%= rule.plugin_name -%>: <%= rule.plugin_rule_key -%>" onclick="window.open(this.href,'rule','height=800,width=900,scrollbars=1,resizable=1');return false;" href="<%= url_for :controller => 'rules', :action => 'show', :id => rule.key, :layout => 'false' -%>"><img src="<%= ApplicationController.root_context -%>/images/priority/<%= rule_measure.rule_priority -%>.png"></img></a>
+                    <a id="<%= "rule#{rule_index}" -%>" title="Click for more on <%= rule.plugin_name -%>: <%= rule.plugin_rule_key -%>" onclick="window.open(this.href,'rule','height=800,width=900,scrollbars=1,resizable=1');return false;" href="<%= url_for :controller => 'rules', :action => 'show', :id => rule.key, :layout => 'false' -%>"><img src="<%= ApplicationController.root_context -%>/images/priority/<%= rule_measure.rule_priority -%>.png" /></a>
                           </td>
                       <td>
                          <%= link_to(rule.name, {:overwrite_params => {:rule => rule.key, :sid => nil, :priority => Sonar::RulePriority.to_s(@priority_id)}}, :title => "#{rule.plugin_name}: #{rule.plugin_rule_key}") %>
                    </td>
                    <td class="right" nowrap="nowrap">
-                       <span><%= @period_index ? format_variation(rule_measure, :index => @period_index, :style => 'light') : rule_measure.formatted_value -%></span>
+                       <span><%= @period ? format_variation(rule_measure, :period => @period, :style => 'light') : rule_measure.formatted_value -%></span>
                    </td>
                    <td class="left last">
-                         <%= barchart(:width => 70, :percent => (100 * value / max).to_i, :color => (@period_index ? '#cc0000' : '#777'))  if max>0 %>
+                         <%= barchart(:width => 70, :percent => (100 * value / max).to_i, :color => (@period ? '#cc0000' : '#777'))  if max>0 %>
                          <!--[if IE]> &nbsp; &nbsp; <![endif]-->
                       </td>
                </tr>
    <% end %>
    </td>
    <td class="right last" nowrap>
-       <%= @period_index ? format_variation(measure, :index => @period_index, :style => 'light') : measure.formatted_value -%>
+       <%= @period ? format_variation(measure, :period => @period, :style => 'light') : measure.formatted_value -%>
        <!--[if IE]> &nbsp; &nbsp; <![endif]-->
    </td>
 </tr>