The previous commit changed it so that `/pools?search[name_matches]` does a full-text search. So for example, `search[name_matches]=smiling` will now match pool names containing any of the words "smiling", "smile", "smiles", or "smiled". This commit adds a `/pools?search[name_contains]` param that does what `name_matches` did before, and switches to it in search forms. So for example, `search[name_contains]=smiling` will only match pool names containing the exact substring "smiling". This change is so that `<field>_matches` works consistently across the site, and so that it's possible to search pool names by either an exact substring match, or by a looser natural language match. This is a minor breaking API change. API users can replace `/pools?search[name_matches]` with `/pools?search[name_contains]` to get the same behavior as before. The same applies to /favorite_groups.
94 lines
2.4 KiB
Ruby
94 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PoolsController < ApplicationController
|
|
respond_to :html, :xml, :json, :js
|
|
|
|
def new
|
|
@pool = authorize Pool.new(permitted_attributes(Pool))
|
|
respond_with(@pool)
|
|
end
|
|
|
|
def edit
|
|
@pool = authorize Pool.find(params[:id])
|
|
respond_with(@pool)
|
|
end
|
|
|
|
def index
|
|
if request.format.html?
|
|
@pools = authorize Pool.paginated_search(params, count_pages: true, defaults: { is_deleted: false })
|
|
else
|
|
@pools = authorize Pool.paginated_search(params, count_pages: true)
|
|
end
|
|
|
|
respond_with(@pools)
|
|
end
|
|
|
|
def gallery
|
|
limit = params[:limit].presence || CurrentUser.user.per_page
|
|
search = search_params.presence || ActionController::Parameters.new(category: "series")
|
|
|
|
@pools = authorize Pool.search(search).paginate(params[:page], limit: limit, search_count: params[:search])
|
|
respond_with(@pools)
|
|
end
|
|
|
|
def show
|
|
limit = params[:limit].presence || CurrentUser.user.per_page
|
|
|
|
@pool = authorize Pool.find(params[:id])
|
|
@posts = @pool.posts.paginate(params[:page], limit: limit, count: @pool.post_count)
|
|
respond_with(@pool)
|
|
end
|
|
|
|
def create
|
|
@pool = authorize Pool.new(permitted_attributes(Pool))
|
|
@pool.save
|
|
flash[:notice] = @pool.valid? ? "Pool created" : @pool.errors.full_messages.join("; ")
|
|
respond_with(@pool)
|
|
end
|
|
|
|
def update
|
|
@pool = authorize Pool.find(params[:id])
|
|
@pool.update(permitted_attributes(@pool))
|
|
unless @pool.errors.any?
|
|
flash[:notice] = "Pool updated"
|
|
end
|
|
respond_with(@pool)
|
|
end
|
|
|
|
def destroy
|
|
@pool = authorize Pool.find(params[:id])
|
|
@pool.update(is_deleted: true)
|
|
@pool.create_mod_action_for_delete
|
|
flash[:notice] = "Pool deleted"
|
|
respond_with(@pool)
|
|
end
|
|
|
|
def undelete
|
|
@pool = authorize Pool.find(params[:id])
|
|
@pool.update(is_deleted: false)
|
|
@pool.create_mod_action_for_undelete
|
|
flash[:notice] = "Pool undeleted"
|
|
respond_with(@pool)
|
|
end
|
|
|
|
def revert
|
|
@pool = authorize Pool.find(params[:id])
|
|
@version = @pool.versions.find(params[:version_id])
|
|
@pool.revert_to!(@version)
|
|
flash[:notice] = "Pool reverted"
|
|
respond_with(@pool) do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def item_matches_params(pool)
|
|
if params[:search][:name_contains]
|
|
Pool.normalize_name_for_search(pool.name) == Pool.normalize_name_for_search(params[:search][:name_contains])
|
|
else
|
|
true
|
|
end
|
|
end
|
|
end
|