]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3692 Fix issue with name generation and improve widget property i18n
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 23 Jan 2013 08:54:19 +0000 (09:54 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 23 Jan 2013 08:54:31 +0000 (09:54 +0100)
13 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java
sonar-server/src/main/webapp/WEB-INF/app/helpers/properties_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_BOOLEAN.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_FLOAT.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_INTEGER.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_STRING.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_TEXT.html.erb

index eb3f4b05d14d3ce4e0c500f7780b350067dd1820..bd7015dfddff071b902d32258c3462b095cf22e8 100644 (file)
@@ -124,46 +124,6 @@ import java.util.List;
         project = false,
         global = true,
         category = CoreProperties.CATEGORY_GENERAL),
-    @Property(
-        key = "sonar.test",
-        defaultValue = "complexity",
-        name = "Metric",
-        project = true,
-        global = true,
-        category = CoreProperties.CATEGORY_GENERAL,
-        type = PropertyType.METRIC),
-    @Property(
-        key = "sonar.testmetric",
-        name = "Metric",
-        project = true,
-        global = true,
-        category = CoreProperties.CATEGORY_GENERAL,
-        type = PropertyType.METRIC),
-    @Property(
-        key = "sonar.test2",
-        name = "Single",
-        defaultValue = "2",
-        project = true,
-        global = true,
-        category = CoreProperties.CATEGORY_GENERAL,
-        type = PropertyType.SINGLE_SELECT_LIST,
-        options = {"1", "2", "3"}),
-    @Property(
-        key = "sonar.testsinglelist",
-        name = "Single2",
-        project = true,
-        global = true,
-        category = CoreProperties.CATEGORY_GENERAL,
-        type = PropertyType.SINGLE_SELECT_LIST,
-        options = {"1", "2", "3"}),
-    @Property(
-        key = "sonar.test3",
-        name = "Password",
-        project = true,
-        global = true,
-        category = CoreProperties.CATEGORY_GENERAL,
-        type = PropertyType.PASSWORD,
-        options = {"1", "2", "3"}),
     @Property(
         key = CoreProperties.LINKS_HOME_PAGE,
         defaultValue = "",
index 930e5b02dfbeab7ae546094779a38fcc34a53b8b..a7f2e322d81dbce1d0f6acb65d656e0de858926d 100644 (file)
@@ -26,31 +26,12 @@ import org.sonar.api.web.WidgetPropertyType;
 
 @WidgetCategory("History")
 @WidgetProperties({
-  @WidgetProperty(key = "chartTitle", type = WidgetPropertyType.STRING, description = "chartTitle description"),
-  @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc", options = {WidgetConstants.FILTER_OUT_NEW_METRICS}, description = "metric1 description"),
-  @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}, description = "metric2 description"),
-  @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}, description = "metric3 description"),
-  @WidgetProperty(key = "hideEvents", type = WidgetPropertyType.BOOLEAN, description = "hideEvents description"),
-  @WidgetProperty(key = "hideEvents2", type = WidgetPropertyType.BOOLEAN, description = "hideEvents description", defaultValue = "true"),
-  @WidgetProperty(key = "chartHeight", type = WidgetPropertyType.INTEGER, defaultValue = "80", description = "chartHeight description"),
-
-  @WidgetProperty(key = "text", type = WidgetPropertyType.TEXT, description = "text description"),
-  @WidgetProperty(key = "password", type = WidgetPropertyType.PASSWORD, description = "password description", defaultValue = "123"),
-  @WidgetProperty(key = "password2", type = WidgetPropertyType.PASSWORD, description = "password2 description"),
-  @WidgetProperty(key = "float", type = WidgetPropertyType.FLOAT, description = "float description"),
-  @WidgetProperty(key = "regex", type = WidgetPropertyType.REGULAR_EXPRESSION, description = "regex description"),
-  @WidgetProperty(key = "filter", type = WidgetPropertyType.FILTER, description = "filter description"),
-  @WidgetProperty(
-    key = "list",
-    defaultValue = "2",
-    type = WidgetPropertyType.SINGLE_SELECT_LIST,
-    options = {"1", "2", "3"},
-    description = "list description"),
-    @WidgetProperty(
-        key = "list2",
-        type = WidgetPropertyType.SINGLE_SELECT_LIST,
-        options = {"1", "2", "3"},
-        description = "list2 description")
+    @WidgetProperty(key = "chartTitle", type = WidgetPropertyType.STRING),
+    @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc", 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 = "hideEvents", type = WidgetPropertyType.BOOLEAN),
+    @WidgetProperty(key = "chartHeight", type = WidgetPropertyType.INTEGER, defaultValue = "80")
 })
 public class TimelineWidget extends CoreWidget {
   public TimelineWidget() {
index 9a3a2ff7a34809e62e6925c299ab8fafe9d8ae7b..fd19bacb372fc7437ce463926e18c81abd1b3ab4 100644 (file)
@@ -52,8 +52,8 @@ module PropertiesHelper
         password_field_tag name, value, {:size => options[:size] || 25}.update(html_options)
 
       when PropertyType::TYPE_BOOLEAN
-        if options[:default]
-          select_options = "<option value='' #{ 'selected' if value.blank? }>#{ options[:default] }</option>"
+        if !options[:default].blank?
+          select_options = "<option value='' #{ 'selected' if value.blank? }>#{ message('default') }</option>"
           select_options += "<option value='true' #{ 'selected' if value=='true' }>#{ message('true') }</option>"
           select_options += "<option value='false' #{ 'selected' if value=='false' }>#{ message('false') }</option>"
           select_tag name, select_options, html_options
@@ -90,11 +90,8 @@ module PropertiesHelper
         default_value = options[:default].blank? ? '' : message('default')
         select_options = "<option value=''>#{ default_value }</option>"
         options[:values].each do |option|
-          if screen == SCREEN_WIDGET
-            message = message("widget.#{options[:extra_values][:key]}.option.#{name}.#{option}.name", :default => option)
-          else
-            message = option_name(options[:extra_values][:property], options[:extra_values][:field], option)
-          end
+          message = screen == SCREEN_WIDGET ? option_name_with_key(options[:extra_values][:key], nil, option, 'widget') :
+              option_name(options[:extra_values][:property], options[:extra_values][:field], option)
           select_options += "<option value='#{ html_escape option }' #{ 'selected' if value && value==option }>#{ message }</option>"
         end
         select_tag name, select_options, html_options
@@ -135,4 +132,20 @@ module PropertiesHelper
     end
   end
 
+  def option_name_with_key(property_key, field_key, option, key_prefix = '')
+    prefix = ''
+    prefix = key_prefix + "." if !key_prefix.blank?
+    if field_key
+      # Old key used for retro-compatibility
+      message = message(prefix +"option.#{property_key}.#{field_key}.#{option}.name", :default => '')
+      message = message(prefix +"property.#{property_key}.#{field_key}.option.#{option}.name", :default => option) unless message != ''
+      message
+    else
+      # Old key used for retro-compatibility
+      message = message(prefix +"option.#{property_key}.#{option}.name", :default => '')
+      message = message(prefix +"property.#{property_key}.option.#{option}.name", :default => option) unless message != ''
+      message
+    end
+  end
+
 end
index f019fdc4ff14501449e972b952a06c1ea1c248f6..e61180f519c060792b6ac8ebd0240455bb6d9e6b 100644 (file)
@@ -45,11 +45,7 @@ module SettingsHelper
   end
 
   def option_name(property, field, option)
-    if field
-      message("option.#{property.key}.#{field.key}.#{option}.name", :default => option)
-    else
-      message("option.#{property.key}.#{option}.name", :default => option)
-    end
+    option_name_with_key(property.key, field ? field.key : nil, option, nil)
   end
 
   def category_help(category)
index 93fcc8f30abac7c9a16e690d36497eb52b4ca173..df14ac28ff4f9d6df3106df6064dbb08182c4af8 100644 (file)
@@ -29,6 +29,7 @@
           <%= property_value_field(property_def, widget.property_text_value(property_def.key()), widget) -%>
           <div class="form-val-note">
             <%
+               # Old key used for retro-compatibility
                property_description = message("widget." + widget.key + ".param." + property_def.key(), :default => '')
                property_description = message("widget." + widget.key + ".property." + property_def.key() + ".desc", :default => property_def.description()) unless property_description != ''
             -%>
index f465d0577e5c221bf17a8764b0b5010c830a88e2..e1e809eb2b2483075bc1cde76f83bb071c30fb60 100644 (file)
@@ -1 +1 @@
-<%= property_input_field(id, PropertyType::TYPE_BOOLEAN, value, PropertiesHelper::SCREEN_SETTINGS, {:id => id, :default => message('default')}) %>
\ No newline at end of file
+<%= property_input_field(name, PropertyType::TYPE_BOOLEAN, value, PropertiesHelper::SCREEN_SETTINGS, {:id => id, :default => (defined? defaultValue) ? property.defaultValue : nil }) %>
\ No newline at end of file
index 01ea42e3c208b638361be527de1211b459fb35dd..d9e9399908dcc0001b9d643b9d5a8f571400701b 100644 (file)
@@ -2,4 +2,4 @@
    options = {:id => id}
    options[:size] = (defined? size) ? size : 50
 %>
-<%= property_input_field(id, PropertyType::TYPE_FLOAT, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
+<%= property_input_field(name, PropertyType::TYPE_FLOAT, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
index 077ff457a3b97d30aa5b2d4c696f2399c76aeeb4..79f4a1f6efa0c33faac280d4d8e1becab3fa478d 100644 (file)
@@ -2,4 +2,4 @@
    options = {:id => id}
    options[:size] = (defined? size) ? size : 50
 %>
-<%= property_input_field(id, PropertyType::TYPE_INTEGER, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
+<%= property_input_field(name, PropertyType::TYPE_INTEGER, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
index 2ac1183619bc669ad059ae52880ab8c89e7b3702..4f121917ca4cca748f891c951471d120fb236611 100644 (file)
@@ -1,5 +1,8 @@
+<%
+   defaultValue = (defined? defaultValue) ? property.defaultValue : nil
+%>
 <select name="<%= name -%>" id="<%= id -%>">
-  <option value=""><%= !property.defaultValue.blank? ? message('default') : nil -%></option>
+  <option value=""><%= !defaultValue.blank? ? message('default') : nil -%></option>
   <%
      metrics_per_domain={}
      metrics_filtered_by(property.options).each do |metric|
index f7a94ebda2d64e033f04efb59e62ef376793a3c5..ee7ca50b73ac1dd4c27e593123c01a46e05fda49 100644 (file)
@@ -2,4 +2,4 @@
    options = {:id => id}
    options[:size] = (defined? size) ? size : 50
 %>
-<%= property_input_field(id, PropertyType::TYPE_PASSWORD, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
+<%= property_input_field(name, PropertyType::TYPE_PASSWORD, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
index 26ef0412fa816908d5cb3d8e0d0c702d42935821..7dececf6629c33208d9a8937b8be98388aa57e79 100644 (file)
@@ -2,4 +2,4 @@
    options = {:id => id}
    options[:size] = (defined? size) ? size : 50
 %>
-<%= property_input_field(id, PropertyType::TYPE_REGULAR_EXPRESSION, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
+<%= property_input_field(name, PropertyType::TYPE_REGULAR_EXPRESSION, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
index 903eb0b119f1baf1b20babaae11fd0cb4e693e20..3df9028bebe7e6eb0a50dbe86b964fabe585464e 100644 (file)
@@ -2,4 +2,4 @@
    options = {:id => id}
    options[:size] = (defined? size) ? size : 50
 %>
-<%= property_input_field(id, PropertyType::TYPE_STRING, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
+<%= property_input_field(name, PropertyType::TYPE_STRING, value, PropertiesHelper::SCREEN_SETTINGS, options) %>
\ No newline at end of file
index d3e59483f860dffef52410d23dd65b726d9dd83f..ac671bf69153fc92329fb1f13f39cca55362ec8b 100644 (file)
@@ -2,4 +2,4 @@
    options = {:id => id}
    options[:cols] = (defined? size) ? size : 50
 %>
-<%= property_input_field(id, PropertyType::TYPE_TEXT, value, PropertiesHelper::SCREEN_SETTINGS, {:id => id,  :cols => (defined? size) ? size : nil}) %>
+<%= property_input_field(name, PropertyType::TYPE_TEXT, value, PropertiesHelper::SCREEN_SETTINGS, {:id => id,  :cols => (defined? size) ? size : nil}) %>