This commit is contained in:
r888888888
2014-08-25 16:41:27 -07:00
parent 3c4119663e
commit 267df896c6
9 changed files with 95 additions and 5 deletions

View File

@@ -10,6 +10,10 @@ article.post-preview {
@include inline-block;
position: relative;
&.pooled {
height: 194px;
}
img {
margin: auto;
}

View File

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

View 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

View File

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

View File

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

View 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

View File

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

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

View File

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