From 6bf95f66f31b5b183c21656d33725a05011124f3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Thu, 30 Jan 2014 16:35:17 +0100 Subject: [PATCH] SONAR-4799 Allow selection of differential metrics in custom measure widget --- .../core/widgets/CustomMeasuresWidget.java | 20 +++++++++---------- .../core/widgets/custom_measures.html.erb | 13 ++++++++++-- .../WEB-INF/app/models/project_measure.rb | 4 ++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java index 640716d7e45..3872d0e214b 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java @@ -24,16 +24,16 @@ import org.sonar.api.web.WidgetProperty; import org.sonar.api.web.WidgetPropertyType; @WidgetProperties({ - @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric4", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric5", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric6", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric7", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric8", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric9", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = "metric10", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}) + @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric4", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric5", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric6", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric7", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric8", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric9", type = WidgetPropertyType.METRIC), + @WidgetProperty(key = "metric10", type = WidgetPropertyType.METRIC) }) public class CustomMeasuresWidget extends CoreWidget { public CustomMeasuresWidget() { diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/custom_measures.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/custom_measures.html.erb index bc8863f29a6..70095e0e1a0 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/custom_measures.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/custom_measures.html.erb @@ -5,6 +5,7 @@ m=(metric ? measure(metric) : nil) measures << m if m end + period = params[:period] unless measures.empty? %> @@ -13,17 +14,25 @@ <% measures.each do |measure| - %> + if measure.visible?(period.to_i) + -%>

<%= measure.metric.short_name -%>

+ <% if measure.value.nil? -%> + <%# This is a differential measure -%> + <%= format_measure(measure, :url => url_for_drilldown(measure, :period => period), :period => period) -%> + <% else -%> + <%# This is a classic measure that can have a differential -%> <%= format_measure(measure, :url => url_for_drilldown(measure)) -%> <%= dashboard_configuration.selected_period? ? format_variation(measure) : trend_icon(measure) -%> + <% end -%>

<% + end end - %> + -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb index d24d27e0198..30adb6fa617 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb @@ -264,6 +264,10 @@ class ProjectMeasure < ActiveRecord::Base value<=>other.value end + def visible?(period) + ! (value.nil? && variation(period).nil?) + end + private def numerical_metric? -- 2.39.5