#
module PropertiesHelper
- def property_value(key, type, value)
+ def property_value(key, type, value, options = {})
if type==PropertyType::TYPE_INTEGER
- text_field_tag key, value, :size => 10
+ text_field_tag key, value, {:size => 10}.update(options)
elsif type==PropertyType::TYPE_BOOLEAN
- check_box_tag key, "true", value=='true'
+ check_box_tag key, "true", value=='true', options
elsif type==PropertyType::TYPE_FLOAT
- text_field_tag key, value, :size => 10
+ text_field_tag key, value, {:size => 10}.update(options)
elsif type==PropertyType::TYPE_STRING
- text_field_tag key, value, :size => 10
+ text_field_tag key, value, {:size => 10}.update(options)
elsif type==PropertyType::TYPE_METRIC
- select_tag key, options_grouped_by_domain(Metric.all.select{|m| m.display?}.sort_by(&:short_name), value, :include_empty => true)
+ select_tag key, options_grouped_by_domain(Metric.all.select{|m| m.display?}.sort_by(&:short_name), value, :include_empty => true), 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)
+ filters_combo = select_tag key, option_group('My Filters', user_filters) + option_group('Shared Filters', shared_filters), options
filter_link = link_to message('widget.filter.edit'), {:controller => :filters, :action => :manage}, :class => 'link-action'
"#{filters_combo} #{filter_link}"
elsif type==PropertyType::TYPE_TEXT
- text_area_tag key, value, :size => '40x6'
+ text_area_tag key, value, {:size => '40x6'}.update(options)
elsif type==PropertyType::TYPE_PASSWORD
- password_field_tag key, value, :size => 10
+ password_field_tag key, value, {:size => 10}.update(options)
else
- hidden_field_tag key
+ hidden_field_tag key, options
end
end
--- /dev/null
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+module RulesConfigurationHelper
+ include PropertiesHelper
+
+ PARAM_TYPE_STRING = "s"
+ PARAM_TYPE_STRING_LIST = "s{}"
+ PARAM_TYPE_INTEGER = "i"
+ PARAM_TYPE_INTEGER_LIST = "i{}"
+ PARAM_TYPE_BOOLEAN = "b"
+ PARAM_TYPE_REGEXP = "r"
+
+ def property_type_for_param_type(type)
+ return PropertyType::TYPE_STRING if type == PARAM_TYPE_STRING
+ return PropertyType::TYPE_STRING if type == PARAM_TYPE_STRING_LIST
+ return PropertyType::TYPE_INTEGER if type == PARAM_TYPE_INTEGER
+ return PropertyType::TYPE_INTEGER if type == PARAM_TYPE_INTEGER_LIST
+ return PropertyType::TYPE_BOOLEAN if type == PARAM_TYPE_BOOLEAN
+ return PropertyType::TYPE_STRING if type == PARAM_TYPE_REGEXP
+ end
+
+ def readable_type(type)
+ return "" if type == PARAM_TYPE_STRING
+ return "Set of string (, as delimiter)" if type == PARAM_TYPE_STRING_LIST
+ return "Number" if type == PARAM_TYPE_INTEGER
+ return "Set of number (, as delimiter)" if type == PARAM_TYPE_INTEGER_LIST
+ return "" if type == PARAM_TYPE_BOOLEAN
+ return "Regular expression" if type == PARAM_TYPE_REGEXP
+ return "Set of values (, as delimiter)" if is_set(type)
+ end
+
+ def param_value_input(parameter, value, options = {})
+ property_value 'value', property_type_for_param_type(parameter.param_type), value, {:id => parameter.id}.update(options)
+ end
+
+ def input_size(type)
+ return 15 if type == PARAM_TYPE_STRING
+ return 15 if type == PARAM_TYPE_STRING_LIST
+ return 8 if type == PARAM_TYPE_INTEGER
+ return 8 if type == PARAM_TYPE_INTEGER_LIST
+ return 4 if type == PARAM_TYPE_BOOLEAN
+ return 15 if type == PARAM_TYPE_REGEXP
+ if is_set(type)
+ size = (type.length / 2).to_i
+ size = 64 if size > 64
+ size
+ end
+ end
+
+ def is_set(type)
+ type.at(1) == "[" && type.ends_with?("]")
+ end
+end
+
+++ /dev/null
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2012 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
-#
-module RulesParametersHelper
- include PropertiesHelper
-
- PARAM_TYPE_STRING = "s"
- PARAM_TYPE_STRING_LIST = "s{}"
- PARAM_TYPE_INTEGER = "i"
- PARAM_TYPE_INTEGER_LIST = "i{}"
- PARAM_TYPE_BOOLEAN = "b"
- PARAM_TYPE_REGEXP = "r"
-
- def readable_type(type)
- return "String" if type == PARAM_TYPE_STRING
- return "Set of string (, as delimiter)" if type == PARAM_TYPE_STRING_LIST
- return "Number" if type == PARAM_TYPE_INTEGER
- return "Set of number (, as delimiter)" if type == PARAM_TYPE_INTEGER_LIST
- return "Boolean" if type == PARAM_TYPE_BOOLEAN
- return "Regular expression" if type == PARAM_TYPE_REGEXP
- return "Set of values (, as delimiter)" if is_set(type)
- end
-
- def input_size(type)
- return 15 if type == PARAM_TYPE_STRING
- return 15 if type == PARAM_TYPE_STRING_LIST
- return 8 if type == PARAM_TYPE_INTEGER
- return 8 if type == PARAM_TYPE_INTEGER_LIST
- return 4 if type == PARAM_TYPE_BOOLEAN
- return 15 if type == PARAM_TYPE_REGEXP
- if is_set(type)
- size = (type.length / 2).to_i
- size = 64 if size > 64
- size
- end
- end
-
- def is_set(type)
- type.at(1) == "[" && type.ends_with?("]")
- end
-end
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
class RulesParameter < ActiveRecord::Base
- include RulesParametersHelper
+ include RulesConfigurationHelper
PARAM_MAX_NUMBER = 4
write_attribute(:description, value)
end
- def readable_param_type
- readable_type(param_type)
- end
-
- def input_box_size
- input_size(param_type)
- end
-
def validate_value(attribute, errors, value)
return if attribute.nil? or attribute.length == 0
if is_set_type
allowed_tokens = get_allowed_tokens
provided_tokens.each do |provided_token|
if !allowed_tokens.include?(provided_token)
- errors.add("#{value}", "Invalid value '" + provided_token + "'. Must be one of : " + allowed_tokens.join(", "))
+ errors.add("#{value}", "'#{provided_token}' kust be one of : " + allowed_tokens.join(", "))
end
end
- elsif param_type == RulesParametersHelper::PARAM_TYPE_INTEGER
- begin
- Kernel.Integer(attribute)
- rescue
- errors.add("#{value}", "Invalid value '" + attribute + "'. Must be an integer.")
+ elsif param_type == RulesConfigurationHelper::PARAM_TYPE_INTEGER
+ if !Api::Utils.is_integer?(attribute)
+ errors.add("#{value}", "'#{attribute}' must be an integer.")
end
- elsif param_type == RulesParametersHelper::PARAM_TYPE_INTEGER_LIST
+ elsif param_type == RulesConfigurationHelper::PARAM_TYPE_INTEGER_LIST
provided_numbers = attribute.split(",")
provided_numbers.each do |provided_number|
- begin
- Kernel.Integer(provided_number)
- rescue
- errors.add("#{value}", "Invalid value '" + provided_number + "'. Must be an integer.")
+ if !Api::Utils.is_integer?(provided_number)
+ errors.add("#{value}", "'#{provided_number}' must be an integer.")
return
end
end
- elsif param_type == RulesParametersHelper::PARAM_TYPE_BOOLEAN
+ elsif param_type == RulesConfigurationHelper::PARAM_TYPE_BOOLEAN
if attribute != "true" && attribute != "false"
- errors.add("#{value}", "Invalid value '" + attribute + "'. Must be one of : true,false")
+ errors.add("#{value}", "'#{attribute}' must be one of : true,false")
end
- elsif param_type == RulesParametersHelper::PARAM_TYPE_REGEXP
+ elsif param_type == RulesConfigurationHelper::PARAM_TYPE_REGEXP
begin
Regexp.new(attribute)
rescue
- errors.add("#{value}", "Invalid regular expression '" + attribute + "'.")
+ errors.add("#{value}", "'#{attribute}' must be a regular expression")
end
end
end
<%
span_id = "text_#{parameter.id}"
read_only = !active_rule || !enable_modification
-
- if param_value.length < 50
- textfield = text_field_tag parameter.id, param_value, :size => parameter.input_box_size, :name => "value", :disabled => read_only
- textfield += link_to_function(image_tag("zoom.png"), "replaceTextField('#{span_id}', '#{parameter.id}')", :id => "toggle_text", :class => 'nolink') unless read_only
- else
- textfield = text_area_tag parameter.id, param_value, :size => "100x10", :name => "value", :disabled => read_only
- textfield += "<br/>"
- end
%>
<div id="error_<%= rule.id -%>" class="error" style="display: none"></div>
- <span id="<%= span_id -%>"><%= textfield -%></span>
+ <span id="<%= span_id -%>"><%= param_value_input(parameter, param_value, :disabled => read_only) -%></span>
<% if !read_only %>
<%= submit_tag message('update_verb') %>
%>
</form>
- <% if parameter.description && !parameter.description.blank? %>
- <div class="form-val-note"><%= h parameter.description -%></div>
- <% end %>
+ <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%></div>
</td>