forked from e621ng/e621ng
Merge pull request #250 from Earlopain/post-favorites
Add list of post favorites to seperate route
This commit is contained in:
commit
c40498ce41
15
app/controllers/post_favorites_controller.rb
Normal file
15
app/controllers/post_favorites_controller.rb
Normal 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
|
@ -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"
|
||||
|
@ -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 = ""
|
||||
|
||||
|
@ -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"));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
33
app/views/post_favorites/index.html.erb
Normal file
33
app/views/post_favorites/index.html.erb
Normal 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 %>
|
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user