merge pool category branch; fixes #1521

This commit is contained in:
Toks
2013-05-26 08:23:46 -04:00
8 changed files with 53 additions and 7 deletions

View File

@@ -1,5 +1,13 @@
@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#a-new {
font-size: 0.8em;

View File

@@ -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"
@@ -13,7 +14,7 @@ class Pool < ActiveRecord::Base
after_save :create_version
after_create :synchronize!
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
@@ -21,6 +22,18 @@ class Pool < ActiveRecord::Base
where("is_deleted = false")
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)
q = scoped
params = {} if params.blank?
@@ -60,6 +73,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
@@ -254,7 +273,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

View File

@@ -161,12 +161,14 @@ class PostPresenter < Presenter
return if pool.nil?
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)
end
else
first = true
@post.pools.each do |pool|
pools = @post.pools.series_first
pools.each do |pool|
if first && template.params[:tags].blank?
html += pool_link_html(template, pool, :include_rel => true)
first = false
@@ -187,11 +189,11 @@ class PostPresenter < Presenter
if options[:include_rel]
prev_rel = "prev"
next_rel = "next"
klass = "active"
klass = "active pool-category-#{pool.category}"
else
prev_rel = nil
next_rel = nil
klass = ""
klass = "pool-category-#{pool.category}"
end
if @post.id != pool.post_id_array.first

View File

@@ -28,6 +28,15 @@
</td>
</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>
<th><label for="search_sort">Order</th>
<td>

View File

@@ -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 %>

View File

@@ -17,7 +17,7 @@
</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>
<%= link_to_user pool.creator %>

View File

@@ -5,6 +5,7 @@
<%= f.input :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 %>

View 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