From 6166547c9aed424caea662a7208cbd6a5c265151 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 7 Mar 2011 16:59:29 +0100 Subject: [PATCH] SONAR-2218 add drilldown on new lines to cover + add period select-box on measures drilldown --- .../core/widgets/code_coverage.html.erb | 8 +++---- .../org/sonar/api/measures/CoreMetrics.java | 3 ++- .../org/sonar/server/ui/DefaultPages.java | 2 +- .../app/controllers/drilldown_controller.rb | 3 +-- .../WEB-INF/app/helpers/application_helper.rb | 1 - .../webapp/WEB-INF/app/models/drilldown.rb | 11 ++++++++- .../app/views/drilldown/measures.html.erb | 24 +++++++++++++++++++ 7 files changed, 42 insertions(+), 10 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 dd0a2ed7656..79c0d1787fb 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 @@ -44,20 +44,20 @@ <% if new_lines.to_i>0 %> <% if new_coverage %>

- <%= new_coverage.format_numeric_value(variation_value(new_coverage))||'-' -%> coverage + <%= new_coverage.format_numeric_value(variation_value(new_coverage))||'-' -%> coverage

<% end %>

- <%= new_lines.to_i -%> new lines to cover + <%= new_lines.to_i -%> new lines to cover

<% if new_line_coverage %>

- <%= new_line_coverage.format_numeric_value(variation_value(new_line_coverage))||'-' -%> line coverage + <%= new_line_coverage.format_numeric_value(variation_value(new_line_coverage))||'-' -%> line coverage

<% end %> <% if new_branch_coverage %>

- <%= new_branch_coverage.format_numeric_value(variation_value(new_branch_coverage))||'-' -%> branch coverage + <%= new_branch_coverage.format_numeric_value(variation_value(new_branch_coverage))||'-' -%> branch coverage

<% 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 d105ad6fa32..5daca1d7e72 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 @@ -264,7 +264,8 @@ public final class CoreMetrics { public static final String NEW_LINES_TO_COVER_KEY = "new_lines_to_cover"; public static final Metric NEW_LINES_TO_COVER = new Metric.Builder(NEW_LINES_TO_COVER_KEY, "New lines to cover", Metric.ValueType.INT) .setDescription("New lines to cover") - .setDirection(Metric.DIRECTION_BETTER) + .setDirection(Metric.DIRECTION_WORST) + .setQualitative(false) .setDomain(DOMAIN_TESTS) .setFormula(new SumChildValuesFormula(false)) .setHidden(true) diff --git a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java index cc5d24a4f26..c8f33678b7d 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java @@ -61,7 +61,7 @@ public final class DefaultPages { @DefaultTab(metrics = {CoreMetrics.COVERAGE_KEY, CoreMetrics.LINES_TO_COVER_KEY, CoreMetrics.UNCOVERED_LINES_KEY, CoreMetrics.LINE_COVERAGE_KEY, CoreMetrics.CONDITIONS_TO_COVER_KEY, CoreMetrics.UNCOVERED_CONDITIONS_KEY, CoreMetrics.BRANCH_COVERAGE_KEY, CoreMetrics.NEW_COVERAGE_KEY, CoreMetrics.NEW_UNCOVERED_LINES_KEY, CoreMetrics.NEW_LINE_COVERAGE_KEY, - CoreMetrics.NEW_LINES_TO_COVER_KEY, CoreMetrics.NEW_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_CONDITIONS_TO_COVER_KEY + CoreMetrics.NEW_LINES_TO_COVER_KEY, CoreMetrics.NEW_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_UNCOVERED_CONDITIONS_KEY }) @UserRole(UserRole.CODEVIEWER) private static final class CoverageTab implements RubyRailsPage { 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 217766f7591..46910f85fb4 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 @@ -25,7 +25,7 @@ class DrilldownController < ApplicationController SECTION=Navigation::SECTION_RESOURCE def measures - @metric = select_metric(params[:metric], Metric::NCLOC) + @metric = select_metric(params[:metric], 'ncloc') @highlighted_metric = Metric.by_key(params[:highlight]) || @metric # selected resources @@ -120,7 +120,6 @@ class DrilldownController < ApplicationController @project = project_key ? Project.by_key(project_key) : nil if @project.nil? render :text => "Project [#{project_key}] not found", :status => 404 - return end end 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 c5c63f84d31..92d4ca39ee5 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,7 +199,6 @@ module ApplicationHelper # * :resource - id or key of the selected resource # * :highlight - key of the metric to highlight, different than the metric to drilldown. # * :period - period index - # * :only_periods - true if only v # # === Examples # 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 5fdeb5562d8..33108f61b8c 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 @@ -18,10 +18,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # class Drilldown - attr_reader :snapshot, :columns + attr_reader :snapshot, :columns, :metric def initialize(resource, metric, selected_resource_ids, options={}) @snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => resource.id}, :include => [:project]) + @metric=metric @columns=[] column=nil @@ -36,6 +37,14 @@ class Drilldown def highlighted_resource @highlighted_resource end + + def display_value? + ProjectMeasure.exists?(["snapshot_id=? and metric_id=? and value is not null", @snapshot.id, @metric.id]) + end + + def display_period?(period_index) + ProjectMeasure.exists?(["snapshot_id=? and metric_id=? and variation_value_#{period_index.to_i} is not null", @snapshot.id, @metric.id]) + end end class DrilldownColumn 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 cc6a0287ccb..329dfd64cfb 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 @@ -1,5 +1,29 @@ <%= render :partial => 'header' -%> + + +<% if params[:period] && @snapshot.project_snapshot.periods? %> +
+

+
+ + + +
+

+
+<% end %> + + + +
<% if @characteristic %>

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

-- 2.39.5