diff --git a/app/models/pool.rb b/app/models/pool.rb index d03b235d0..7c01e45d2 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -3,6 +3,7 @@ require 'ostruct' class Pool < ActiveRecord::Base validates_uniqueness_of :name validates_format_of :name, :with => /\A[^\s;,]+\Z/, :on => :create, :message => "cannot have whitespace, commas, or semicolons" + validates_inclusion_of :category, :in => %w(series collection) belongs_to :creator, :class_name => "User" belongs_to :updater, :class_name => "User" has_many :versions, :class_name => "PoolVersion", :dependent => :destroy, :order => "pool_versions.id ASC" @@ -12,7 +13,7 @@ class Pool < ActiveRecord::Base before_validation :initialize_creator, :on => :create after_save :create_version before_destroy :create_mod_action_for_destroy - attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :as => [:member, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default] + attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :category, :as => [:member, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default] attr_accessible :is_deleted, :as => [:janitor, :moderator, :admin] module SearchMethods @@ -20,6 +21,14 @@ class Pool < ActiveRecord::Base where("is_deleted = false") end + def series + where("category = ?", "series") + end + + def collection + where("category = ?", "collection") + end + def search(params) q = scoped params = {} if params.blank? @@ -54,6 +63,12 @@ class Pool < ActiveRecord::Base q = q.order("updated_at desc") end + if params[:category] == "series" + q = q.series + elsif params[:category] == "collection" + q = q.collection + end + q end end @@ -236,7 +251,7 @@ class Pool < ActiveRecord::Base end def create_version - if post_ids_changed? || name_changed? || description_changed? || is_active_changed? || is_deleted_changed? + if post_ids_changed? || name_changed? || description_changed? || is_active_changed? || is_deleted_changed? || category_changed? last_version = versions.last if last_version && CurrentUser.ip_addr == last_version.updater_ip_addr && CurrentUser.id == last_version.updater_id diff --git a/app/views/pools/edit.html.erb b/app/views/pools/edit.html.erb index dfaa49daa..26bfb5953 100644 --- a/app/views/pools/edit.html.erb +++ b/app/views/pools/edit.html.erb @@ -5,6 +5,7 @@ <%= f.input :name, :input_html => { :value => @pool.pretty_name } %> <%= f.input :description %> <%= f.input :post_ids, :label => "Posts" %> + <%= f.input :category, :collection => ["series", "collection"], :include_blank => false %> <%= f.input :is_active %> <%= f.button :submit %> <% end %> diff --git a/app/views/pools/new.html.erb b/app/views/pools/new.html.erb index c9b05fa68..839c17456 100644 --- a/app/views/pools/new.html.erb +++ b/app/views/pools/new.html.erb @@ -4,6 +4,7 @@

New Pool

<%= f.input :name %> <%= f.input :description %> + <%= f.input :category, :collection => ["series", "collection"], :include_blank => false %> <%= f.button :submit %> <% end %> diff --git a/db/migrate/20130506154136_add_category_to_pools.rb b/db/migrate/20130506154136_add_category_to_pools.rb new file mode 100644 index 000000000..61be564d8 --- /dev/null +++ b/db/migrate/20130506154136_add_category_to_pools.rb @@ -0,0 +1,6 @@ +class AddCategoryToPools < ActiveRecord::Migration + def change + execute("set statement_timeout = 0") + add_column :pools, :category, :string, :null => false, :default => "series" + end +end