diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 4fc442d17..f5096ef6f 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -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,24 +174,24 @@ 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) end up_tag = tag.span(tag.a('▲'.html_safe, class: 'post-vote-up-link', 'data-id': post.id), - class: confirm_score_class(vote_score, 1), - id: "post-vote-up-#{post.id}") + class: confirm_score_class(vote_score, 1), + id: "post-vote-up-#{post.id}") down_tag = tag.span(tag.a('▼'.html_safe, class: 'post-vote-down-link', 'data-id': post.id), - class: confirm_score_class(vote_score, -1), - id: "post-vote-down-#{post.id}") - vote_block = tag.span(" (vote ".html_safe + up_tag + "/" + down_tag + ")") + class: confirm_score_class(vote_score, -1), + id: "post-vote-down-#{post.id}") + vote_block = tag.span(" (vote ".html_safe + up_tag + "/" + down_tag + ")") 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 diff --git a/app/indexes/post_index.rb b/app/indexes/post_index.rb index 05d0d86dd..fb1e729b5 100644 --- a/app/indexes/post_index.rb +++ b/app/indexes/post_index.rb @@ -127,7 +127,7 @@ module PostIndex scores = scores[1..-2].split(",").map(&:to_i) [pid.to_i, uids.zip(scores)] end - + upvote_ids = vote_ids.map { |pid, user| [pid, user.reject { |uid, s| s <= 0 }.map {|uid, _| uid}] }.to_h downvote_ids = vote_ids.map { |pid, user| [pid, user.reject { |uid, s| s >= 0 }.map {|uid, _| uid}] }.to_h @@ -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, diff --git a/app/javascript/src/styles/base/000_vars.scss b/app/javascript/src/styles/base/000_vars.scss index e242a9b3b..d12658aa7 100644 --- a/app/javascript/src/styles/base/000_vars.scss +++ b/app/javascript/src/styles/base/000_vars.scss @@ -35,12 +35,16 @@ $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; width: 20px; height: 20px; - color: white; + color: white; background-color: rgba(0,0,0,0.5); margin: 2px; text-align: center; @@ -51,7 +55,7 @@ $dark_grey_color: hsl(0, 0%, 50%); position: absolute; width: 20px; height: 20px; - color: white; + color: white; background-color: rgba(0,0,0,0.5); margin: 2px; text-align: center; diff --git a/app/javascript/src/styles/specific/posts.scss b/app/javascript/src/styles/specific/posts.scss index da3bfb49d..6b32712c2 100644 --- a/app/javascript/src/styles/specific/posts.scss +++ b/app/javascript/src/styles/specific/posts.scss @@ -41,12 +41,31 @@ article.post-preview { } .desc { - font-size: 80%; - margin-bottom: 0; + 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 { diff --git a/app/javascript/src/styles/specific/z_responsive.scss b/app/javascript/src/styles/specific/z_responsive.scss index 7234d8dad..7a8626e1a 100644 --- a/app/javascript/src/styles/specific/z_responsive.scss +++ b/app/javascript/src/styles/specific/z_responsive.scss @@ -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; } diff --git a/app/models/comment.rb b/app/models/comment.rb index 5d417d601..6199a175b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index e8a594323..adbe89dac 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -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 diff --git a/app/views/posts/partials/index/_preview.html.erb b/app/views/posts/partials/index/_preview.html.erb index 9dda428ff..1f66a072c 100644 --- a/app/views/posts/partials/index/_preview.html.erb +++ b/app/views/posts/partials/index/_preview.html.erb @@ -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 -%> +
+ <%= post_stats_section(post) %> +
+ <% end -%> <% if pool -%>

<%= link_to pool.pretty_name.truncate(80), pool %> diff --git a/db/migrate/20190804010156_add_post_comment_counter.rb b/db/migrate/20190804010156_add_post_comment_counter.rb new file mode 100644 index 000000000..bfe58fea0 --- /dev/null +++ b/db/migrate/20190804010156_add_post_comment_counter.rb @@ -0,0 +1,5 @@ +class AddPostCommentCounter < ActiveRecord::Migration[5.2] + def change + add_column :posts, :comment_count, :integer, null: false, default: 0 + end +end diff --git a/db/structure.sql b/db/structure.sql index a7dd84f52..ef94257ee 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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');