]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3529 Clean code a bit
authorDavid Gageot <david@gageot.net>
Thu, 4 Oct 2012 15:43:47 +0000 (17:43 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 4 Oct 2012 15:43:47 +0000 (17:43 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb

index a373a86c460283290409be5229a9203f4cc09027..814c40f539d37e5042cfec5d9b4e9157080031a9 100644 (file)
@@ -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
index b2007ca090c5c8298f06dcacef721da0e556b3da..8650ff409a587b152f0b3b961f1a8a6a3a6792cf 100644 (file)
@@ -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>