Add context for search screens
This commit is contained in:
@@ -11,23 +11,21 @@ class Command::Parser::Context
|
||||
def cards
|
||||
if viewing_card_contents?
|
||||
user.accessible_cards.where id: params[:id]
|
||||
elsif viewing_list_of_cards?
|
||||
elsif viewing_cards_index?
|
||||
filter.cards.published
|
||||
elsif viewing_search_results?
|
||||
user.accessible_cards.where(id: user.search(params[:q]).select(:card_id))
|
||||
else
|
||||
Card.none
|
||||
end
|
||||
end
|
||||
|
||||
def filter
|
||||
user.filters.from_params(params.permit(*Filter::Params::PERMITTED_PARAMS).reverse_merge(**FilterScoped::DEFAULT_PARAMS))
|
||||
end
|
||||
|
||||
def viewing_card_contents?
|
||||
controller == "cards" && action == "show"
|
||||
viewing_card_perma?
|
||||
end
|
||||
|
||||
def viewing_list_of_cards?
|
||||
controller == "cards" && action == "index"
|
||||
viewing_cards_index? || viewing_search_results?
|
||||
end
|
||||
|
||||
private
|
||||
@@ -36,6 +34,22 @@ class Command::Parser::Context
|
||||
MAX_CARDS = 20
|
||||
MAX_CLOSED_CARDS = 10
|
||||
|
||||
def filter
|
||||
user.filters.from_params(params.permit(*Filter::Params::PERMITTED_PARAMS).reverse_merge(**FilterScoped::DEFAULT_PARAMS))
|
||||
end
|
||||
|
||||
def viewing_card_perma?
|
||||
controller == "cards" && action == "show"
|
||||
end
|
||||
|
||||
def viewing_cards_index?
|
||||
controller == "cards" && action == "index"
|
||||
end
|
||||
|
||||
def viewing_search_results?
|
||||
controller == "searches" && action == "show"
|
||||
end
|
||||
|
||||
def extract_url_components
|
||||
uri = URI.parse(url || "")
|
||||
route = Rails.application.routes.recognize_path(uri.path)
|
||||
|
||||
Reference in New Issue
Block a user