]> source.dussan.org Git - sonarqube.git/commitdiff
Fix widget properties with type METRIC
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 8 Oct 2012 14:12:12 +0000 (16:12 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 8 Oct 2012 14:34:10 +0000 (16:34 +0200)
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/properties_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb

index 465d2ada0b472c28f1b626ffe77eebdccdfd005a..f5c9a89d69c9ad0ce2bd12dae6d380a64879874e 100644 (file)
@@ -715,7 +715,10 @@ module ApplicationHelper
 
     metrics_by_domain=metrics.sort_by(&:short_name).inject({}) { |h, metric| h[metric.domain]||=[]; h[metric.domain]<<[metric.short_name, metric.key]; h }
 
-    html = select_tag(name, grouped_options_for_select(metrics_by_domain, options[:selected_key], select_tag_prompt), :multiple => options[:multiple], :disabled => options[:disabled])
+    html = select_tag(name, grouped_options_for_select(metrics_by_domain, options[:selected_key], select_tag_prompt),
+                      :multiple => options[:multiple],
+                      :disabled => options[:disabled],
+                      :id => html_id)
     js = "$j('##{html_id}').select2({#{js_options.map{|k,v| "#{k}:#{v}"}.join(',')}});"
     "#{html}<script>#{js}</script>"
   end
index f2809b086bfc159b9f7837e8124135dca8b25845..ea98146eabb1a96fb779223d77ffe0fd0f595d29 100644 (file)
 #
 module PropertiesHelper
 
-  def property_input_field(key, type, value, options, additionalOptions = {})
+  # html_options support :
+  # :html_id - the id of the generated HTML element
+  #
+  def property_input_field(key, type, value, options, html_options = {})
     if type==PropertyType::TYPE_STRING
-      text_field_tag key, value, {:size => 25}.update(additionalOptions)
+      text_field_tag key, value, {:size => 25}.update(html_options)
 
     elsif type==PropertyType::TYPE_TEXT
-      text_area_tag key, value, {:rows => '6', :style => 'width: 100%'}.update(additionalOptions)
+      text_area_tag key, value, {:rows => '6', :style => 'width: 100%'}.update(html_options)
 
     elsif type==PropertyType::TYPE_PASSWORD
-      password_field_tag key, value, {:size => 25}.update(additionalOptions)
+      password_field_tag key, value, {:size => 25}.update(html_options)
 
     elsif type==PropertyType::TYPE_BOOLEAN
-      (hidden_field_tag key, 'false', additionalOptions) + (check_box_tag key, 'true', value=='true', additionalOptions)
+      (hidden_field_tag key, 'false', html_options) + (check_box_tag key, 'true', value=='true', html_options)
 
     elsif type==PropertyType::TYPE_INTEGER
-      text_field_tag key, value, {:size => 10}.update(additionalOptions)
+      text_field_tag key, value, {:size => 10}.update(html_options)
 
     elsif type==PropertyType::TYPE_FLOAT
-      text_field_tag key, value, {:size => 10}.update(additionalOptions)
+      text_field_tag key, value, {:size => 10}.update(html_options)
 
     elsif type==PropertyType::TYPE_METRIC
-      metric_select_tag key, metrics_filtered_by(options), :selected_key => value, :allow_empty => true
+      metric_select_tag key, metrics_filtered_by(options), {:selected_key => value, :allow_empty => true}.update(html_options)
 
     elsif type==PropertyType::TYPE_REGULAR_EXPRESSION
-      text_field_tag key, value, {:size => 25}.update(additionalOptions)
+      text_field_tag key, value, {:size => 25}.update(html_options)
 
     elsif type==PropertyType::TYPE_FILTER
       user_filters = options_key(value, ::Filter.find(:all, :conditions => ['user_id=?', current_user.id]).sort_by(&:id))
       shared_filters = options_key(value, ::Filter.find(:all, :conditions => ['(user_id<>? or user_id is null) and shared=?', current_user.id, true]).sort_by(&:id))
 
-      filters_combo = select_tag key, option_group('My Filters', user_filters) + option_group('Shared Filters', shared_filters), additionalOptions
+      filters_combo = select_tag key, option_group('My Filters', user_filters) + option_group('Shared Filters', shared_filters), html_options
       filter_link = link_to message('widget.filter.edit'), {:controller => :filters, :action => :manage}, :class => 'link-action'
 
       "#{filters_combo} #{filter_link}"
 
     else
-      hidden_field_tag key, additionalOptions
+      hidden_field_tag key, html_options
     end
   end
 
index 00de6bec37c5159d1d78e5f16ded6e827b12caa3..1766c94faff97a13f624fb6b6aad942605d9e850 100644 (file)
@@ -20,8 +20,8 @@
 module WidgetPropertiesHelper
   include PropertiesHelper
 
-  def property_value_field(definition, value)
-    property_input_field definition.key, definition.type.name, value.nil? ? definition.defaultValue : value, definition.options
+  def property_value_field(definition, value, widget)
+    property_input_field definition.key, definition.type.name, value.nil? ? definition.defaultValue : value, definition.options, {:html_id => "prop-#{widget.key.parameterize}-#{definition.key.parameterize}"}
   end
 
 end
index bcac687922dda7cd1a8323bf4cd00d24df72f345..4cd3b99551fabcf84fe3585bd406014b9ef06b57 100644 (file)
@@ -24,7 +24,7 @@
       <tr>
         <td class="form-key-cell"><%= property_def.key() -%><%= " *" unless property_def.optional() -%></td>
         <td class="form-val-cell" id="row_<%= property_def.key() -%>">
-          <%= property_value_field(property_def, widget.property_text_value(property_def.key())) -%>
+          <%= property_value_field(property_def, widget.property_text_value(property_def.key()), widget) -%>
           <div class="form-val-note">
             <%= message("widget." + widget.key + ".param." + property_def.key(), :default => property_def.description()) -%>
           </div>