forked from e621ng/e621ng
Add post status below post on index pages
This commit is contained in:
parent
813a700b26
commit
1861441100
@ -146,6 +146,22 @@ module PostsHelper
|
||||
Tag.scan_query(params[:tags]).size == 1 && TagChangeNoticeService.get_forum_topic_id(params[:tags])
|
||||
end
|
||||
|
||||
def post_stats_section(post)
|
||||
status_flags = []
|
||||
status_flags << 'P' if post.parent_id
|
||||
status_flags << 'C' if post.has_children?
|
||||
status_flags << 'U' if post.is_pending?
|
||||
status_flags << 'F' if post.is_flagged?
|
||||
|
||||
post_score_icon = "#{"↑" if post.score > 0}#{"↓" if post.score < 0}#{"↕" if post.score == 0}"
|
||||
score = tag.span("#{post_score_icon}#{post.score}".html_safe, class: "post-score-score " + score_class(post.score))
|
||||
favs = tag.span("♥#{post.fav_count}".html_safe, class: 'post-score-faves')
|
||||
comments = tag.span "C#{post.comment_count}", class: 'post-score-comments'
|
||||
rating = tag.span(post.rating.upcase, class: "post-score-rating")
|
||||
status = tag.span(status_flags.join(''), class: 'post-score-extras')
|
||||
tag.div score + favs + comments + rating + status, class: 'post-score', id: "post-score-#{post.id}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def nav_params_for(page)
|
||||
@ -158,11 +174,6 @@ module PostsHelper
|
||||
vote_score = voted ? vote.score : 0
|
||||
post_score = post.score
|
||||
|
||||
def score_class(score)
|
||||
return 'score-neutral' if score == 0
|
||||
score > 0 ? 'score-positive' : 'score-negative'
|
||||
end
|
||||
|
||||
def confirm_score_class(score, want)
|
||||
return 'score-neutral' if score != want || score == 0
|
||||
score_class(score)
|
||||
@ -178,4 +189,9 @@ module PostsHelper
|
||||
score_tag = tag.span(post.score, class: "post-score #{score_class(post_score)}", id: "post-score-#{post.id}", title: "#{post.up_score} up/#{post.down_score} down")
|
||||
score_tag + (CurrentUser.is_voter? ? vote_block : '')
|
||||
end
|
||||
|
||||
def score_class(score)
|
||||
return 'score-neutral' if score == 0
|
||||
score > 0 ? 'score-positive' : 'score-negative'
|
||||
end
|
||||
end
|
||||
|
@ -181,7 +181,7 @@ module PostIndex
|
||||
tag_count_meta: tag_count_meta,
|
||||
tag_count_species: tag_count_species,
|
||||
tag_count_invalid: tag_count_invalid,
|
||||
comment_count: options[:comment_count] || Comment.where(post_id: id).count,
|
||||
comment_count: options[:comment_count] || comment_count,
|
||||
|
||||
file_size: file_size,
|
||||
parent: parent_id,
|
||||
|
@ -35,6 +35,10 @@ $red_color: #e45f5f;
|
||||
$green_color: #3e9e49;
|
||||
$dark_grey_color: hsl(0, 0%, 50%);
|
||||
|
||||
$explicit_rating_color: $red_color;
|
||||
$questionable_rating_color: hsl(50, 100%, 70%);
|
||||
$safe_rating_color: $green_color;
|
||||
|
||||
@mixin animated-icon {
|
||||
content: "►";
|
||||
position: absolute;
|
||||
|
@ -41,12 +41,31 @@ article.post-preview {
|
||||
}
|
||||
|
||||
.desc {
|
||||
background-color: $grey_color;
|
||||
font-size: 80%;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.post-score>span {
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
&.post-rating-explicit .post-score-rating {
|
||||
color: $explicit_rating_color;
|
||||
}
|
||||
|
||||
&.post-rating-safe .post-score-rating {
|
||||
color: $safe_rating_color;
|
||||
}
|
||||
|
||||
&.post-rating-questionable .post-score-rating {
|
||||
color: $questionable_rating_color;
|
||||
}
|
||||
|
||||
img {
|
||||
margin: auto;
|
||||
max-height: 150px;
|
||||
max-width: 150px;
|
||||
}
|
||||
|
||||
&[data-tags~=animated]:before, &[data-file-ext=swf]:before, &[data-file-ext=webm]:before, &[data-file-ext=mp4]:before, &[data-file-ext=zip]:before {
|
||||
|
@ -170,10 +170,16 @@
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: none;
|
||||
max-height: none;
|
||||
width: 33.3vw;
|
||||
border: none !important;
|
||||
}
|
||||
|
||||
.desc {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&[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;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ class Comment < ApplicationRecord
|
||||
validate :validate_post_exists, :on => :create
|
||||
validate :validate_creator_is_not_limited, :on => :create
|
||||
validates_presence_of :body, :message => "has no content"
|
||||
belongs_to :post
|
||||
belongs_to :post, counter_cache: :comment_count
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
user_status_counter :comment_count
|
||||
|
@ -20,6 +20,8 @@ class PostPresenter < Presenter
|
||||
return ""
|
||||
end
|
||||
|
||||
options[:stats] |= !options[:avatar] && !options[:inline]
|
||||
|
||||
locals = {}
|
||||
|
||||
locals[:article_attrs] = {
|
||||
@ -40,7 +42,7 @@ class PostPresenter < Presenter
|
||||
locals[:link_params]["post_set_id"] = options[:post_set_id]
|
||||
end
|
||||
|
||||
locals[:tooltip] = "#{post.tag_string} rating:#{post.rating} score:#{post.score}"
|
||||
locals[:tooltip] = "Rating: #{post.rating}\nID: #{post.id}\nStatus: #{post.status}\nScore: #{post.score}\n\n#{post.tag_string}"
|
||||
|
||||
locals[:cropped_url] = if Danbooru.config.enable_image_cropping && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
|
||||
post.crop_file_url
|
||||
@ -80,13 +82,18 @@ class PostPresenter < Presenter
|
||||
locals[:size] = nil
|
||||
end
|
||||
|
||||
if options[:stats]
|
||||
locals[:post] = post
|
||||
locals[:stats] = true
|
||||
end
|
||||
|
||||
ApplicationController.render(partial: "posts/partials/index/preview", locals: locals)
|
||||
end
|
||||
|
||||
def self.preview_class(post, highlight_score: nil, pool: nil, size: nil, similarity: nil, **options)
|
||||
klass = ["post-preview"]
|
||||
# klass << " large-cropped" if post.has_cropped? && options[:show_cropped]
|
||||
klass << "captioned" if pool || size || similarity
|
||||
klass = ["post-preview", "captioned"]
|
||||
# Always captioned with new post stats section.
|
||||
# klass << "captioned" if pool || size || similarity
|
||||
klass << "post-status-pending" if post.is_pending?
|
||||
klass << "post-status-flagged" if post.is_flagged?
|
||||
klass << "post-status-deleted" if post.is_deleted?
|
||||
@ -94,6 +101,9 @@ class PostPresenter < Presenter
|
||||
klass << "post-status-has-children" if post.has_visible_children?
|
||||
klass << "post-pos-score" if highlight_score && post.score >= 3
|
||||
klass << "post-neg-score" if highlight_score && post.score <= -3
|
||||
klass << "post-rating-safe" if post.rating == 's'
|
||||
klass << "post-rating-questionable" if post.rating == 'q'
|
||||
klass << "post-rating-explicit" if post.rating == 'e'
|
||||
klass
|
||||
end
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
<%= content_tag(:article, article_attrs) do -%>
|
||||
<%= link_to polymorphic_path(link_target, link_params) do -%>
|
||||
<%= content_tag(:picture) do -%>
|
||||
<%= tag.source media: "(max-width: 660px)", srcset: cropped_url -%>
|
||||
<%= tag.source media: "(min-width: 660px)", srcset: preview_url -%>
|
||||
<%= tag.source media: "(max-width: 800px)", srcset: cropped_url -%>
|
||||
<%= tag.source media: "(min-width: 800px)", srcset: preview_url -%>
|
||||
<%= tag.img class: "has-cropped-#{has_cropped}", src: preview_url, title: tooltip, alt: alt_text -%>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% if stats -%>
|
||||
<div class="desc">
|
||||
<%= post_stats_section(post) %>
|
||||
</div>
|
||||
<% end -%>
|
||||
<% if pool -%>
|
||||
<p class="desc">
|
||||
<%= link_to pool.pretty_name.truncate(80), pool %>
|
||||
|
5
db/migrate/20190804010156_add_post_comment_counter.rb
Normal file
5
db/migrate/20190804010156_add_post_comment_counter.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddPostCommentCounter < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :posts, :comment_count, :integer, null: false, default: 0
|
||||
end
|
||||
end
|
@ -1966,7 +1966,8 @@ CREATE TABLE public.posts (
|
||||
locked_tags text,
|
||||
tag_count_species integer DEFAULT 0 NOT NULL,
|
||||
tag_count_invalid integer DEFAULT 0 NOT NULL,
|
||||
description text DEFAULT ''::text NOT NULL
|
||||
description text DEFAULT ''::text NOT NULL,
|
||||
comment_count integer DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@ -5184,6 +5185,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20190714122705'),
|
||||
('20190717205018'),
|
||||
('20190718201354'),
|
||||
('20190801210547');
|
||||
('20190801210547'),
|
||||
('20190804010156');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user