From 6446e5b409eb6df2ab23eb7e8d13d4a6a979e96c Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 19 Jun 2025 13:00:26 +0200 Subject: [PATCH] Select cards with # --- app/controllers/prompts/cards_controller.rb | 15 +++++++++++++++ app/helpers/rich_text_helper.rb | 4 ++++ app/models/card/searchable.rb | 2 +- app/models/concerns/searchable.rb | 1 + app/views/cards/edit.html.erb | 1 + app/views/prompts/cards/_card.html.erb | 8 ++++++++ app/views/prompts/cards/index.html.erb | 1 + config/routes.rb | 1 + db/schema.rb | 1 + db/schema_cache.yml | 18 +++++++++++++++++- 10 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 app/controllers/prompts/cards_controller.rb create mode 100644 app/views/prompts/cards/_card.html.erb create mode 100644 app/views/prompts/cards/index.html.erb diff --git a/app/controllers/prompts/cards_controller.rb b/app/controllers/prompts/cards_controller.rb new file mode 100644 index 000000000..04737be76 --- /dev/null +++ b/app/controllers/prompts/cards_controller.rb @@ -0,0 +1,15 @@ +class Prompts::CardsController < ApplicationController + def index + @cards = if filter_param.present? + Current.user.accessible_cards.mentioning(filter_param) + else + Current.user.accessible_cards.latest.limit(10) + end + render layout: false + end + + private + def filter_param + params[:filter] + end +end diff --git a/app/helpers/rich_text_helper.rb b/app/helpers/rich_text_helper.rb index e3ac46c83..42c7cf5f1 100644 --- a/app/helpers/rich_text_helper.rb +++ b/app/helpers/rich_text_helper.rb @@ -2,4 +2,8 @@ module RichTextHelper def mentions_prompt content_tag "lexical-prompt", "", trigger: "@", src: prompts_users_path, name: "mention" end + + def cards_prompt + content_tag "lexical-prompt", "", trigger: "#", src: prompts_cards_path, name: "card", "insert-editable-text": true, "remote-filtering": true + end end diff --git a/app/models/card/searchable.rb b/app/models/card/searchable.rb index af2d3dbc9..97fb5b665 100644 --- a/app/models/card/searchable.rb +++ b/app/models/card/searchable.rb @@ -45,7 +45,7 @@ module Card::Searchable private # TODO: Temporary until we stabilize the search API def title_and_description - [ title, description.to_plain_text ].join(" ") + [ id.to_s, title, description.to_plain_text ].join(" ") end def search_embedding_content diff --git a/app/models/concerns/searchable.rb b/app/models/concerns/searchable.rb index 5946212dd..9a6b03bc0 100644 --- a/app/models/concerns/searchable.rb +++ b/app/models/concerns/searchable.rb @@ -68,3 +68,4 @@ module Searchable search_embedding&.destroy end end + diff --git a/app/views/cards/edit.html.erb b/app/views/cards/edit.html.erb index 4a6043125..03b1ae325 100644 --- a/app/views/cards/edit.html.erb +++ b/app/views/cards/edit.html.erb @@ -12,6 +12,7 @@ placeholder: "Add some notes, context, pictures, or video about this…", data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } do %> <%= mentions_prompt %> + <%= cards_prompt %> <% end %> <%= form.button "Save changes", type: :submit, class: "btn btn--reversed", style: "--btn-background: #{@card.color}" %> diff --git a/app/views/prompts/cards/_card.html.erb b/app/views/prompts/cards/_card.html.erb new file mode 100644 index 000000000..ebecb20a6 --- /dev/null +++ b/app/views/prompts/cards/_card.html.erb @@ -0,0 +1,8 @@ + + + + diff --git a/app/views/prompts/cards/index.html.erb b/app/views/prompts/cards/index.html.erb new file mode 100644 index 000000000..253e6e543 --- /dev/null +++ b/app/views/prompts/cards/index.html.erb @@ -0,0 +1 @@ +<%= render partial: "prompts/cards/card", collection: @cards %> diff --git a/config/routes.rb b/config/routes.rb index dc00a8766..8032e842d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -105,6 +105,7 @@ Rails.application.routes.draw do namespace :prompts do resources :users + resources :cards end namespace :public do diff --git a/db/schema.rb b/db/schema.rb index d27ab0295..dff0ccb02 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -324,6 +324,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_06_09_102553) do t.datetime "created_at", null: false t.string "title" t.datetime "updated_at", null: false + t.index ["title"], name: "index_tags_on_account_id_and_title", unique: true end create_table "users", force: :cascade do |t| diff --git a/db/schema_cache.yml b/db/schema_cache.yml index 479604bf0..89fca8331 100644 --- a/db/schema_cache.yml +++ b/db/schema_cache.yml @@ -2200,7 +2200,23 @@ indexes: nulls_not_distinct: comment: valid: true - tags: [] + tags: + - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition + table: tags + name: index_tags_on_account_id_and_title + unique: true + columns: + - title + lengths: {} + orders: {} + opclasses: {} + where: + type: + using: + include: + nulls_not_distinct: + comment: + valid: true users: - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition table: users