From: David Gageot Date: Thu, 4 Oct 2012 15:43:47 +0000 (+0200) Subject: SONAR-3529 Clean code a bit X-Git-Tag: 3.3~116 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2b3d944acfbfa405ead9b7420447730f40f65393;p=sonarqube.git SONAR-3529 Clean code a bit --- 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 a373a86c460..814c40f539d 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 @@ -56,27 +56,26 @@ class SettingsController < ApplicationController def update_property_sets(resource_id) (params[:property_sets] || []).each do |key, set_keys| - Property.transaction do - # clear - Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all + if params[key][:auto_generate] + set_keys = Array.new(set_keys.size - 1) { |i| i.to_s } + end - if params[key][:auto_generate] - set_keys = Array.new(set_keys.size - 1) { |i| i.to_s } - end + update_property_set(key, set_keys, params[key], resource_id) + end + end - # set keys - update_property(key, set_keys, resource_id) - set_keys.each do |set_key| - update_property("#{key}.#{set_key}.key", set_key, resource_id) - end + def update_property_set(key, set_keys, fields_hash, resource_id) + Property.transaction do + Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all + + update_property(key, set_keys, resource_id) + set_keys.each do |set_key| + update_property("#{key}.#{set_key}.key", set_key, resource_id) + end - # set fields - params[key].each do |field_key, field_values| - field_values.zip(set_keys).each do |field_value, set_key| - if set_key - update_property("#{key}.#{set_key}.#{field_key}", field_value, resource_id) - end - end + fields_hash.each do |field_key, field_values| + field_values.zip(set_keys).each do |field_value, set_key| + update_property("#{key}.#{set_key}.#{field_key}", field_value, resource_id) if set_key end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb index b2007ca090c..8650ff409a5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb @@ -9,12 +9,13 @@ <% end -%> <% property.fields.reject { |field| field.key == 'key' }.each do |field| -%> - <% key = "#{property.key}.#{set_key}.#{field.key}" if set_key -%> - <% value = Property.value(key, resource_id) if set_key -%> + <% if set_key -%> + <% key = "#{property.key}.#{set_key}.#{field.key}" -%> + <% value = Property.value(key, resource_id) -%> + <% errors << (render "settings/error", :key => key) -%> + <% end -%> <%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%> - - <% errors << (render "settings/error", :key => key) if set_key -%> <% end -%> <%= message('delete') -%>