From 8e738b461b77b9f72e29ca1f028709ca0c2e7742 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Sat, 29 Sep 2012 13:36:13 +0200 Subject: [PATCH] SONAR-3529 Edition of property sets --- .../app/controllers/settings_controller.rb | 40 +++++++++++++--- .../WEB-INF/app/helpers/settings_helper.rb | 2 +- .../_type_PROPERTY_SET_DEFINITION.html.erb | 48 ++++++++++++++----- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb index d0d1791bf3f..255294383cf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb @@ -38,12 +38,40 @@ class SettingsController < ApplicationController 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? @@ -52,11 +80,11 @@ class SettingsController < ApplicationController @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' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb index ca9c3da8189..c97111ef077 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb @@ -55,6 +55,6 @@ module SettingsHelper end def input_name(property) - h(property.key) + (property.multi_values ? '[]' : '') + "settings[#{h property.key}#{property.multi_values ? '[]' : ''}]" end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb index 22777ac090f..029762ae2a7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb @@ -1,17 +1,43 @@ -<% 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| -%> -

<%= set_key -%>

+<% Property.values(property.key, resource_id).reject(&:blank?).each do |set_key| -%> +
+
+
- <% property.fields.each do |field| -%> -
- <% end -%> + <% property.fields.each do |field| -%> +
+ "/> +
+ <% end -%> - <%= message('delete') -%> + <%= message('delete') -%> +

+
<% end -%> + + -- 2.39.5