From c319c49345d7bce0a0b7c2f26f398945d4caedd3 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Wed, 25 Jun 2025 07:48:02 +0200 Subject: [PATCH] Add search command --- app/models/command/get_insight.rb | 8 -------- app/models/command/parser.rb | 11 +++++++---- app/models/command/search.rb | 11 +++++++++++ app/views/commands/_help.html.erb | 2 +- test/models/command/search_test.rb | 11 +++++++++++ 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 app/models/command/search.rb create mode 100644 test/models/command/search_test.rb diff --git a/app/models/command/get_insight.rb b/app/models/command/get_insight.rb index adfde915a..a43183fd0 100644 --- a/app/models/command/get_insight.rb +++ b/app/models/command/get_insight.rb @@ -12,14 +12,6 @@ class Command::GetInsight < Command Command::Result::InsightResponse.new(response.content) end - def undoable? - false - end - - def needs_confirmation? - false - end - private def chat chat = RubyLLM.chat diff --git a/app/models/command/parser.rb b/app/models/command/parser.rb index c37a7a174..fe6269515 100644 --- a/app/models/command/parser.rb +++ b/app/models/command/parser.rb @@ -18,6 +18,7 @@ class Command::Parser private def parse_command(string) command_name, *command_arguments = string.strip.split(" ") + combined_arguments = command_arguments.join(" ") case command_name when /^#/ @@ -26,16 +27,18 @@ class Command::Parser Command::GoToUser.new(user_id: assignee_from(command_name)&.id) when "/assign", "/assignto" Command::Assign.new(assignee_ids: assignees_from(command_arguments).collect(&:id), card_ids: cards.ids) - when "/insight" - Command::GetInsight.new(query: command_arguments.join(" "), card_ids: cards.ids) when "/clear" Command::ClearFilters.new(params: filter.as_params) when "/close" - Command::Close.new(card_ids: cards.ids, reason: command_arguments.join(" ")) + Command::Close.new(card_ids: cards.ids, reason: combined_arguments) + when "/insight" + Command::GetInsight.new(query: combined_arguments, card_ids: cards.ids) + when "/search" + Command::Search.new(terms: combined_arguments) when "/visit" Command::VisitUrl.new(url: command_arguments.first) when "/tag" - Command::Tag.new(tag_title: tag_title_from(command_arguments.join(" ")), card_ids: cards.ids) + Command::Tag.new(tag_title: tag_title_from(combined_arguments), card_ids: cards.ids) else parse_free_string(string) end diff --git a/app/models/command/search.rb b/app/models/command/search.rb new file mode 100644 index 000000000..1a4586718 --- /dev/null +++ b/app/models/command/search.rb @@ -0,0 +1,11 @@ +class Command::Search < Command + store_accessor :data, :terms + + def title + "Search '#{terms}'" + end + + def execute + redirect_to search_path(q: terms) + end +end diff --git a/app/views/commands/_help.html.erb b/app/views/commands/_help.html.erb index 45d9db64c..3454c7c91 100644 --- a/app/views/commands/_help.html.erb +++ b/app/views/commands/_help.html.erb @@ -12,7 +12,7 @@
Just show cards taggged [tag]
[id] [id]…
Show multiple cards by ID
-
[search term]
+
[/search term]
Keyword search
/clear
Clear all filters
diff --git a/test/models/command/search_test.rb b/test/models/command/search_test.rb new file mode 100644 index 000000000..61e46b436 --- /dev/null +++ b/test/models/command/search_test.rb @@ -0,0 +1,11 @@ +require "test_helper" + +class Command::SearchTest < ActionDispatch::IntegrationTest + include CommandTestHelper + + test "redirect to the user perma" do + result = execute_command "/search something" + + assert_equal search_path(q: "something"), result.url + end +end