Merge pull request #3957 from evazion/fix-related-tags

Related tags: build html server-side, eliminate cookies
This commit is contained in:
Albert Yi
2018-10-24 17:34:14 -07:00
committed by GitHub
24 changed files with 282 additions and 426 deletions

View File

@@ -1,5 +1,5 @@
class ArtistUrlsController < ApplicationController
respond_to :json, :xml, :html
respond_to :js, :json, :xml, :html
before_action :member_only, except: [:index]
def index

View File

@@ -46,7 +46,6 @@ class PostsController < ApplicationController
@post = Post.find(params[:id])
@post.update(post_params) if @post.visible?
save_recent_tags
respond_with_post_after_update(@post)
end
@@ -96,15 +95,6 @@ private
params[:tags] || (params[:post] && params[:post][:tags])
end
def save_recent_tags
if @post
tags = Tag.scan_tags(@post.tag_string)
tags = (TagAlias.to_aliased(tags) + Tag.scan_tags(cookies[:recent_tags])).uniq.slice(0, 30)
cookies[:recent_tags] = tags.join(" ")
cookies[:recent_tags_with_categories] = Tag.categories_for(tags).to_a.flatten.join(" ")
end
end
def respond_with_post_after_update(post)
respond_with(post) do |format|
format.html do

View File

@@ -1,10 +1,9 @@
class RelatedTagsController < ApplicationController
respond_to :json
respond_to :html, :only=>[:show]
respond_to :json, :xml, :js, :html, except: [:update]
before_action :require_reportbooru_key, only: [:update]
def show
@query = RelatedTagQuery.new(params[:query].to_s.downcase, params[:category])
@query = RelatedTagQuery.new(query: params[:query], category: params[:category], user: CurrentUser.user)
respond_with(@query) do |format|
format.json do
render :json => @query.to_json

View File

@@ -58,21 +58,11 @@ class UploadsController < ApplicationController
flash[:notice] = @service.warnings.join(".\n \n")
end
save_recent_tags
respond_with(@upload)
end
private
def save_recent_tags
if @upload
tags = Tag.scan_tags(@upload.tag_string)
tags = (TagAlias.to_aliased(tags) + Tag.scan_tags(cookies[:recent_tags])).compact.uniq.slice(0, 30)
cookies[:recent_tags] = tags.join(" ")
cookies[:recent_tags_with_categories] = Tag.categories_for(tags).to_a.flatten.join(" ")
end
end
def upload_params
permitted_params = %i[
file source tag_string rating status parent_id artist_commentary_title

View File

@@ -66,8 +66,6 @@ class UsersController < ApplicationController
@user = User.find(params[:id])
check_privilege(@user)
@user.update(user_params(:update))
cookies.delete(:favorite_tags)
cookies.delete(:favorite_tags_with_categories)
if @user.errors.any?
flash[:notice] = @user.errors.full_messages.join("; ")
else