pools/gallery: refactor post previews.
This commit is contained in:
@@ -31,7 +31,7 @@ class PoolsController < ApplicationController
|
||||
search = search_params.presence || ActionController::Parameters.new(category: "series")
|
||||
|
||||
@pools = Pool.search(search).paginate(params[:page], limit: limit, search_count: params[:search])
|
||||
@post_set = PostSets::PoolGallery.new(@pools)
|
||||
respond_with(@pools)
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
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
|
||||
@@ -273,8 +273,8 @@ class Pool < ApplicationRecord
|
||||
post_ids[n]
|
||||
end
|
||||
|
||||
def cover_post_id
|
||||
post_ids.first
|
||||
def cover_post
|
||||
post_count > 0 ? Post.find(post_ids.first) : nil
|
||||
end
|
||||
|
||||
def create_version(updater: CurrentUser.user, updater_ip_addr: CurrentUser.ip_addr)
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
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)
|
||||
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, link_target: pool, pool: pool, show_deleted: true)
|
||||
html << "\n"
|
||||
end
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,9 @@
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<section>
|
||||
<%= @post_set.presenter.post_previews_html(self) %>
|
||||
<% @pools.each do |pool| %>
|
||||
<%= PostPresenter.preview(pool.cover_post, link_target: pool, pool: pool, show_deleted: true) %>
|
||||
<% end %>
|
||||
|
||||
<%= numbered_paginator(@pools) %>
|
||||
</section>
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
<% if @pool.post_count == 0 %>
|
||||
<%= render "post_sets/blank" %>
|
||||
<% else %>
|
||||
<% @posts.each do |post| %>
|
||||
<%= PostPresenter.preview(post, pool_id: @pool.id) %>
|
||||
<% end %>
|
||||
<%= post_previews_html(@posts, pool_id: @pool.id) %>
|
||||
|
||||
<%= numbered_paginator(@posts) %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user