Support user prompts in Fizzy do, move parsing logic to context
This commit is contained in:
@@ -28,6 +28,29 @@ class Command::Parser::Context
|
||||
viewing_cards_index? || viewing_search_results?
|
||||
end
|
||||
|
||||
def find_user(string)
|
||||
if string.starts_with?("gid://")
|
||||
User.find_by_id(GlobalID::Locator.locate(string).id)
|
||||
else
|
||||
string_without_at = string.delete_prefix("@")
|
||||
User.all.find { |user| user.mentionable_handles.include?(string_without_at.downcase) }
|
||||
end
|
||||
end
|
||||
|
||||
def find_workflow_stage(string)
|
||||
candidate_stages.find do |stage|
|
||||
stage.name.downcase.include?(combined_arguments.downcase)
|
||||
end
|
||||
end
|
||||
|
||||
def find_tag(string)
|
||||
Tag.find_by_title(string)
|
||||
end
|
||||
|
||||
def find_collection(string)
|
||||
Collection.where("lower(name) like ?", "%#{name.downcase}%").first
|
||||
end
|
||||
|
||||
private
|
||||
attr_reader :controller, :action, :params
|
||||
|
||||
@@ -57,4 +80,8 @@ class Command::Parser::Context
|
||||
@action = route[:action]
|
||||
@params = ActionController::Parameters.new(Rack::Utils.parse_nested_query(uri.query).merge(route.except(:controller, :action)))
|
||||
end
|
||||
|
||||
def candidate_stages
|
||||
Workflow::Stage.where(workflow_id: cards.joins(:collection).select("collections.workflow_id").distinct)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user