merge pool category branch; fixes #1521
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
@import "../common/000_vars.css.scss";
|
@import "../common/000_vars.css.scss";
|
||||||
|
|
||||||
|
a.pool-category-collection, span.pool-category-collection a {
|
||||||
|
color: #A0A;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #B6B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
div#c-pool-elements {
|
div#c-pool-elements {
|
||||||
div#a-new {
|
div#a-new {
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ require 'ostruct'
|
|||||||
class Pool < ActiveRecord::Base
|
class Pool < ActiveRecord::Base
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validates_format_of :name, :with => /\A[^\s;,]+\Z/, :on => :create, :message => "cannot have whitespace, commas, or semicolons"
|
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 :creator, :class_name => "User"
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
has_many :versions, :class_name => "PoolVersion", :dependent => :destroy, :order => "pool_versions.id ASC"
|
has_many :versions, :class_name => "PoolVersion", :dependent => :destroy, :order => "pool_versions.id ASC"
|
||||||
@@ -13,7 +14,7 @@ class Pool < ActiveRecord::Base
|
|||||||
after_save :create_version
|
after_save :create_version
|
||||||
after_create :synchronize!
|
after_create :synchronize!
|
||||||
before_destroy :create_mod_action_for_destroy
|
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]
|
attr_accessible :is_deleted, :as => [:janitor, :moderator, :admin]
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
@@ -21,6 +22,18 @@ class Pool < ActiveRecord::Base
|
|||||||
where("is_deleted = false")
|
where("is_deleted = false")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def series
|
||||||
|
where("category = ?", "series")
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection
|
||||||
|
where("category = ?", "collection")
|
||||||
|
end
|
||||||
|
|
||||||
|
def series_first
|
||||||
|
order("(case category when 'series' then 0 else 1 end), name")
|
||||||
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = scoped
|
q = scoped
|
||||||
params = {} if params.blank?
|
params = {} if params.blank?
|
||||||
@@ -60,6 +73,12 @@ class Pool < ActiveRecord::Base
|
|||||||
q = q.order("updated_at desc")
|
q = q.order("updated_at desc")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:category] == "series"
|
||||||
|
q = q.series
|
||||||
|
elsif params[:category] == "collection"
|
||||||
|
q = q.collection
|
||||||
|
end
|
||||||
|
|
||||||
q
|
q
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -254,7 +273,7 @@ class Pool < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_version
|
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
|
last_version = versions.last
|
||||||
|
|
||||||
if last_version && CurrentUser.ip_addr == last_version.updater_ip_addr && CurrentUser.id == last_version.updater_id
|
if last_version && CurrentUser.ip_addr == last_version.updater_ip_addr && CurrentUser.id == last_version.updater_id
|
||||||
|
|||||||
@@ -161,12 +161,14 @@ class PostPresenter < Presenter
|
|||||||
return if pool.nil?
|
return if pool.nil?
|
||||||
html += pool_link_html(template, pool, :include_rel => true)
|
html += pool_link_html(template, pool, :include_rel => true)
|
||||||
|
|
||||||
@post.pools.active.where("id <> ?", template.params[:pool_id]).each do |other_pool|
|
other_pools = @post.pools.where("id <> ?", template.params[:pool_id]).series_first
|
||||||
|
other_pools.each do |other_pool|
|
||||||
html += pool_link_html(template, other_pool)
|
html += pool_link_html(template, other_pool)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
first = true
|
first = true
|
||||||
@post.pools.each do |pool|
|
pools = @post.pools.series_first
|
||||||
|
pools.each do |pool|
|
||||||
if first && template.params[:tags].blank?
|
if first && template.params[:tags].blank?
|
||||||
html += pool_link_html(template, pool, :include_rel => true)
|
html += pool_link_html(template, pool, :include_rel => true)
|
||||||
first = false
|
first = false
|
||||||
@@ -187,11 +189,11 @@ class PostPresenter < Presenter
|
|||||||
if options[:include_rel]
|
if options[:include_rel]
|
||||||
prev_rel = "prev"
|
prev_rel = "prev"
|
||||||
next_rel = "next"
|
next_rel = "next"
|
||||||
klass = "active"
|
klass = "active pool-category-#{pool.category}"
|
||||||
else
|
else
|
||||||
prev_rel = nil
|
prev_rel = nil
|
||||||
next_rel = nil
|
next_rel = nil
|
||||||
klass = ""
|
klass = "pool-category-#{pool.category}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if @post.id != pool.post_id_array.first
|
if @post.id != pool.post_id_array.first
|
||||||
|
|||||||
@@ -28,6 +28,15 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th><label for="search_category">Category</th>
|
||||||
|
<td>
|
||||||
|
<div class="input">
|
||||||
|
<%= select "search", "category", [["Series", "series"], ["Collection", "collection"]], :selected => params[:search][:category], :include_blank => true %>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th><label for="search_sort">Order</th>
|
<th><label for="search_sort">Order</th>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<%= f.input :name, :input_html => { :value => @pool.pretty_name } %>
|
<%= f.input :name, :input_html => { :value => @pool.pretty_name } %>
|
||||||
<%= f.input :description %>
|
<%= f.input :description %>
|
||||||
<%= f.input :post_ids, :label => "Posts" %>
|
<%= f.input :post_ids, :label => "Posts" %>
|
||||||
|
<%= f.input :category, :collection => ["series", "collection"], :include_blank => false %>
|
||||||
<%= f.input :is_active %>
|
<%= f.input :is_active %>
|
||||||
<%= f.button :submit %>
|
<%= f.button :submit %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to h(pool.pretty_name), pool_path(pool) %>
|
<%= link_to h(pool.pretty_name), pool_path(pool), :class => "pool-category-#{pool.category}" %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to_user pool.creator %>
|
<%= link_to_user pool.creator %>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<%= f.input :name %>
|
<%= f.input :name %>
|
||||||
<%= f.input :description %>
|
<%= f.input :description %>
|
||||||
<%= f.input :post_ids, :label => "Posts" %>
|
<%= f.input :post_ids, :label => "Posts" %>
|
||||||
|
<%= f.input :category, :collection => ["series", "collection"], :include_blank => false %>
|
||||||
<%= f.input :is_active %>
|
<%= f.input :is_active %>
|
||||||
<%= f.button :submit %>
|
<%= f.button :submit %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
6
db/migrate/20130506154136_add_category_to_pools.rb
Normal file
6
db/migrate/20130506154136_add_category_to_pools.rb
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user