mirror of
https://github.com/discourse/discourse.git
synced 2025-03-22 03:05:43 +08:00
DEV: Passing the list options to page_params is unnecessary
They are always merged with the result before being used.
This commit is contained in:
parent
c5bcad10a6
commit
2e979a4681
app/controllers
@ -316,28 +316,25 @@ class ListController < ApplicationController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def next_page_params(opts = nil)
|
def next_page_params
|
||||||
page_params(opts).merge(page: params[:page].to_i + 1)
|
page_params.merge(page: params[:page].to_i + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prev_page_params(opts = nil)
|
def prev_page_params
|
||||||
pg = params[:page].to_i
|
pg = params[:page].to_i
|
||||||
if pg > 1
|
if pg > 1
|
||||||
page_params(opts).merge(page: pg - 1)
|
page_params.merge(page: pg - 1)
|
||||||
else
|
else
|
||||||
page_params(opts).merge(page: nil)
|
page_params.merge(page: nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def page_params(opts = nil)
|
def page_params
|
||||||
opts ||= {}
|
|
||||||
route_params = { format: 'json' }
|
route_params = { format: 'json' }
|
||||||
route_params[:category] = @category.slug_for_url if @category
|
route_params[:category] = @category.slug_for_url if @category
|
||||||
route_params[:parent_category] = @category.parent_category.slug_for_url if @category && @category.parent_category
|
route_params[:parent_category] = @category.parent_category.slug_for_url if @category && @category.parent_category
|
||||||
route_params[:order] = opts[:order] if opts[:order].present?
|
|
||||||
route_params[:ascending] = opts[:ascending] if opts[:ascending].present?
|
|
||||||
route_params[:username] = UrlHelper.escape_uri(params[:username]) if params[:username].present?
|
route_params[:username] = UrlHelper.escape_uri(params[:username]) if params[:username].present?
|
||||||
route_params
|
route_params
|
||||||
end
|
end
|
||||||
@ -392,9 +389,9 @@ class ListController < ApplicationController
|
|||||||
def construct_url_with(action, opts, url_prefix = nil)
|
def construct_url_with(action, opts, url_prefix = nil)
|
||||||
method = url_prefix.blank? ? "#{action_name}_path" : "#{url_prefix}_#{action_name}_path"
|
method = url_prefix.blank? ? "#{action_name}_path" : "#{url_prefix}_#{action_name}_path"
|
||||||
url = if action == :prev
|
url = if action == :prev
|
||||||
public_send(method, opts.merge(prev_page_params(opts)))
|
public_send(method, opts.merge(prev_page_params))
|
||||||
else # :next
|
else # :next
|
||||||
public_send(method, opts.merge(next_page_params(opts)))
|
public_send(method, opts.merge(next_page_params))
|
||||||
end
|
end
|
||||||
url.sub('.json?', '?')
|
url.sub('.json?', '?')
|
||||||
end
|
end
|
||||||
|
@ -305,26 +305,23 @@ class TagsController < ::ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
# TODO: this is duplication of ListController
|
# TODO: this is duplication of ListController
|
||||||
def page_params(opts = nil)
|
def page_params
|
||||||
opts ||= {}
|
|
||||||
route_params = { format: 'json' }
|
route_params = { format: 'json' }
|
||||||
route_params[:category] = @filter_on_category.slug_for_url if @filter_on_category
|
route_params[:category] = @filter_on_category.slug_for_url if @filter_on_category
|
||||||
route_params[:parent_category] = @filter_on_category.parent_category.slug_for_url if @filter_on_category && @filter_on_category.parent_category
|
route_params[:parent_category] = @filter_on_category.parent_category.slug_for_url if @filter_on_category && @filter_on_category.parent_category
|
||||||
route_params[:order] = opts[:order] if opts[:order].present?
|
|
||||||
route_params[:ascending] = opts[:ascending] if opts[:ascending].present?
|
|
||||||
route_params
|
route_params
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_page_params(opts = nil)
|
def next_page_params
|
||||||
page_params(opts).merge(page: params[:page].to_i + 1)
|
page_params.merge(page: params[:page].to_i + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prev_page_params(opts = nil)
|
def prev_page_params
|
||||||
pg = params[:page].to_i
|
pg = params[:page].to_i
|
||||||
if pg > 1
|
if pg > 1
|
||||||
page_params(opts).merge(page: pg - 1)
|
page_params.merge(page: pg - 1)
|
||||||
else
|
else
|
||||||
page_params(opts).merge(page: nil)
|
page_params.merge(page: nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -343,9 +340,9 @@ class TagsController < ::ApplicationController
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
url = if action == :prev
|
url = if action == :prev
|
||||||
public_send(method, opts.merge(prev_page_params(opts)))
|
public_send(method, opts.merge(prev_page_params))
|
||||||
else # :next
|
else # :next
|
||||||
public_send(method, opts.merge(next_page_params(opts)))
|
public_send(method, opts.merge(next_page_params))
|
||||||
end
|
end
|
||||||
rescue ActionController::UrlGenerationError
|
rescue ActionController::UrlGenerationError
|
||||||
raise Discourse::NotFound
|
raise Discourse::NotFound
|
||||||
|
Loading…
x
Reference in New Issue
Block a user