diff --git a/app/controllers/post_favorites_controller.rb b/app/controllers/post_favorites_controller.rb new file mode 100644 index 000000000..de88e4164 --- /dev/null +++ b/app/controllers/post_favorites_controller.rb @@ -0,0 +1,15 @@ +class PostFavoritesController < ApplicationController + before_action :member_only + respond_to :html + + def index + @post = Post.find(params[:post_id]) + query = User.includes(:user_status).joins(:favorites) + unless CurrentUser.is_admin? + query = query.where("bit_prefs & :value != :value", {value: 2**User::BOOLEAN_ATTRIBUTES.find_index("enable_privacy_mode")}).or(query.where(favorites: {user_id: CurrentUser.id})) + end + query = query.where(favorites: {post_id: @post.id}) + query = query.order("users.name asc") + @users = query.paginate(params[:page], limit: 75) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9598ff433..af53ecec3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -288,7 +288,7 @@ protected when "notes", "note_versions" /^\/notes/ - when "posts", "uploads", "post_versions", "explore/posts", "moderator/post/dashboards", "favorites" + when "posts", "uploads", "post_versions", "explore/posts", "moderator/post/dashboards", "favorites", "post_favorites" /^\/posts/ when "artists", "artist_versions" diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 243e18c8d..6c5f2a861 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -44,10 +44,6 @@ module PostsHelper end end - def post_favlist(post) - post.favorited_users.reverse_each.map {|user| link_to_user(user)}.join(", ").html_safe - end - def has_parent_message(post, parent_post_set) html = "" diff --git a/app/javascript/src/javascripts/posts.js.erb b/app/javascript/src/javascripts/posts.js.erb index 756367e58..bd47beedf 100644 --- a/app/javascript/src/javascripts/posts.js.erb +++ b/app/javascript/src/javascripts/posts.js.erb @@ -24,7 +24,6 @@ Post.initialize_all = function() { if ($("#c-posts").length && $("#a-show").length) { this.initialize_links(); this.initialize_post_relationship_previews(); - this.initialize_favlist(); this.initialize_post_sections(); this.initialize_resize(); this.initialize_similar(); @@ -443,13 +442,6 @@ Post.toggle_relationship_preview = function(preview, preview_link) { } } -Post.initialize_favlist = function() { - $("#show-favlist-link, #hide-favlist-link").on("click.danbooru", function(e) { - $("#favlist, #show-favlist-link, #hide-favlist-link").toggle(); - e.preventDefault(); - }); -} - Post.currentPost = function() { if(!this._currentPost) this._currentPost = this.fromDOM($("#image-container")); diff --git a/app/javascript/src/styles/specific/posts.scss b/app/javascript/src/styles/specific/posts.scss index 276e2c3fe..b3db90a59 100644 --- a/app/javascript/src/styles/specific/posts.scss +++ b/app/javascript/src/styles/specific/posts.scss @@ -456,11 +456,6 @@ div#c-posts { } } - #favlist { - margin-left: 1em; - word-wrap: break-word; - } - .search-seq-nav + .pool-nav, .search-seq-nav + .set-nav, .pool-nav + .set-nav { margin-top: 0.5em; } diff --git a/app/models/user.rb b/app/models/user.rb index 427404bf7..6e51f8d41 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -122,7 +122,7 @@ class User < ApplicationRecord has_many :forum_posts, -> {order("forum_posts.created_at, forum_posts.id")}, :foreign_key => "creator_id" has_many :user_name_change_requests, -> {visible.order("user_name_change_requests.id desc")} has_many :post_sets, -> {order(name: :asc)}, foreign_key: :creator_id - has_many :favorites, ->(rec) {where("user_id = ?", rec.id).order("id desc")} + has_many :favorites, -> {order(id: :desc)} belongs_to :avatar, class_name: 'Post', optional: true accepts_nested_attributes_for :dmail_filter diff --git a/app/views/post_favorites/index.html.erb b/app/views/post_favorites/index.html.erb new file mode 100644 index 000000000..22fc9dfe6 --- /dev/null +++ b/app/views/post_favorites/index.html.erb @@ -0,0 +1,33 @@ +
+
+

Post Favorites

+ <%= PostPresenter.preview(@post) %> + + + + + + + + + <% @users.each do |user| %> + + + + + <% end %> + +
Favorited byOther Favorites
+ <%= link_to_user user %> + + <%= link_to(user.favorite_count, favorites_path(:user_id => user.id)) %> +
+ <%= numbered_paginator(@users) %> +
+
+ +<%= render "posts/partials/common/secondary_links" %> + +<% content_for(:page_title) do %> + Post Favorites - #<%= params[:post_id] %> +<% end %> diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index 79ed420a7..a597508ce 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -41,9 +41,5 @@ <% end %>
  • Favorites: <%= post.fav_count %> - <% if CurrentUser.is_privileged? %> - <%= link_to "Show »", "#", id: "show-favlist-link", style: ("display: none;" if post.fav_count == 0) %> - <%= link_to "« Hide", "#", id: "hide-favlist-link", style: "display: none;" %> - - <% end %>
  • + <%= link_to "Show", post_favorites_path(post.id), style: ("display: none;" if post.fav_count == 0) %> diff --git a/config/routes.rb b/config/routes.rb index aac7f6811..d7bd97d3b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -253,6 +253,7 @@ Rails.application.routes.draw do resources :replacements, :only => [:index, :new, :create], :controller => "post_replacements" resource :votes, :controller => "post_votes", :only => [:create, :destroy] resource :flag, controller: 'post_flags', only: [:destroy] + resources :favorites, :controller => "post_favorites", :only => [:index] collection do get :random end diff --git a/public/robots.txt b/public/robots.txt index 41f4a57d0..0b7ece9e7 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -56,6 +56,7 @@ Disallow: /posts*?*pool_id* Disallow: /posts*?*post_set_id* Disallow: /posts.json Disallow: /posts.xml +Disallow: /posts/*/favorites Disallow: /reports Disallow: /session Disallow: /sources