access_denied if (@resource.nil? && !is_admin?)
load_properties()
+ save_properties(resource_id)
+ save_property_sets(resource_id)
+ render :partial => 'settings/properties'
+ end
+
+ private
+
+ # TODO: Validation
+ def save_property_sets(resource_id)
+ params[:property_sets].each do |key, value|
+ value = drop_trailing_blank_values(value)
+
+ # TODO: clear all
+ Property.set(key, value.map { |v| v.gsub(',', '%2C') }.join(','), resource_id)
+
+ fields = params[key]
+
+ fields.each do |field_key, field_values|
+ field_values.each_with_index do |field_value, index|
+ set_key = value[index]
+ if set_key
+ Property.set(key + "." + set_key + "." + field_key, field_value, resource_id)
+ end
+ end
+ end
+ end
+ end
+
+ def save_properties(resource_id)
@updated_properties = {}
- @definitions.map(&:key).each do |key|
- value = params[key]
+ params[:settings].each do |key, value|
if value.kind_of? Array
- value = value.reverse.drop_while(&:blank?).reverse
+ value = drop_trailing_blank_values(value)
end
if value.blank?
@updated_properties[key] = Property.set(key, value, resource_id)
end
end
-
- render :partial => 'settings/properties'
end
- private
+ def drop_trailing_blank_values(array)
+ array.reverse.drop_while(&:blank?).reverse
+ end
def load_properties
@category = params[:category] || 'general'
-<% Property.set('sonar.test.jira.servers', 'jira1,jira2') -%>
-<% Property.set('sonar.test.jira.servers.jira1.url', 'http://url1') -%>
-<% Property.set('sonar.test.jira.servers.jira1.port', '1234') -%>
-<% Property.set('sonar.test.jira.servers.jira2.url', 'http://url2') -%>
-<% Property.set('sonar.test.jira.servers.jira2.port', '9999') -%>
+<% if Property.value('sonar.test.jira.servers').blank? -%>
+ <% Property.set('sonar.test.jira.servers', 'jira1,jira2') -%>
+ <% Property.set('sonar.test.jira.servers.jira1.url', 'http://url1') -%>
+ <% Property.set('sonar.test.jira.servers.jira1.port', '1234') -%>
+ <% Property.set('sonar.test.jira.servers.jira2.url', 'http://url2') -%>
+ <% Property.set('sonar.test.jira.servers.jira2.port', '9999') -%>
+<% end -%>
+
+<% resource_id = @resource.id if @resource -%>
-<% Property.values(property.key).reject(&:blank?).each do |set_key| -%>
- <h3><%= set_key -%></h3>
+<% Property.values(property.key, resource_id).reject(&:blank?).each do |set_key| -%>
+ <div class="multi_value">
+ <label>Key: </label><br/>
+ <input name="property_sets[<%= property.key -%>][]" value="<%= set_key -%>"/><br/>
- <% property.fields.each do |field| -%>
- <label><%= field.key -%>: </label><input type="text" value="<%= Property.value([property.key, set_key, field.key].join('.')) -%>"/><br/>
- <% end -%>
+ <% property.fields.each do |field| -%>
+ <label><%= field.key -%>: </label><br/>
+ <input type="text" name="<%= property.key -%>[<%= field.key -%>][]" value="<%= Property.value("#{property.key}.#{set_key}.#{field.key}", resource_id) -%>"/>
+ <br/>
+ <% end -%>
- <a href="#" class="delete link-action"><%= message('delete') -%></a>
+ <a href="#" class="delete link-action"><%= message('delete') -%></a>
+ <br/><br/>
+ </div>
<% end -%>
+<div class="template" style="display:none;">
+ <div class="multi_value">
+ <label>Key: </label><br/>
+ <input name="property_sets[<%= property.key -%>][]" value=""/><br/>
+
+ <% property.fields.each do |field| -%>
+ <label><%= field.key -%>: </label><br/>
+ <input type="text" name="<%= property.key -%>[<%= field.key -%>][]" value=""/>
+ <br/>
+ <% end -%>
+
+ <a href="#" class="delete link-action"><%= message('delete') -%></a>
+ <br/><br/>
+ </div>
+</div>
+
<button class="add_value"><%= message('settings.add') -%></button>