Support selecting multiple cards by using a list of numbers (separated by comma, or space)
https://3.basecamp.com/2914079/buckets/37331921/todos/8620236700#__recording_8620273944
This commit is contained in:
@@ -11,14 +11,14 @@ class Command::Parser
|
||||
command_name, *command_arguments = string.strip.split(" ")
|
||||
|
||||
case command_name
|
||||
when "/assign", "/assignto"
|
||||
Command::Assign.new(assignee_ids: assignees_from(command_arguments).collect(&:id), card_ids: cards.ids)
|
||||
when "/close"
|
||||
Command::Close.new(card_ids: cards.ids, reason: command_arguments.join(" "))
|
||||
when /^@/
|
||||
Command::GoToUser.new(user_id: assignee_from(command_name)&.id)
|
||||
else
|
||||
search(string)
|
||||
when "/assign", "/assignto"
|
||||
Command::Assign.new(assignee_ids: assignees_from(command_arguments).collect(&:id), card_ids: cards.ids)
|
||||
when "/close"
|
||||
Command::Close.new(card_ids: cards.ids, reason: command_arguments.join(" "))
|
||||
when /^@/
|
||||
Command::GoToUser.new(user_id: assignee_from(command_name)&.id)
|
||||
else
|
||||
search(string)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,10 +37,21 @@ class Command::Parser
|
||||
end
|
||||
|
||||
def search(string)
|
||||
if card = user.accessible_cards.find_by_id(string)
|
||||
if cards = multiple_cards_from(string)
|
||||
Command::FilterCards.new(card_ids: cards.ids, params: filter.as_params)
|
||||
elsif card = user.accessible_cards.find_by_id(string)
|
||||
Command::GoToCard.new(card_id: card.id)
|
||||
else
|
||||
Command::Search.new(query: string, params: filter.as_params)
|
||||
end
|
||||
end
|
||||
|
||||
def multiple_cards_from(string)
|
||||
if tokens = string.split(/[\s,]+/).filter { it =~ /\A\d+\z/ }.presence
|
||||
if tokens.many?
|
||||
cards = user.accessible_cards.where(id: tokens)
|
||||
cards.any? ? cards : nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user