diff options
author | David Gageot <david@gageot.net> | 2012-10-04 17:43:47 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-10-04 17:43:47 +0200 |
commit | 2b3d944acfbfa405ead9b7420447730f40f65393 (patch) | |
tree | 6a10db0a12a21b933bb41a516a459582cb9f5035 | |
parent | 1e67149fab20a225574ad00a97b1b87afc8365ac (diff) | |
download | sonarqube-2b3d944acfbfa405ead9b7420447730f40f65393.tar.gz sonarqube-2b3d944acfbfa405ead9b7420447730f40f65393.zip |
SONAR-3529 Clean code a bit
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb | 35 | ||||
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb | 9 |
2 files changed, 22 insertions, 22 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 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 -%> <td><%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%></td> - - <% errors << (render "settings/error", :key => key) if set_key -%> <% end -%> <td><a href="#" class="delete link-action"><%= message('delete') -%></a></td> |