Fix #4930: "Show scores" setting should be preserved
Make "show scores" setting persistent. The setting is stored in a `post_preview_show_votes` cookie. This means it's remembered on a per-device basis, but not on a per-account basis. This is so users without an account can use the setting, and so you can use different settings on desktop and mobile. The `view=score` URL param has been replaced by `show_votes=true`. The `show_votes` URL param overrides the `post_preview_show_votes` cookie.
This commit is contained in:
@@ -9,12 +9,13 @@ class PostsController < ApplicationController
|
|||||||
format.html { redirect_to(@post) }
|
format.html { redirect_to(@post) }
|
||||||
end
|
end
|
||||||
elsif params[:random].to_s.truthy?
|
elsif params[:random].to_s.truthy?
|
||||||
post_set = PostSets::Post.new(params[:tags], params[:page], params[:limit], format: request.format.symbol, view: params[:view])
|
post_set = PostSets::Post.new(params[:tags], params[:page], params[:limit], format: request.format.symbol)
|
||||||
query = "#{post_set.normalized_query.to_s} random:#{post_set.per_page}".strip
|
query = "#{post_set.normalized_query.to_s} random:#{post_set.per_page}".strip
|
||||||
redirect_to posts_path(tags: query, page: params[:page], limit: params[:limit], format: request.format.symbol, view: params[:view], size: params[:size])
|
redirect_to posts_path(tags: query, page: params[:page], limit: params[:limit], format: request.format.symbol)
|
||||||
else
|
else
|
||||||
tag_query = params[:tags] || params.dig(:post, :tags)
|
tag_query = params[:tags] || params.dig(:post, :tags)
|
||||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], format: request.format.symbol, view: params[:view])
|
@show_votes = (params[:show_votes].presence || cookies[:post_preview_show_votes].presence || "false").truthy?
|
||||||
|
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], format: request.format.symbol, show_votes: @show_votes)
|
||||||
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
|
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
|
||||||
@posts = authorize @post_set.posts, policy_class: PostPolicy
|
@posts = authorize @post_set.posts, policy_class: PostPolicy
|
||||||
@post_set.log!
|
@post_set.log!
|
||||||
@@ -56,6 +57,7 @@ class PostsController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
@post = authorize Post.find(params[:id])
|
@post = authorize Post.find(params[:id])
|
||||||
@post.update(permitted_attributes(@post))
|
@post.update(permitted_attributes(@post))
|
||||||
|
@show_votes = (params[:show_votes].presence || cookies[:post_preview_show_votes].presence || "false").truthy?
|
||||||
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
|
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
|
||||||
respond_with_post_after_update(@post)
|
respond_with_post_after_update(@post)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Post.initialize_all = function() {
|
|||||||
this.initialize_excerpt();
|
this.initialize_excerpt();
|
||||||
this.initialize_gestures();
|
this.initialize_gestures();
|
||||||
this.initialize_post_preview_size_menu();
|
this.initialize_post_preview_size_menu();
|
||||||
|
this.initialize_post_preview_options_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($("#c-posts").length && $("#a-show").length) {
|
if ($("#c-posts").length && $("#a-show").length) {
|
||||||
@@ -255,6 +256,20 @@ Post.initialize_post_preview_size_menu = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Post.initialize_post_preview_options_menu = function() {
|
||||||
|
$(document).on("click.danbooru", "a.post-preview-show-votes", (e) => {
|
||||||
|
Cookie.put("post_preview_show_votes", "true");
|
||||||
|
location.reload();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on("click.danbooru", "a.post-preview-hide-votes", (e) => {
|
||||||
|
Cookie.put("post_preview_show_votes", "false");
|
||||||
|
location.reload();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Post.view_original = function(e = null) {
|
Post.view_original = function(e = null) {
|
||||||
if (Utility.test_max_width(660)) {
|
if (Utility.test_max_width(660)) {
|
||||||
// Do the default behavior (navigate to image)
|
// Do the default behavior (navigate to image)
|
||||||
@@ -424,10 +439,10 @@ Post.update = async function(post_id, mode, params) {
|
|||||||
Post.show_pending_update_notice()
|
Post.show_pending_update_notice()
|
||||||
|
|
||||||
let urlParams = new URLSearchParams(window.location.search);
|
let urlParams = new URLSearchParams(window.location.search);
|
||||||
let view = urlParams.get("view");
|
let show_votes = urlParams.get("show_votes");
|
||||||
let size = urlParams.get("size");
|
let size = urlParams.get("size");
|
||||||
|
|
||||||
await $.ajax({ type: "PUT", url: `/posts/${post_id}.js`, data: { mode, view, size, ...params }});
|
await $.ajax({ type: "PUT", url: `/posts/${post_id}.js`, data: { mode, show_votes, size, ...params }});
|
||||||
|
|
||||||
Post.pending_update_count -= 1;
|
Post.pending_update_count -= 1;
|
||||||
Post.show_pending_update_notice();
|
Post.show_pending_update_notice();
|
||||||
|
|||||||
@@ -7,17 +7,18 @@ module PostSets
|
|||||||
MAX_PER_PAGE = 200
|
MAX_PER_PAGE = 200
|
||||||
MAX_SIDEBAR_TAGS = 25
|
MAX_SIDEBAR_TAGS = 25
|
||||||
|
|
||||||
attr_reader :page, :format, :tag_string, :query, :normalized_query, :view
|
attr_reader :page, :format, :tag_string, :query, :normalized_query, :show_votes
|
||||||
delegate :post_count, to: :normalized_query
|
delegate :post_count, to: :normalized_query
|
||||||
|
alias_method :show_votes?, :show_votes
|
||||||
|
|
||||||
def initialize(tags, page = 1, per_page = nil, user: CurrentUser.user, format: "html", view: "simple")
|
def initialize(tags, page = 1, per_page = nil, user: CurrentUser.user, format: "html", show_votes: false)
|
||||||
@query = PostQueryBuilder.new(tags, user, tag_limit: user.tag_query_limit, safe_mode: CurrentUser.safe_mode?, hide_deleted_posts: user.hide_deleted_posts?)
|
@query = PostQueryBuilder.new(tags, user, tag_limit: user.tag_query_limit, safe_mode: CurrentUser.safe_mode?, hide_deleted_posts: user.hide_deleted_posts?)
|
||||||
@normalized_query = query.normalized_query
|
@normalized_query = query.normalized_query
|
||||||
@tag_string = tags
|
@tag_string = tags
|
||||||
@page = page
|
@page = page
|
||||||
@per_page = per_page
|
@per_page = per_page
|
||||||
@format = format.to_s
|
@format = format.to_s
|
||||||
@view = view.presence || "simple"
|
@show_votes = show_votes
|
||||||
end
|
end
|
||||||
|
|
||||||
def humanized_tag_string
|
def humanized_tag_string
|
||||||
@@ -126,10 +127,6 @@ module PostSets
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_votes?
|
|
||||||
view == "score"
|
|
||||||
end
|
|
||||||
|
|
||||||
def includes
|
def includes
|
||||||
if show_votes?
|
if show_votes?
|
||||||
[:media_asset, :vote_by_current_user]
|
[:media_asset, :vote_by_current_user]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<section id="tag-box">
|
<section id="tag-box">
|
||||||
<h2>Tags</h2>
|
<h2>Tags</h2>
|
||||||
<%= render_search_tag_list(@post_set.related_tags, current_query: params[:tags], show_extra_links: policy(Post).show_extra_links?, search_params: { view: params[:view], size: params[:size] }) %>
|
<%= render_search_tag_list(@post_set.related_tags, current_query: params[:tags], show_extra_links: policy(Post).show_extra_links?, search_params: { show_votes: params[:show_votes], size: params[:size] }) %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="options-box">
|
<section id="options-box">
|
||||||
@@ -75,69 +75,69 @@
|
|||||||
<a class="mobile-only" href="#search-box">Search »</a>
|
<a class="mobile-only" href="#search-box">Search »</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<%= render PopupMenuComponent.new(classes: "hidden post-preview-size-menu") do |menu| %>
|
<%= render PopupMenuComponent.new(classes: "post-preview-size-menu") do |menu| %>
|
||||||
<% menu.button do %>
|
<% menu.button do %>
|
||||||
<span class="text-sm">Size <%= caret_down_icon %></span>
|
<span class="text-sm">Size <%= caret_down_icon %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% menu.item do %>
|
<% menu.item do %>
|
||||||
<% if @preview_size == "150" %>
|
<% if @preview_size == "150" %>
|
||||||
<%= link_to "Small", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "150"), class: "font-bold", rel: "nofollow" %>
|
<%= link_to "Small", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "150"), class: "font-bold", rel: "nofollow" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Small", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "150"), rel: "nofollow" %>
|
<%= link_to "Small", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "150"), rel: "nofollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% menu.item do %>
|
<% menu.item do %>
|
||||||
<% if @preview_size == "180" %>
|
<% if @preview_size == "180" %>
|
||||||
<%= link_to "Medium", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "180"), class: "font-bold", rel: "nofollow" %>
|
<%= link_to "Medium", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "180"), class: "font-bold", rel: "nofollow" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Medium", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "180"), rel: "nofollow" %>
|
<%= link_to "Medium", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "180"), rel: "nofollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% menu.item do %>
|
<% menu.item do %>
|
||||||
<% if @preview_size == "225" %>
|
<% if @preview_size == "225" %>
|
||||||
<%= link_to "Large", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "225"), class: "font-bold", rel: "nofollow" %>
|
<%= link_to "Large", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "225"), class: "font-bold", rel: "nofollow" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Large", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "225"), rel: "nofollow" %>
|
<%= link_to "Large", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "225"), rel: "nofollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%# Mobile only %>
|
<%# Mobile only %>
|
||||||
<% menu.item do %>
|
<% menu.item do %>
|
||||||
<% if @preview_size == "360" %>
|
<% if @preview_size == "360" %>
|
||||||
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "360"), class: "mobile-only font-bold", rel: "nofollow" %>
|
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "360"), class: "mobile-only font-bold", rel: "nofollow" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "360"), class: "mobile-only", rel: "nofollow" %>
|
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "360"), class: "mobile-only", rel: "nofollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%# Desktop only %>
|
<%# Desktop only %>
|
||||||
<% menu.item do %>
|
<% menu.item do %>
|
||||||
<% if @preview_size == "270" %>
|
<% if @preview_size == "270" %>
|
||||||
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "270"), class: "desktop-only font-bold", rel: "nofollow" %>
|
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "270"), class: "desktop-only font-bold", rel: "nofollow" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "270"), class: "desktop-only", rel: "nofollow" %>
|
<%= link_to "Huge", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "270"), class: "desktop-only", rel: "nofollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%# Desktop only %>
|
<%# Desktop only %>
|
||||||
<% menu.item do %>
|
<% menu.item do %>
|
||||||
<% if @preview_size == "360" %>
|
<% if @preview_size == "360" %>
|
||||||
<%= link_to "Gigantic", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "360"), class: "desktop-only font-bold", rel: "nofollow" %>
|
<%= link_to "Gigantic", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "360"), class: "desktop-only font-bold", rel: "nofollow" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Gigantic", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: params[:view], size: "360"), class: "desktop-only", rel: "nofollow" %>
|
<%= link_to "Gigantic", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: params[:show_votes], size: "360"), class: "desktop-only", rel: "nofollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render PopupMenuComponent.new do |menu| %>
|
<%= render PopupMenuComponent.new(classes: "post-preview-options-menu") do |menu| %>
|
||||||
<% menu.item do %>
|
<% menu.item do %>
|
||||||
<% if params[:view] == "score" %>
|
<% if @show_votes %>
|
||||||
<%= link_to "Hide scores", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: nil, size: params[:size]), rel: "nofollow" %>
|
<%= link_to "Hide scores", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: nil, size: params[:size]), class: "post-preview-hide-votes", rel: "nofollow" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Show scores", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], view: "score", size: params[:size]), rel: "nofollow" %>
|
<%= link_to "Show scores", posts_path(tags: params[:tags], page: params[:page], limit: params[:limit], show_votes: true, size: params[:size]), class: "post-preview-show-votes", rel: "nofollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<% if params[:random] %>
|
<% if params[:random] %>
|
||||||
<%= hidden_field_tag :random, params[:random] %>
|
<%= hidden_field_tag :random, params[:random] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if params[:view] %>
|
<% if params[:show_votes] %>
|
||||||
<%= hidden_field_tag :view, params[:view] %>
|
<%= hidden_field_tag :show_votes, params[:show_votes] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if params[:size] %>
|
<% if params[:size] %>
|
||||||
<%= hidden_field_tag :size, params[:size] %>
|
<%= hidden_field_tag :size, params[:size] %>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<% if @post.valid? %>
|
<% if @post.valid? %>
|
||||||
var $post = $("#post_<%= @post.id %>");
|
var $post = $("#post_<%= @post.id %>");
|
||||||
var $new_post = $("<%= j post_preview(@post, fit: :compact, show_deleted: true, show_votes: params[:view] == "score", size: @preview_size) %>");
|
var $new_post = $("<%= j post_preview(@post, fit: :compact, show_deleted: true, show_votes: @show_votes, size: @preview_size) %>");
|
||||||
Danbooru.Blacklist.apply_post($new_post.get(0));
|
Danbooru.Blacklist.apply_post($new_post.get(0));
|
||||||
$("#post_<%= @post.id %>").replaceWith($new_post);
|
$("#post_<%= @post.id %>").replaceWith($new_post);
|
||||||
<% if params[:mode] == "quick-edit" %>
|
<% if params[:mode] == "quick-edit" %>
|
||||||
|
|||||||
Reference in New Issue
Block a user