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 @@ +
Favorited by | +Other Favorites | +
---|---|
+ <%= link_to_user user %> + | ++ <%= link_to(user.favorite_count, favorites_path(:user_id => user.id)) %> + | +