Merge pull request #250 from Earlopain/post-favorites

Add list of post favorites to seperate route
This commit is contained in:
Zwagoth 2021-04-03 03:11:33 -04:00 committed by GitHub
commit c40498ce41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 53 additions and 24 deletions

View File

@ -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

View File

@ -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"

View File

@ -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 = ""

View File

@ -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"));

View File

@ -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;
}

View File

@ -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

View File

@ -0,0 +1,33 @@
<div id="c-post-favorites">
<div id="a-index">
<h1>Post Favorites</h1>
<%= PostPresenter.preview(@post) %>
<table width="100%" class="striped">
<thead>
<tr>
<th>Favorited by</th>
<th>Other Favorites</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td>
<%= link_to_user user %>
</td>
<td>
<%= link_to(user.favorite_count, favorites_path(:user_id => user.id)) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= numbered_paginator(@users) %>
</div>
</div>
<%= render "posts/partials/common/secondary_links" %>
<% content_for(:page_title) do %>
Post Favorites - #<%= params[:post_id] %>
<% end %>

View File

@ -41,9 +41,5 @@
<% end %>
</li>
<li>Favorites: <span id="favcount-for-post-<%= post.id %>"><%= post.fav_count %></span>
<% 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;" %>
<div id="favlist" style="display: none;"><%= post_favlist(post) %></div>
<% end %></li>
<%= link_to "Show", post_favorites_path(post.id), style: ("display: none;" if post.fav_count == 0) %>
</ul>

View File

@ -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

View File

@ -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