}
@Properties(@Property(key = "hello", name = "Hello", fields = {
- @PropertyField(key = "first", name = "First"),
+ @PropertyField(key = "first", name = "First", description = "Description", options = {"A", "B"}),
@PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER)}))
static class WithPropertySet {
}
assertThat(def.getFields()).hasSize(2);
assertThat(def.getFields()[0].getKey()).isEqualTo("first");
assertThat(def.getFields()[0].getName()).isEqualTo("First");
+ assertThat(def.getFields()[0].getDescription()).isEqualTo("Description");
assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING);
+ assertThat(def.getFields()[0].getOptions()).containsOnly("A", "B");
assertThat(def.getFields()[1].getKey()).isEqualTo("second");
assertThat(def.getFields()[1].getName()).isEqualTo("Second");
assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER);
+ assertThat(def.getFields()[1].getOptions()).isEmpty();
}
@Properties(@Property(key = "hello", name = "Hello"))
access_denied if (@resource.nil? && !is_admin?)
load_properties()
+
+ @updated_properties = {}
save_properties(resource_id)
save_property_sets(resource_id)
private
- # TODO: Validation
def save_property_sets(resource_id)
(params[:property_sets] || []).each do |key, value|
set_keys = drop_trailing_blank_values(value)
params[key].each do |field_key, field_values|
field_values.each_with_index do |field_value, index|
set_key = set_keys[index]
- Property.set("#{key}.#{set_key}.#{field_key}", field_value, resource_id) if set_key
+ if set_key
+ field_property_key = "#{key}.#{set_key}.#{field_key}"
+ @updated_properties[field_property_key] = Property.set(field_property_key, field_value, resource_id)
+ end
end
end
end
end
def save_properties(resource_id)
- @updated_properties = {}
-
(params[:settings] || []).each do |key, value|
if value.kind_of? Array
value = drop_trailing_blank_values(value)
message("field.#{property.key}.#{field.key}.description", :default => field.description)
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
+ end
+
def property_help(property)
message("property.#{property.key}.help", :default => '')
end
end
end
+ def java_field_definition
+ @java_field_definition ||=
+ begin
+ if /(.*)\..*\.(.*)/.match(key)
+ property_definition = Java::OrgSonarServerUi::JRubyFacade.getInstance().getPropertyDefinitions().get(Regexp.last_match(1))
+ if property_definition
+ property_definition.fields.find { |field| field.key == Regexp.last_match(2) }
+ end
+ end
+ end
+ end
+
def validation_error_message
msg=''
errors.each_full do |error|
end
def validate
+ validate_property()
+ validate_field()
+ end
+
+ def validate_property
if java_definition
validation_result = java_definition.validate(text_value)
errors.add_to_base(validation_result.getErrorKey()) unless validation_result.isValid()
end
end
+
+ def validate_field
+ if java_field_definition
+ validation_result = java_field_definition.validate(text_value)
+ errors.add_to_base(validation_result.getErrorKey()) unless validation_result.isValid()
+ end
+ end
end
--- /dev/null
+<% if @updated_properties -%>
+ <% p = @updated_properties[key] -%>
+
+ <% if p && !p.valid? -%>
+ <div class="error"><%= p.validation_error_message -%></div>
+ <% end -%>
+<% end -%>
<%= render "settings/single_value", :property => property, :value => value -%>
<% end -%>
- <% p = @updated_properties[property.key] if @updated_properties -%>
- <% if p && !p.valid? -%>
- <div class="error"><%= p.validation_error_message -%></div>
- <% end -%>
+ <%= render "settings/error", :key => property.key -%>
<% default_prop_value = (@resource ? Property.value(property.key, nil, property.defaultValue) : property.defaultValue) -%>
<% unless default_prop_value.blank? -%>
</div>
<% property.fields.each do |field| -%>
+ <% key = "#{property.key}.#{set_key}.#{field.key}" if set_key -%>
+ <% value = Property.value(key, resource_id) if set_key -%>
+
<div class="field">
<label><%= field_name(property, field) -%>: </label>
-
- <% value = Property.value("#{property.key}.#{set_key}.#{field.key}", resource_id) if set_key -%>
- <%= render "settings/type_#{field.type}", :property => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}" -%>
+ <%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}" -%>
<% desc=field_description(property, field) -%>
<% unless desc.blank? %>
<p class="note"><%= desc -%></p>
<% end -%>
+
+ <%= render "settings/error", :key => key -%>
</div>
<% end -%>
<br/>
-<%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value, :name => input_name(property), :id => "input_#{h property.key}" -%>
+<%= render "settings/type_#{property_type(property, value)}", :property => property, :field => nil, :value => value, :name => input_name(property), :id => "input_#{h property.key}" -%>
<select name="<%= name -%>" id="<%= id -%>">
<option value=""><%= message('default') -%></option>
<% property.options.each do |option| %>
- <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option>
+ <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= option_name(property, field, option) -%></option>
<% end %>
</select>
\ No newline at end of file
padding-right: 5px;
}
-.field .note {
+.field .note, .field .error {
margin-top: 3px;
- margin-left: 90px;
+ margin-left: 88px;
}