On 04/19/2011 08:29 AM, jzigmund@redhat.com wrote:
From: Jozef Zigmundjzigmund@redhat.com
src/app/models/pool.rb | 1 + src/app/views/resources/pools/_list.haml | 2 ++ src/app/views/resources/pools/edit.haml | 3 +++ src/app/views/resources/pools/new.haml | 5 ++++- .../migrate/20110413093434_add_enabled_to_pool.rb | 19 +++++++++++++++++++ src/db/seeds.rb | 2 +- 6 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/db/migrate/20110413093434_add_enabled_to_pool.rb
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb index a228a14..b3da2a7 100644 --- a/src/app/models/pool.rb +++ b/src/app/models/pool.rb @@ -50,6 +50,7 @@ class Pool< ActiveRecord::Base
validates_presence_of :name validates_presence_of :pool_family
- validates_inclusion_of :enabled, :in => [true, false] validates_uniqueness_of :name validates_uniqueness_of :exported_as, :if => :exported_as validates_length_of :name, :maximum => 255
diff --git a/src/app/views/resources/pools/_list.haml b/src/app/views/resources/pools/_list.haml index 1e7b3d7..c8083b7 100644 --- a/src/app/views/resources/pools/_list.haml +++ b/src/app/views/resources/pools/_list.haml @@ -21,6 +21,8 @@ ='%' %td = pool.pool_family.name
%td
= pool.enabled
:javascript $(document).ready(function () {
diff --git a/src/app/views/resources/pools/edit.haml b/src/app/views/resources/pools/edit.haml index cc00233..d4c511f 100644 --- a/src/app/views/resources/pools/edit.haml +++ b/src/app/views/resources/pools/edit.haml @@ -17,6 +17,9 @@ %button.linkbutton.nospace{ :type => 'button', :onclick => "set_unlimited_quota("quota_instances");" }<> = t('provider_accounts.form.unlimited_quota') )
%fieldset
= form.label :enabled, "Enabled:",{ :class => "grid_2 alpha" }
= form.check_box :enabled %fieldset.clear
= form.submit "Save"
diff --git a/src/app/views/resources/pools/new.haml b/src/app/views/resources/pools/new.haml index dde52c9..5c48c9e 100644 --- a/src/app/views/resources/pools/new.haml +++ b/src/app/views/resources/pools/new.haml @@ -8,12 +8,15 @@ = form.label :pool_family_id, "Pool Family:", :class => "grid_2 alpha" = form.collection_select :pool_family_id, PoolFamily.all, :id, :name %fieldset
- = label_tag "Quota"
= label_tag "Quota:" = text_field :quota, :maximum_running_instances, :title => t('provider_accounts.form.quota_instances'), :value => @quota.maximum_running_instances || "unlimited", :id => "quota_instances", :class => "grid_3 omega" ( %button.linkbutton.nospace{ :type => 'button', :onclick => "set_unlimited_quota("quota_instances");" }<> = t('provider_accounts.form.unlimited_quota') )
%fieldset
= form.label :enabled, "Enabled:",{ :class => "grid_2 alpha" }
= form.check_box :enabled %fieldset.clear
= form.submit "Save"
diff --git a/src/db/migrate/20110413093434_add_enabled_to_pool.rb b/src/db/migrate/20110413093434_add_enabled_to_pool.rb new file mode 100644 index 0000000..a5c8948 --- /dev/null +++ b/src/db/migrate/20110413093434_add_enabled_to_pool.rb @@ -0,0 +1,19 @@ +class AddEnabledToPool< ActiveRecord::Migration
- def self.up
- add_column :pools, :enabled, :boolean, :default => false
- set_enabled
- end
- def self.down
- remove_column :pools, :enabled
- end
- def self.set_enabled
- unless Pool.all.empty?
Pool.all.each do |pool|
pool.enabled = pool.name == 'default_pool' ? true : false
I think for the migration you should just enable all of them. We should avoid adding any additional dependencies on the current name of the default pool, since it could be changed at any time.
pool.save!
end
- end
- end
+end diff --git a/src/db/seeds.rb b/src/db/seeds.rb index 69be3f4..a42517b 100644 --- a/src/db/seeds.rb +++ b/src/db/seeds.rb @@ -2,7 +2,7 @@ PoolFamily.create!(:name => "default", :description => "default pool family")
# Default Pool -Pool.create!(:name => "default_pool", :quota => Quota.create, :pool_family => PoolFamily.find_by_name('default')) +Pool.create!(:name => "default_pool", :quota => Quota.create, :pool_family => PoolFamily.find_by_name('default'), :enabled => true)
# Create default roles