diff options
7 files changed, 30 insertions, 16 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 20be067423e..6410d64e60b 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.*; @WidgetCategory({"Measures"}) @WidgetProperties( { - @WidgetProperty(key = "metric1", type = WidgetPropertyType.STRING, description = "Key as defined in <a href='http://docs.codehaus.org/display/SONAR/Metric+definitions'>this list</a>"), - @WidgetProperty(key = "metric2", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric3", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric4", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric5", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric6", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric7", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric8", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric9", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "metric10", type = WidgetPropertyType.STRING) + @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 AbstractRubyTemplate implements RubyRailsWidget { 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 8d7422760ac..bc6c5d5b94e 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 @@ -6,7 +6,7 @@ if m %> <div class="dashbox"> - <p class="title"><%= m.metric.short_name -%></p> + <p class="title"><%= metric.short_name -%></p> <p> <span class="big"><%= format_measure(m, :url => url_for_drilldown(m)) -%></span> <%= dashboard_configuration.selected_period? ? format_variation(m) : trend_icon(m) -%> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetPropertyType.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetPropertyType.java index 35c58e560f1..8037ebf2ab6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetPropertyType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetPropertyType.java @@ -20,5 +20,9 @@ package org.sonar.api.web; public enum WidgetPropertyType { - INTEGER, BOOLEAN, FLOAT, STRING + INTEGER, + BOOLEAN, + FLOAT, + STRING, + METRIC // @since 2.10 } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb index f86d510e0bb..6d7fbd7f069 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb @@ -19,6 +19,7 @@ # module DashboardHelper include WidgetPropertiesHelper + include MetricsHelper def formatted_value(measure, default='') measure ? measure.formatted_value : default diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/metrics_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/metrics_helper.rb index f94dddf81ee..ef3725df381 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/metrics_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/metrics_helper.rb @@ -23,7 +23,7 @@ module MetricsHelper metrics.map {|m| m.domain(translate)}.uniq.compact.sort end - def options_grouped_by_domain(metrics, selected_key='') + def options_grouped_by_domain(metrics, selected_key='', options={}) metrics_per_domain={} metrics.each do |metric| domain=metric.domain || '' @@ -32,10 +32,14 @@ module MetricsHelper end html='' + if options[:include_empty]==true + html+= "<option value=''></option>" + end + metrics_per_domain.keys.sort.each do |domain| html += "<optgroup label=\"#{html_escape(domain)}\">" metrics_per_domain[domain].each do |m| - selected_attr = " selected='selected'" if (m.key==selected_key || m.id==selected_key) + selected_attr = (m.key==selected_key || m.id==selected_key) ? " selected='selected'" : '' html += "<option value='#{html_escape(m.key)}'#{selected_attr}>#{html_escape(m.short_name)}</option>" end html += '</optgroup>' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb index a44fe8abf29..c5c358ee8b8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb @@ -18,8 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # module WidgetPropertiesHelper - - + def property_value_field(definition, value) val=value || definition.defaultValue() if definition.type.name()==WidgetProperty::TYPE_INTEGER @@ -31,6 +30,9 @@ module WidgetPropertiesHelper elsif definition.type.name()==WidgetProperty::TYPE_BOOLEAN check_box_tag definition.key(), "true", val=='true' + elsif definition.type.name()==WidgetProperty::TYPE_METRIC + select_tag definition.key(), options_grouped_by_domain(Metric.all.select{|m| m.display?}, val, :include_empty => true) + elsif definition.type.name()==WidgetProperty::TYPE_STRING text_field_tag definition.key(), val, :size => 10 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb index a47ba81b6e5..4aa241e38d3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/widget_property.rb @@ -22,6 +22,7 @@ class WidgetProperty < ActiveRecord::Base TYPE_BOOLEAN = 'BOOLEAN' TYPE_FLOAT = 'FLOAT' TYPE_STRING = 'STRING' + TYPE_METRIC = 'METRIC' belongs_to :widget @@ -44,6 +45,8 @@ class WidgetProperty < ActiveRecord::Base Float(value) when TYPE_BOOLEAN value=='true' + when TYPE_METRIC + Metric.by_key(value.to_s) else value end |