posts: refactor post previews to use ViewComponent.
Refactor the post preview html to use the ViewComponent framework. This lets us encapsulate all the HTML, CSS, and helper methods for a UI component in a single place. See https://viewcomponent.org.
This commit is contained in:
2
app/components/application_component.rb
Normal file
2
app/components/application_component.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class ApplicationComponent < ViewComponent::Base
|
||||
end
|
||||
116
app/components/post_preview_component.rb
Normal file
116
app/components/post_preview_component.rb
Normal file
@@ -0,0 +1,116 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PostPreviewComponent < ApplicationComponent
|
||||
with_collection_parameter :post
|
||||
|
||||
attr_reader :post, :tags, :show_deleted, :show_cropped, :link_target, :pool, :pool_id, :favgroup_id, :similarity, :recommended, :compact, :size, :current_user, :options
|
||||
delegate :external_link_to, :time_ago_in_words_tagged, to: :helpers
|
||||
|
||||
def initialize(post:, tags: "", show_deleted: false, show_cropped: true, link_target: post, pool: nil, pool_id: nil, favgroup_id: nil, similarity: nil, recommended: nil, compact: nil, size: nil, current_user: CurrentUser.user, **options)
|
||||
@post = post
|
||||
@tags = tags
|
||||
@show_deleted = show_deleted
|
||||
@show_cropped = show_cropped
|
||||
@link_target = link_target
|
||||
@pool = pool
|
||||
@pool_id = pool_id
|
||||
@favgroup_id = favgroup_id
|
||||
@similarity = similarity.round(1) if similarity.present?
|
||||
@recommended = recommended.round(1) if recommended.present?
|
||||
@compact = compact
|
||||
@size = post.file_size if size.present?
|
||||
@current_user = current_user
|
||||
@options = options
|
||||
end
|
||||
|
||||
def render?
|
||||
post.present? && post.visible?(current_user) && (!post.is_deleted? || show_deleted)
|
||||
end
|
||||
|
||||
def article_attrs(classes = nil)
|
||||
{ class: [classes, *preview_class].compact.join(" "), **data_attributes }
|
||||
end
|
||||
|
||||
def link_params
|
||||
link_params = {}
|
||||
|
||||
link_params["q"] = tags if tags.present? && !current_user.is_anonymous?
|
||||
link_params["pool_id"] = pool_id if pool_id
|
||||
link_params["favgroup_id"] = favgroup_id if favgroup_id
|
||||
|
||||
link_params
|
||||
end
|
||||
|
||||
def cropped_url
|
||||
if show_cropped && post.has_cropped? && !current_user.disable_cropped_thumbnails?
|
||||
post.crop_file_url
|
||||
else
|
||||
post.preview_file_url
|
||||
end
|
||||
end
|
||||
|
||||
def preview_dimensions
|
||||
# XXX work around ancient bad posts with null or zero dimensions.
|
||||
if post.image_width.to_i > 0 && post.image_height.to_i > 0
|
||||
downscale_ratio = Danbooru.config.small_image_width.to_f / [post.image_width, post.image_height].max
|
||||
|
||||
{
|
||||
width: [(downscale_ratio * post.image_width).floor, post.image_width].min,
|
||||
height: [(downscale_ratio * post.image_height).floor, post.image_height].min
|
||||
}
|
||||
else
|
||||
{ width: 0, height: 0 }
|
||||
end
|
||||
end
|
||||
|
||||
def tooltip
|
||||
"#{post.tag_string} rating:#{post.rating} score:#{post.score}"
|
||||
end
|
||||
|
||||
def preview_class
|
||||
klass = ["post-preview"]
|
||||
klass << "captioned" if pool || size || similarity || recommended
|
||||
klass << "post-status-pending" if post.is_pending?
|
||||
klass << "post-status-flagged" if post.is_flagged?
|
||||
klass << "post-status-deleted" if post.is_deleted?
|
||||
klass << "post-status-has-parent" if post.parent_id
|
||||
klass << "post-status-has-children" if post.has_visible_children?
|
||||
klass << "post-preview-compact" if compact
|
||||
klass
|
||||
end
|
||||
|
||||
def data_attributes
|
||||
attributes = {
|
||||
"data-id" => post.id,
|
||||
"data-has-sound" => post.has_tag?('video_with_sound|flash_with_sound'),
|
||||
"data-tags" => post.tag_string,
|
||||
"data-pools" => post.pool_string,
|
||||
"data-approver-id" => post.approver_id,
|
||||
"data-rating" => post.rating,
|
||||
"data-large-width" => post.large_image_width,
|
||||
"data-large-height" => post.large_image_height,
|
||||
"data-width" => post.image_width,
|
||||
"data-height" => post.image_height,
|
||||
"data-flags" => post.status_flags,
|
||||
"data-parent-id" => post.parent_id,
|
||||
"data-has-children" => post.has_children?,
|
||||
"data-score" => post.score,
|
||||
"data-views" => post.view_count,
|
||||
"data-fav-count" => post.fav_count,
|
||||
"data-pixiv-id" => post.pixiv_id,
|
||||
"data-file-ext" => post.file_ext,
|
||||
"data-source" => post.source,
|
||||
"data-uploader-id" => post.uploader_id,
|
||||
"data-normalized-source" => post.normalized_source,
|
||||
}
|
||||
|
||||
if post.visible?(current_user)
|
||||
attributes["data-md5"] = post.md5
|
||||
attributes["data-file-url"] = post.file_url
|
||||
attributes["data-large-file-url"] = post.large_file_url
|
||||
attributes["data-preview-file-url"] = post.preview_file_url
|
||||
end
|
||||
|
||||
attributes
|
||||
end
|
||||
end
|
||||
@@ -1,10 +1,10 @@
|
||||
<%= content_tag(:article, article_attrs) do -%>
|
||||
<%= tag.article id: "post_#{post.id}", **article_attrs do -%>
|
||||
<%= link_to polymorphic_path(link_target, link_params) do -%>
|
||||
<%= content_tag(:picture) do -%>
|
||||
<picture>
|
||||
<%= tag.source media: "(max-width: 660px)", srcset: cropped_url -%>
|
||||
<%= tag.source media: "(min-width: 660px)", srcset: preview_url -%>
|
||||
<%= tag.img class: "has-cropped-#{has_cropped}", src: preview_url, style: "min-width: #{preview_width}px; min-height: #{preview_height}px;", title: tooltip, alt: alt_text -%>
|
||||
<% end -%>
|
||||
<%= tag.source media: "(min-width: 660px)", srcset: post.preview_file_url -%>
|
||||
<%= tag.img class: "has-cropped-#{post.has_cropped?}", src: post.preview_file_url, style: "min-width: #{preview_dimensions[:width]}px; min-height: #{preview_dimensions[:height]}px;", title: tooltip, alt: "post ##{post.id}" -%>
|
||||
</picture>
|
||||
<% end -%>
|
||||
<% if pool -%>
|
||||
<p class="desc">
|
||||
@@ -24,7 +24,7 @@
|
||||
<% if size -%>
|
||||
<p class="desc">
|
||||
<%= link_to number_to_human_size(size), post.file_url %>
|
||||
(<%= width %>x<%= height %>)
|
||||
(<%= post.image_width %>x<%= post.image_height %>)
|
||||
</p>
|
||||
<% end -%>
|
||||
<% if similarity -%>
|
||||
@@ -0,0 +1,162 @@
|
||||
@import "../../javascript/src/styles/base/000_vars.scss";
|
||||
|
||||
article.post-preview {
|
||||
height: 154px;
|
||||
width: 154px;
|
||||
margin: 0 10px 10px 0;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
|
||||
a {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
&.captioned {
|
||||
height: auto;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
|
||||
&.post-preview-compact {
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 80%;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
img {
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
&[data-tags~=animated]::before, &[data-file-ext=swf]::before, &[data-file-ext=webm]::before, &[data-file-ext=mp4]::before, &[data-file-ext=zip]::before {
|
||||
@include animated-icon;
|
||||
}
|
||||
|
||||
&[data-has-sound=true]::before {
|
||||
@include sound-icon;
|
||||
}
|
||||
}
|
||||
|
||||
/* Avoid dead space around thumbnails in tables. */
|
||||
table article.post-preview {
|
||||
height: auto;
|
||||
width: auto;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.post-preview {
|
||||
img {
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
|
||||
&.post-status-has-children img {
|
||||
border-color: var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent img {
|
||||
border-color: var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-has-parent-color) var(--preview-has-parent-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-deleted img {
|
||||
border-color: var(--preview-deleted-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-deleted img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-deleted-color) var(--preview-deleted-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent.post-status-deleted img {
|
||||
border-color: var(--preview-has-parent-color) var(--preview-deleted-color) var(--preview-deleted-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent.post-status-deleted img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-deleted-color) var(--preview-deleted-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
/* Pending and flagged posts have blue borders (except in the modqueue). */
|
||||
&.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-pending-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-has-children.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-pending-color) var(--preview-pending-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-has-parent.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-has-parent-color) var(--preview-pending-color) var(--preview-pending-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-has-children.post-status-has-parent.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-pending-color) var(--preview-pending-color) var(--preview-has-parent-color);
|
||||
}
|
||||
}
|
||||
|
||||
/* Flagged posts have red borders for approvers. */
|
||||
body[data-current-user-can-approve-posts="true"] .post-preview {
|
||||
&.post-status-flagged img {
|
||||
border-color: var(--preview-flagged-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-flagged img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-flagged-color) var(--preview-flagged-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent.post-status-flagged img {
|
||||
border-color: var(--preview-has-parent-color) var(--preview-flagged-color) var(--preview-flagged-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent.post-status-flagged img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-flagged-color) var(--preview-flagged-color) var(--preview-has-parent-color);
|
||||
}
|
||||
}
|
||||
|
||||
.post-preview.current-post {
|
||||
background-color: var(--preview-current-post-background);
|
||||
}
|
||||
|
||||
@media screen and (max-width: 660px) {
|
||||
article.post-preview {
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
|
||||
a {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 33.3vw;
|
||||
border: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.user-disable-cropped-false {
|
||||
article.post-preview {
|
||||
width: 33.3%;
|
||||
height: 33.3vw;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 33.3vw;
|
||||
height: 33.3vw;
|
||||
|
||||
&.has-cropped-false {
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
module PostsHelper
|
||||
def post_preview(post, **options)
|
||||
render PostPreviewComponent.new(post: post, **options)
|
||||
end
|
||||
|
||||
def post_previews_html(posts, **options)
|
||||
posts.map do |post|
|
||||
PostPresenter.preview(post, **options)
|
||||
end.join("").html_safe
|
||||
render PostPreviewComponent.with_collection(posts, **options)
|
||||
end
|
||||
|
||||
def reportbooru_enabled?
|
||||
|
||||
@@ -28,6 +28,8 @@ require("@fortawesome/fontawesome-free/css/regular.css");
|
||||
|
||||
importAll(require.context('../src/javascripts', true, /\.js(\.erb)?$/));
|
||||
importAll(require.context('../src/styles', true, /\.s?css(?:\.erb)?$/));
|
||||
importAll(require.context('../../components', true, /\.js(\.erb)?$/));
|
||||
importAll(require.context('../../components', true, /\.s?css(?:\.erb)?$/));
|
||||
|
||||
export { default as jQuery } from "jquery";
|
||||
export { default as Autocomplete } from '../src/javascripts/autocomplete.js.erb';
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
@import "../base/000_vars.scss";
|
||||
|
||||
@keyframes heartbeat {
|
||||
0% {
|
||||
transform:scale(1);
|
||||
@@ -24,54 +22,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
article.post-preview {
|
||||
height: 154px;
|
||||
width: 154px;
|
||||
margin: 0 10px 10px 0;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
|
||||
a {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
&.captioned {
|
||||
height: auto;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
|
||||
&.post-preview-compact {
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 80%;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
img {
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
&[data-tags~=animated]::before, &[data-file-ext=swf]::before, &[data-file-ext=webm]::before, &[data-file-ext=mp4]::before, &[data-file-ext=zip]::before {
|
||||
@include animated-icon;
|
||||
}
|
||||
|
||||
&[data-has-sound=true]::before {
|
||||
@include sound-icon;
|
||||
}
|
||||
}
|
||||
|
||||
/* Avoid dead space around thumbnails in tables. */
|
||||
table article.post-preview {
|
||||
height: auto;
|
||||
width: auto;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#saved-searches-nav {
|
||||
margin-top: 1em;
|
||||
}
|
||||
@@ -89,84 +39,6 @@ table article.post-preview {
|
||||
}
|
||||
}
|
||||
|
||||
.post-preview {
|
||||
img {
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
|
||||
&.post-status-has-children img {
|
||||
border-color: var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent img {
|
||||
border-color: var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-has-parent-color) var(--preview-has-parent-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-deleted img {
|
||||
border-color: var(--preview-deleted-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-deleted img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-deleted-color) var(--preview-deleted-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent.post-status-deleted img {
|
||||
border-color: var(--preview-has-parent-color) var(--preview-deleted-color) var(--preview-deleted-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent.post-status-deleted img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-deleted-color) var(--preview-deleted-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
/* Pending and flagged posts have blue borders (except in the modqueue). */
|
||||
&.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-pending-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-has-children.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-pending-color) var(--preview-pending-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-has-parent.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-has-parent-color) var(--preview-pending-color) var(--preview-pending-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent.post-status-pending:not(.mod-queue-preview) img,
|
||||
&.post-status-has-children.post-status-has-parent.post-status-flagged:not(.mod-queue-preview) img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-pending-color) var(--preview-pending-color) var(--preview-has-parent-color);
|
||||
}
|
||||
}
|
||||
|
||||
/* Flagged posts have red borders for approvers. */
|
||||
body[data-current-user-can-approve-posts="true"] .post-preview {
|
||||
&.post-status-flagged img {
|
||||
border-color: var(--preview-flagged-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-flagged img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-flagged-color) var(--preview-flagged-color) var(--preview-has-children-color);
|
||||
}
|
||||
|
||||
&.post-status-has-parent.post-status-flagged img {
|
||||
border-color: var(--preview-has-parent-color) var(--preview-flagged-color) var(--preview-flagged-color) var(--preview-has-parent-color);
|
||||
}
|
||||
|
||||
&.post-status-has-children.post-status-has-parent.post-status-flagged img {
|
||||
border-color: var(--preview-has-children-color) var(--preview-flagged-color) var(--preview-flagged-color) var(--preview-has-parent-color);
|
||||
}
|
||||
}
|
||||
|
||||
.post-preview.current-post {
|
||||
background-color: var(--preview-current-post-background);
|
||||
}
|
||||
|
||||
#has-parent-relationship-preview, #has-children-relationship-preview {
|
||||
overflow-x: auto;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -66,37 +66,4 @@
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
article.post-preview {
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
|
||||
a {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 33.3vw;
|
||||
border: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.user-disable-cropped-false {
|
||||
article.post-preview {
|
||||
width: 33.3%;
|
||||
height: 33.3vw;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 33.3vw;
|
||||
height: 33.3vw;
|
||||
|
||||
&.has-cropped-false {
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,20 +140,6 @@ module PostSets
|
||||
@pending_bulk_update_requests ||= BulkUpdateRequest.pending.where_array_includes_any(:tags, tag.name)
|
||||
end
|
||||
|
||||
def post_previews_html(template)
|
||||
html = ""
|
||||
if shown_posts.empty?
|
||||
return template.render("post_sets/blank")
|
||||
end
|
||||
|
||||
shown_posts.each do |post|
|
||||
html << PostPresenter.preview(post, show_deleted: show_deleted?, show_cropped: true, tags: tag_string)
|
||||
html << "\n"
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
def show_deleted?
|
||||
query.select_metatags("status").any? do |metatag|
|
||||
metatag.value.in?(%w[all any active unmoderated modqueue deleted appealed])
|
||||
|
||||
@@ -2,147 +2,6 @@ class PostPresenter
|
||||
attr_reader :pool, :next_post_in_pool
|
||||
delegate :tag_list_html, :split_tag_list_html, :split_tag_list_text, :inline_tag_list_html, to: :tag_set_presenter
|
||||
|
||||
def self.preview(post, show_deleted: false, tags: "", **options)
|
||||
if post.nil?
|
||||
return "<em>none</em>".html_safe
|
||||
end
|
||||
|
||||
if post.is_deleted? && !show_deleted
|
||||
return ""
|
||||
end
|
||||
|
||||
if !post.visible?
|
||||
return ""
|
||||
end
|
||||
|
||||
if post.is_ugoira? && !post.has_ugoira_webm?
|
||||
# ugoira preview gen is async so dont render it immediately
|
||||
return ""
|
||||
end
|
||||
|
||||
locals = {}
|
||||
locals[:post] = post
|
||||
|
||||
locals[:article_attrs] = {
|
||||
"id" => "post_#{post.id}",
|
||||
"class" => preview_class(post, **options).join(" ")
|
||||
}.merge(data_attributes(post))
|
||||
|
||||
locals[:link_target] = options[:link_target] || post
|
||||
|
||||
locals[:link_params] = {}
|
||||
if tags.present? && !CurrentUser.is_anonymous?
|
||||
locals[:link_params]["q"] = tags
|
||||
end
|
||||
if options[:pool_id]
|
||||
locals[:link_params]["pool_id"] = options[:pool_id]
|
||||
end
|
||||
if options[:favgroup_id]
|
||||
locals[:link_params]["favgroup_id"] = options[:favgroup_id]
|
||||
end
|
||||
|
||||
locals[:tooltip] = "#{post.tag_string} rating:#{post.rating} score:#{post.score}"
|
||||
|
||||
locals[:cropped_url] = if options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
|
||||
post.crop_file_url
|
||||
else
|
||||
post.preview_file_url
|
||||
end
|
||||
|
||||
locals[:preview_url] = post.preview_file_url
|
||||
|
||||
locals[:alt_text] = "post ##{post.id}"
|
||||
|
||||
locals[:has_cropped] = post.has_cropped?
|
||||
|
||||
if options[:pool]
|
||||
locals[:pool] = options[:pool]
|
||||
else
|
||||
locals[:pool] = nil
|
||||
end
|
||||
|
||||
locals[:width] = post.image_width
|
||||
locals[:height] = post.image_height
|
||||
|
||||
# XXX work around ancient bad posts with null or zero dimensions.
|
||||
if post.image_width.to_i > 0 && post.image_height.to_i > 0
|
||||
downscale_ratio = Danbooru.config.small_image_width.to_f / [post.image_width, post.image_height].max
|
||||
locals[:preview_width] = [(downscale_ratio * post.image_width).floor, post.image_width].min
|
||||
locals[:preview_height] = [(downscale_ratio * post.image_height).floor, post.image_height].min
|
||||
else
|
||||
locals[:preview_width] = 0
|
||||
locals[:preview_height] = 0
|
||||
end
|
||||
|
||||
if options[:similarity]
|
||||
locals[:similarity] = options[:similarity].round(1)
|
||||
else
|
||||
locals[:similarity] = nil
|
||||
end
|
||||
|
||||
if options[:size]
|
||||
locals[:size] = post.file_size
|
||||
else
|
||||
locals[:size] = nil
|
||||
end
|
||||
|
||||
if options[:recommended]
|
||||
locals[:recommended] = options[:recommended].round(1)
|
||||
else
|
||||
locals[:recommended] = nil
|
||||
end
|
||||
|
||||
ApplicationController.render(partial: "posts/partials/index/preview", locals: locals)
|
||||
end
|
||||
|
||||
def self.preview_class(post, pool: nil, size: nil, similarity: nil, recommended: nil, compact: nil, **options)
|
||||
klass = ["post-preview"]
|
||||
# klass << " large-cropped" if post.has_cropped? && options[:show_cropped]
|
||||
klass << "captioned" if pool || size || similarity || recommended
|
||||
klass << "post-status-pending" if post.is_pending?
|
||||
klass << "post-status-flagged" if post.is_flagged?
|
||||
klass << "post-status-deleted" if post.is_deleted?
|
||||
klass << "post-status-has-parent" if post.parent_id
|
||||
klass << "post-status-has-children" if post.has_visible_children?
|
||||
klass << "post-preview-compact" if compact
|
||||
klass
|
||||
end
|
||||
|
||||
def self.data_attributes(post)
|
||||
attributes = {
|
||||
"data-id" => post.id,
|
||||
"data-has-sound" => post.has_tag?('video_with_sound|flash_with_sound'),
|
||||
"data-tags" => post.tag_string,
|
||||
"data-pools" => post.pool_string,
|
||||
"data-approver-id" => post.approver_id,
|
||||
"data-rating" => post.rating,
|
||||
"data-large-width" => post.large_image_width,
|
||||
"data-large-height" => post.large_image_height,
|
||||
"data-width" => post.image_width,
|
||||
"data-height" => post.image_height,
|
||||
"data-flags" => post.status_flags,
|
||||
"data-parent-id" => post.parent_id,
|
||||
"data-has-children" => post.has_children?,
|
||||
"data-score" => post.score,
|
||||
"data-views" => post.view_count,
|
||||
"data-fav-count" => post.fav_count,
|
||||
"data-pixiv-id" => post.pixiv_id,
|
||||
"data-file-ext" => post.file_ext,
|
||||
"data-source" => post.source,
|
||||
"data-uploader-id" => post.uploader_id,
|
||||
"data-normalized-source" => post.normalized_source,
|
||||
}
|
||||
|
||||
if post.visible?
|
||||
attributes["data-md5"] = post.md5
|
||||
attributes["data-file-url"] = post.file_url
|
||||
attributes["data-large-file-url"] = post.large_file_url
|
||||
attributes["data-preview-file-url"] = post.preview_file_url
|
||||
end
|
||||
|
||||
attributes
|
||||
end
|
||||
|
||||
def initialize(post)
|
||||
@post = post
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<%= table_for @commentaries, width: "100%" do |t| %>
|
||||
<% t.column "Post", width: "1%" do |commentary| %>
|
||||
<%= PostPresenter.preview(commentary.post, show_deleted: true) %>
|
||||
<%= post_preview(commentary.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Original" do |commentary| %>
|
||||
<%= format_commentary_title(commentary.original_title) %>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<div id="p-<%= listing_type(:post_id) %>-listing">
|
||||
|
||||
<% if listing_type(:post_id) == :revert && @commentary_versions.present? %>
|
||||
<%= PostPresenter.preview(@commentary_versions.first.post, show_deleted: true) %>
|
||||
<%= post_preview(@commentary_versions.first.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
|
||||
<%= table_for @commentary_versions, class: "striped" do |t| %>
|
||||
<% if listing_type(:post_id) == :standard %>
|
||||
<% t.column "Post", width: "1%" do |commentary_version| %>
|
||||
<%= PostPresenter.preview(commentary_version.post, show_deleted: true) %>
|
||||
<%= post_preview(commentary_version.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if listing_type(:post_id) == :standard %>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<%= table_for @comment_votes, class: "striped autofit" do |t| %>
|
||||
<% t.column "Post" do |vote| %>
|
||||
<%= PostPresenter.preview(vote.comment.post, show_deleted: true) %>
|
||||
<%= post_preview(vote.comment.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Comment", td: {class: "col-expand"} do |vote| %>
|
||||
<div class="prose">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="list-of-comments list-of-messages">
|
||||
<% @comments.each do |comment| %>
|
||||
<% if CurrentUser.is_moderator? || (params[:search] && params[:search][:is_deleted] =~ /t/) || !comment.is_deleted? %>
|
||||
<%= content_tag(:div, { id: "post_#{comment.post.id}", class: ["post", *PostPresenter.preview_class(comment.post)].join(" ") }.merge(PostPresenter.data_attributes(comment.post))) do %>
|
||||
<%= tag.div id: "post_#{comment.post.id}", **PostPreviewComponent.new(post: comment.post).article_attrs("post") do %>
|
||||
<div class="preview">
|
||||
<% if policy(comment.post).visible? %>
|
||||
<%= link_to(image_tag(comment.post.preview_file_url), post_path(comment.post)) %>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<% @posts.select(&:visible?).each do |post| %>
|
||||
<% if post.comments.unhidden(CurrentUser.user).any? || post.comments.hidden(CurrentUser.user).any? %>
|
||||
<%= content_tag(:div, { id: "post_#{post.id}", class: ["post", *PostPresenter.preview_class(post)].join(" ") }.merge(PostPresenter.data_attributes(post))) do %>
|
||||
<%= tag.div id: "post_#{post.id}", **PostPreviewComponent.new(post: post).article_attrs("post") do %>
|
||||
<div class="preview">
|
||||
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<ul id="sortable">
|
||||
<% @favorite_group.posts.limit(1_000).each do |post| %>
|
||||
<li class="ui-state-default" id="favorite_group[post_ids]_<%= post.id %>">
|
||||
<%= PostPresenter.preview(post, show_deleted: true).presence || "Hidden: Post ##{post.id}" %>
|
||||
<%= post_preview(post, show_deleted: true).presence || "Hidden: Post ##{post.id}" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
<span class="iqdb-posts-high-similarity">
|
||||
<% @high_similarity_matches.each do |match| %>
|
||||
<%= PostPresenter.preview(match["post"], show_deleted: true, similarity: match["score"], size: true) %>
|
||||
<%= post_preview(match["post"], show_deleted: true, similarity: match["score"], size: true) %>
|
||||
<% end %>
|
||||
</span>
|
||||
|
||||
<span class="iqdb-posts-low-similarity" style="display: none">
|
||||
<% @low_similarity_matches.each do |match| %>
|
||||
<%= PostPresenter.preview(match["post"], show_deleted: true, similarity: match["score"], size: true) %>
|
||||
<%= post_preview(match["post"], show_deleted: true, similarity: match["score"], size: true) %>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<h1>Move Favorites to Parent</h1>
|
||||
|
||||
<div>
|
||||
<%= PostPresenter.preview(@post, show_deleted: true) %>
|
||||
<%= post_preview(@post, show_deleted: true) %>
|
||||
</div>
|
||||
|
||||
<p style="clear: both;">This will move all the post's favorites to its parent post. Are you sure?</p>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<%= content_tag(:div, { id: "post-#{post.id}", class: ["post", "mod-queue-preview", "column-container", *PostPresenter.preview_class(post)].join(" ") }.merge(PostPresenter.data_attributes(post))) do %>
|
||||
<%= tag.div id: "post-#{post.id}", **PostPreviewComponent.new(post: post).article_attrs("post mod-queue-preview column-container") do %>
|
||||
<aside class="column column-shrink">
|
||||
<%= PostPresenter.preview(post, size: true, show_deleted: true) %>
|
||||
<%= post_preview(post, size: true, show_deleted: true) %>
|
||||
</aside>
|
||||
|
||||
<section class="column column-expand">
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<ul id="sortable">
|
||||
<% @pool.posts.each do |post| %>
|
||||
<li class="ui-state-default" id="pool[post_ids]_<%= post.id %>">
|
||||
<%= PostPresenter.preview(post, show_deleted: true).presence || "Hidden: Post ##{post.id}" %>
|
||||
<%= post_preview(post, show_deleted: true).presence || "Hidden: Post ##{post.id}" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<section>
|
||||
<% @pools.each do |pool| %>
|
||||
<%= PostPresenter.preview(pool.cover_post, link_target: pool, pool: pool, show_deleted: true) %>
|
||||
<%= post_preview(pool.cover_post, link_target: pool, pool: pool, show_deleted: true) %>
|
||||
<% end %>
|
||||
|
||||
<%= numbered_paginator(@pools) %>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<%= table_for @post_appeals, width: "100%" do |t| %>
|
||||
<% t.column "Post", width: "1%" do |post_appeal| %>
|
||||
<%= PostPresenter.preview(post_appeal.post, show_deleted: true) %>
|
||||
<%= post_preview(post_appeal.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Reason" do |post_appeal| %>
|
||||
<span class="prose">
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<%= table_for @post_approvals, width: "100%" do |t| %>
|
||||
<% t.column "Post", width: "1%" do |post_approval| %>
|
||||
<%= PostPresenter.preview(post_approval.post, show_deleted: true) %>
|
||||
<%= post_preview(post_approval.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Approver", width: "15%" do |post_approval| %>
|
||||
<%= link_to_user post_approval.user %>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<%= table_for @post_flags, width: "100%" do |t| %>
|
||||
<% t.column "Post", width: "1%" do |post_flag| %>
|
||||
<%= PostPresenter.preview(post_flag.post, show_deleted: true) %>
|
||||
<%= post_preview(post_flag.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Reason" do |post_flag| %>
|
||||
<span class="prose">
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<%= table_for @post_replacements, class: "striped autofit", width: "100%" do |t| %>
|
||||
<% t.column "Post", width: "1%" do |post_replacement| %>
|
||||
<%= PostPresenter.preview(post_replacement.post, show_deleted: true) %>
|
||||
<%= post_preview(post_replacement.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Source" do |post_replacement| %>
|
||||
<dl>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div id="p-<%= listing_type(:post_id) %>-listing">
|
||||
<% if listing_type(:post_id) == :revert %>
|
||||
<%= PostPresenter.preview(@post_versions.first.post, show_deleted: true) %>
|
||||
<%= post_preview(@post_versions.first.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
|
||||
<%= table_for @post_versions, id: "post-versions-table", class: "striped autofit", width: "100%" do |t| %>
|
||||
@@ -11,7 +11,7 @@
|
||||
<% end %>
|
||||
<% if listing_type(:post_id) == :standard %>
|
||||
<% t.column "Post", width: "1%" do |post_version| %>
|
||||
<%= PostPresenter.preview(post_version.post, show_deleted: true) %>
|
||||
<%= post_preview(post_version.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% t.column "Version", width: "1%" do |post_version| %>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<%= table_for @post_votes, class: "striped autofit" do |t| %>
|
||||
<% t.column "Post" do |vote| %>
|
||||
<%= PostPresenter.preview(vote.post, show_deleted: true) %>
|
||||
<%= post_preview(vote.post, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Tags", td: {class: "col-expand"} do |vote| %>
|
||||
<%= TagSetPresenter.new(vote.post.tag_array).inline_tag_list_html %>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<div id="posts" class="user-disable-cropped-<%= CurrentUser.user.disable_cropped_thumbnails? %>">
|
||||
<div id="posts-container">
|
||||
<%= post_set.post_previews_html(self) %>
|
||||
<% if post_set.shown_posts.empty? %>
|
||||
<%= render "post_sets/blank" %>
|
||||
<% else %>
|
||||
<%= post_previews_html(post_set.posts, show_deleted: post_set.show_deleted?, show_cropped: true, tags: post_set.tag_string) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if post_set.hidden_posts.present? %>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<div class="post-tooltip-body <%= "has-preview" if params[:preview].truthy? %>">
|
||||
<div class="post-tooltip-body-left">
|
||||
<% if params[:preview].truthy? %>
|
||||
<%= PostPresenter.preview(@post, show_deleted: true, compact: true) %>
|
||||
<%= post_preview(@post, show_deleted: true, compact: true) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
<%= render "posts/partials/show/notices", :post => @post %>
|
||||
|
||||
<%= content_tag(:section, class: "image-container note-container", **PostPresenter.data_attributes(@post)) do -%>
|
||||
<%= content_tag(:section, class: "image-container note-container", **PostPreviewComponent.new(post: @post).data_attributes) do -%>
|
||||
<%= render "posts/partials/show/embedded", post: @post %>
|
||||
<div id="note-preview"></div>
|
||||
<% end -%>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% if @post.valid? %>
|
||||
var $post = $("#post_<%= @post.id %>");
|
||||
var $new_post = $("<%= j PostPresenter.preview(@post, show_deleted: true) %>");
|
||||
var $new_post = $("<%= j post_preview(@post, show_deleted: true) %>");
|
||||
Danbooru.Blacklist.apply_post($new_post.get(0));
|
||||
$("#post_<%= @post.id %>").replaceWith($new_post);
|
||||
<% if params[:mode] == "quick-edit" %>
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
<% end %>
|
||||
|
||||
<% @recs.each do |rec| %>
|
||||
<%= PostPresenter.preview(rec[:post], recommended: 100*rec[:score]) %>
|
||||
<%= post_preview(rec[:post], recommended: 100*rec[:score]) %>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<%= table_for @upload_reports do |t| %>
|
||||
<% t.column "Post ID", width: "10%" do |upload_report| %>
|
||||
<%= PostPresenter.preview(upload_report.becomes(Post), show_deleted: true, tags: "user:#{upload_report.uploader.name}") %>
|
||||
<%= post_preview(upload_report.becomes(Post), show_deleted: true, tags: "user:#{upload_report.uploader.name}") %>
|
||||
<% end %>
|
||||
<% t.column "Tags added by uploader", width: "45%" do |upload_report| %>
|
||||
<%= TagSetPresenter.new(upload_report.uploader_tags_array).inline_tag_list_html %>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<div>
|
||||
<% source.related_posts.each do |post| %>
|
||||
<%= PostPresenter.preview(post, show_deleted: true, size: true) %>
|
||||
<%= post_preview(post, show_deleted: true, size: true) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<%= table_for @uploads, class: "striped autofit", width: "100%" do |t| %>
|
||||
<% t.column "Upload" do |upload| %>
|
||||
<%= PostPresenter.preview(upload.post, tags: "user:#{upload.uploader.name}", show_deleted: true) %>
|
||||
<%= post_preview(upload.post, tags: "user:#{upload.uploader.name}", show_deleted: true) %>
|
||||
<% end %>
|
||||
<% t.column "Info", td: {class: "col-expand upload-info"} do |upload| %>
|
||||
<span class="info">
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
<%= link_to "Uploads", posts_path(:tags => "user:#{user.name}") %>
|
||||
</h2>
|
||||
<div>
|
||||
<% presenter.uploads.each do |post| %>
|
||||
<%= PostPresenter.preview(post, :tags => "user:#{user.name}") %>
|
||||
<% end %>
|
||||
<%= post_previews_html(presenter.uploads, tags: "user:#{user.name}") %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -17,9 +15,7 @@
|
||||
<%= link_to "Favorites", posts_path(tags: "ordfav:#{user.name}") %>
|
||||
</h2>
|
||||
<div>
|
||||
<% presenter.favorites.each do |post| %>
|
||||
<%= PostPresenter.preview(post, tags: "ordfav:#{user.name}") %>
|
||||
<% end %>
|
||||
<%= post_previews_html(presenter.favorites, tags: "ordfav:#{user.name}") %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -33,9 +29,7 @@
|
||||
</h2>
|
||||
|
||||
<div class="box">
|
||||
<% presenter.posts_for_saved_search_category(label).each do |post| %>
|
||||
<%= PostPresenter.preview(post, :tags => "search:#{label}") %>
|
||||
<% end %>
|
||||
<%= post_previews_html(presenter.posts_for_saved_search_category, tags: "search:#{label}") %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user