From 083ce75c1078233052ed93a72f5f798c06216565 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 12 Jan 2020 20:54:41 -0600 Subject: [PATCH] pools/gallery: refactor post previews. --- app/controllers/pools_controller.rb | 2 +- app/logical/post_sets/pool_gallery.rb | 20 ------------- app/models/pool.rb | 4 +-- .../post_set_presenters/pool_gallery.rb | 28 ------------------- app/views/pools/gallery.html.erb | 4 ++- app/views/pools/show.html.erb | 4 +-- 6 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 app/logical/post_sets/pool_gallery.rb delete mode 100644 app/presenters/post_set_presenters/pool_gallery.rb diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index 8ca0bb43d..32e4c551d 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -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 diff --git a/app/logical/post_sets/pool_gallery.rb b/app/logical/post_sets/pool_gallery.rb deleted file mode 100644 index 8bccd853d..000000000 --- a/app/logical/post_sets/pool_gallery.rb +++ /dev/null @@ -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 diff --git a/app/models/pool.rb b/app/models/pool.rb index 6adb510db..652490d2d 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -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) diff --git a/app/presenters/post_set_presenters/pool_gallery.rb b/app/presenters/post_set_presenters/pool_gallery.rb deleted file mode 100644 index 52fca8457..000000000 --- a/app/presenters/post_set_presenters/pool_gallery.rb +++ /dev/null @@ -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 diff --git a/app/views/pools/gallery.html.erb b/app/views/pools/gallery.html.erb index a2cb7c6bc..e5b69c7b4 100644 --- a/app/views/pools/gallery.html.erb +++ b/app/views/pools/gallery.html.erb @@ -5,7 +5,9 @@ <%= render "posts/partials/common/inline_blacklist" %>
- <%= @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) %>
diff --git a/app/views/pools/show.html.erb b/app/views/pools/show.html.erb index d3a2fe1a7..d5d19540b 100644 --- a/app/views/pools/show.html.erb +++ b/app/views/pools/show.html.erb @@ -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 %>