From 10b2eb451517431d02da2143cfc2958f1a9411be Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Tue, 1 Mar 2011 14:02:53 +0100 Subject: [PATCH] SONAR-2218 improve drilldown page in order to display variations --- .../core/widgets/code_coverage.html.erb | 16 +++++++--- .../org/sonar/api/measures/CoreMetrics.java | 7 +++- .../app/controllers/drilldown_controller.rb | 11 ++++--- .../WEB-INF/app/helpers/application_helper.rb | 32 ++++++++++--------- .../webapp/WEB-INF/app/models/drilldown.rb | 2 +- .../app/views/drilldown/measures.html.erb | 10 +++--- .../app/views/drilldown/violations.html.erb | 16 +++++----- 7 files changed, 56 insertions(+), 38 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/code_coverage.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/code_coverage.html.erb index 17a7f673f0f..6110cdac682 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/code_coverage.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/code_coverage.html.erb @@ -18,14 +18,14 @@ <% line_coverage=measure(Metric::LINE_COVERAGE) if line_coverage %>

- <%= 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) -%>

<% end %> <% branch_coverage=measure(Metric::BRANCH_COVERAGE) if branch_coverage %>

- <%= 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) -%>

<% end %> @@ -85,9 +85,15 @@ if dashboard_configuration.selected_period? %>

on changed code (<%= new_lines.to_i -%> new lines to cover)

- Coverage: <%= new_coverage.format_numeric_value(variation_value(new_coverage)) -%>
- Line coverage: <%= new_line_coverage.format_numeric_value(variation_value(new_line_coverage)) -%>
- Branch coverage: <%= new_branch_coverage.format_numeric_value(variation_value(new_branch_coverage)) -%> + <% if new_coverage %> + Coverage: <%= new_coverage.format_numeric_value(variation_value(new_coverage)) -%>
+ <% end %> + <% if new_line_coverage %> + Line coverage: <%= new_line_coverage.format_numeric_value(variation_value(new_line_coverage)) -%>
+ <% end %> + <% if new_branch_coverage %> + Branch coverage: <%= new_branch_coverage.format_numeric_value(variation_value(new_branch_coverage)) -%> + <% end %>

<% end diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index 80f9451ec42..f6dac6dbf82 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -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) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb index 5462e264960..217766f7591 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb @@ -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 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 630cc6598c4..fe1c0da82f0 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 @@ -199,13 +199,20 @@ module ApplicationHelper # * :resource - id or key of the selected resource # * :highlight - key of the metric to highlight, different than the metric to drilldown. # *:viewer_plugin_key - the default GWT plugin to be used when clicking on a resource in the drilldown to view it's source + # * :period - period index + # * :only_periods - 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) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb index ecfa0a7f6b0..5fdeb5562d8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb @@ -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' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb index 4ecb2881b59..6698666f014 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb @@ -4,10 +4,12 @@
<% if @characteristic %>

<%= @highlighted_metric.short_name -%> / <%= h(@characteristic.name(true)) -%>

-

<%= html_measure(@snapshot.characteristic_measure(@highlighted_metric, @characteristic), nil, true, nil, '', false) %>

+

<%= format_measure(@snapshot.characteristic_measure(@highlighted_metric, @characteristic)) %>

<% else %>

<%= @highlighted_metric.short_name -%>

-

<%= html_measure(@snapshot.measure(@highlighted_metric.key), nil, true, nil, '', false) %>

+

+ <%= format_measure(@snapshot.measure(@highlighted_metric.key), :period => @period) %> +

<% end %>
  @@ -15,7 +17,7 @@ <% if @highlighted_metric!=@metric %> - + <% end @@ -49,7 +51,7 @@ <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb index 1161f1fbe00..3b84bf7f90b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb @@ -20,7 +20,7 @@ -<% if @period_index %> +<% if @period %>
This service is experimental. More.
<% end %> @@ -32,9 +32,9 @@
Drilldown on <%= @snapshot.f_measure(@metric.key) -%> <%= @metric.short_name -%>Drilldown on <%= @snapshot.f_measure(@metric.key) -%> <%= @metric.short_name -%>
- <%= format_measure(measure, :skip_span_id => true) -%> + <%= format_measure(measure, :skip_span_id => true, :period => @period) -%>
<% - 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 @@
<% - 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) @@ -101,16 +101,16 @@ %> @@ -163,7 +163,7 @@ <% end %> -- 2.39.5
- " 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' -%>"> + " 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' -%>"> <%= 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}") %> - <%= @period_index ? format_variation(rule_measure, :index => @period_index, :style => 'light') : rule_measure.formatted_value -%> + <%= @period ? format_variation(rule_measure, :period => @period, :style => 'light') : rule_measure.formatted_value -%> - <%= 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 %>
- <%= @period_index ? format_variation(measure, :index => @period_index, :style => 'light') : measure.formatted_value -%> + <%= @period ? format_variation(measure, :period => @period, :style => 'light') : measure.formatted_value -%>