fixes #2245
This commit is contained in:
@@ -10,6 +10,10 @@ article.post-preview {
|
||||
@include inline-block;
|
||||
position: relative;
|
||||
|
||||
&.pooled {
|
||||
height: 194px;
|
||||
}
|
||||
|
||||
img {
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@ class PoolsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def gallery
|
||||
@pools = Pool.series.search(params[:search]).order("updated_at desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||
@post_set = PostSets::PoolGallery.new(@pools)
|
||||
end
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
20
app/logical/post_sets/pool_gallery.rb
Normal file
20
app/logical/post_sets/pool_gallery.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module PostSets
|
||||
class PoolGallery < PostSets::Base
|
||||
attr_reader :page, :per_page, :pools
|
||||
|
||||
def initialize(pools, page = 1, per_page = nil)
|
||||
@pools = pools
|
||||
@page = page
|
||||
@per_page = (per_page || CurrentUser.per_page).to_i
|
||||
@per_page = 200 if @per_page > 200
|
||||
end
|
||||
|
||||
def current_page
|
||||
[page.to_i, 1].max
|
||||
end
|
||||
|
||||
def presenter
|
||||
@presenter ||= ::PostSetPresenters::PoolGallery.new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,7 +2,7 @@ require 'ostruct'
|
||||
|
||||
class Pool < ActiveRecord::Base
|
||||
validates_uniqueness_of :name, :case_sensitive => false
|
||||
validates_format_of :name, :with => /\A[^\s,]+\Z/, :message => "cannot have whitespace or commas"
|
||||
validates_format_of :name, :with => /\A[^,]+\Z/, :message => "cannot have commas"
|
||||
validates_inclusion_of :category, :in => %w(series collection)
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
@@ -316,6 +316,10 @@ class Pool < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def cover_post_id
|
||||
post_ids[/^(\d+)/, 1]
|
||||
end
|
||||
|
||||
def create_version(force = false)
|
||||
if post_ids_changed? || name_changed? || description_changed? || is_active_changed? || is_deleted_changed? || category_changed? || force
|
||||
last_version = versions.last
|
||||
|
||||
@@ -12,23 +12,33 @@ class PostPresenter < Presenter
|
||||
|
||||
path = options[:path_prefix] || "/posts"
|
||||
|
||||
html = %{<article id="post_#{post.id}" class="#{preview_class(post)}" #{data_attributes(post)}>}
|
||||
html = %{<article id="post_#{post.id}" class="#{preview_class(post, options[:pool])}" #{data_attributes(post)}>}
|
||||
if options[:tags].present?
|
||||
tag_param = "?tags=#{CGI::escape(options[:tags])}"
|
||||
elsif options[:pool_id]
|
||||
tag_param = "?pool_id=#{options[:pool_id]}"
|
||||
elsif options[:pool_id] || options[:pool]
|
||||
tag_param = "?pool_id=#{CGI::escape((options[:pool_id] || options[:pool].id).to_s)}"
|
||||
else
|
||||
tag_param = nil
|
||||
end
|
||||
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
|
||||
html << %{<img src="#{post.preview_file_url}" alt="#{h(post.tag_string)}">}
|
||||
html << %{</a>}
|
||||
|
||||
if options[:pool]
|
||||
html << %{<p class="desc">}
|
||||
html << %{<a href="/pools/#{options[:pool].id}">}
|
||||
html << options[:pool].pretty_name.truncate(40)
|
||||
html << %{</a>}
|
||||
html << %{</p>}
|
||||
end
|
||||
|
||||
html << %{</article>}
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
def self.preview_class(post)
|
||||
def self.preview_class(post, description = nil)
|
||||
klass = "post-preview"
|
||||
klass << " pooled" if description
|
||||
klass << " post-status-pending" if post.is_pending?
|
||||
klass << " post-status-flagged" if post.is_flagged?
|
||||
klass << " post-status-deleted" if post.is_deleted?
|
||||
|
||||
28
app/presenters/post_set_presenters/pool_gallery.rb
Normal file
28
app/presenters/post_set_presenters/pool_gallery.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module PostSetPresenters
|
||||
class PoolGallery < Base
|
||||
attr_accessor :post_set
|
||||
delegate :pools, :to => :post_set
|
||||
|
||||
def initialize(post_set)
|
||||
@post_set = post_set
|
||||
end
|
||||
|
||||
def post_previews_html(template, options = {})
|
||||
html = ""
|
||||
|
||||
if pools.empty?
|
||||
return template.render("post_sets/blank")
|
||||
end
|
||||
|
||||
pools.each do |pool|
|
||||
if pool.cover_post_id
|
||||
post = ::Post.find(pool.cover_post_id)
|
||||
html << PostPresenter.preview(post, options.merge(:tags => @post_set.tag_string, :raw => @post_set.raw, :pool => pool))
|
||||
html << "\n"
|
||||
end
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<menu>
|
||||
<li><%= render "pools/quick_search" %></li>
|
||||
<li><%= link_to "Gallery", gallery_pools_path %></li>
|
||||
<li><%= link_to "Listing", pools_path %></li>
|
||||
<li><%= link_to "New", new_pool_path %></li>
|
||||
<li><%= link_to "Help", wiki_pages_path(:search => {:title => "help:pools"}) %></li>
|
||||
|
||||
15
app/views/pools/gallery.html.erb
Normal file
15
app/views/pools/gallery.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<div id="c-pools">
|
||||
<div id="a-gallery">
|
||||
<section>
|
||||
<%= @post_set.presenter.post_previews_html(self) %>
|
||||
|
||||
<%= numbered_paginator(@pools) %>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Pool Gallery - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -157,6 +157,9 @@ Rails.application.routes.draw do
|
||||
put :revert
|
||||
post :undelete
|
||||
end
|
||||
collection do
|
||||
get :gallery
|
||||
end
|
||||
resource :order, :only => [:edit, :update], :controller => "pool_orders"
|
||||
end
|
||||
resource :pool_element, :only => [:create, :destroy] do
|
||||
|
||||
Reference in New Issue
Block a user