Module: Protege::ThreadsHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/protege/threads_helper.rb
Overview
View helpers for thread pages — the inbox list, compose selectors, sidebar display, and the thread detail header.
Instance Method Summary collapse
-
#available_persona_options ⇒ Array<Array(String, Integer)>
Format the available personas as
[label, id]pairs for a select dropdown. -
#available_personas ⇒ ActiveRecord::Relation<Protege::Persona>
List the active personas eligible for the compose form.
-
#inbox_threads ⇒ ActiveRecord::Relation<Protege::EmailThread>
Fetch every
EmailThreadordered by most recent activity. -
#thread_date(thread) ⇒ String?
Format the thread's last-activity date for sidebar display.
-
#thread_header(thread) { ... } ⇒ ActiveSupport::SafeBuffer
Render the thread detail header — subject, persona, message count, last activity, and thread ID.
-
#thread_preview(thread) ⇒ String
Build a one-line preview from the first line of the latest message.
-
#thread_title(thread) ⇒ String
Format a thread subject with its message count for sidebar display.
Instance Method Details
#available_persona_options ⇒ Array<Array(String, Integer)>
Format the available personas as [label, id] pairs for a select dropdown.
24 25 26 |
# File 'app/helpers/protege/threads_helper.rb', line 24 def available_personas.map { |persona| ["#{persona.name} <#{persona.email_address}>", persona.id] } end |
#available_personas ⇒ ActiveRecord::Relation<Protege::Persona>
List the active personas eligible for the compose form.
17 18 19 |
# File 'app/helpers/protege/threads_helper.rb', line 17 def available_personas Persona.active end |
#inbox_threads ⇒ ActiveRecord::Relation<Protege::EmailThread>
Fetch every EmailThread ordered by most recent activity.
10 11 12 |
# File 'app/helpers/protege/threads_helper.rb', line 10 def inbox_threads EmailThread.order(last_message_at: :desc) end |
#thread_date(thread) ⇒ String?
Format the thread's last-activity date for sidebar display.
44 45 46 |
# File 'app/helpers/protege/threads_helper.rb', line 44 def thread_date(thread) thread.&.strftime('%-m/%-d/%y') end |
#thread_header(thread) { ... } ⇒ ActiveSupport::SafeBuffer
Render the thread detail header — subject, persona, message count, last activity, and thread ID. An optional block renders actions beside the title.
62 63 64 65 66 67 68 |
# File 'app/helpers/protege/threads_helper.rb', line 62 def thread_header(thread, &block) tag.div(class: 'flex-shrink-0 px-5 py-3') do thread_header_title(thread, &block) + (thread) + thread_header_id(thread) end end |
#thread_preview(thread) ⇒ String
Build a one-line preview from the first line of the latest message.
52 53 54 |
# File 'app/helpers/protege/threads_helper.rb', line 52 def thread_preview(thread) thread.&.text_body.to_s.lines.first.to_s.strip.presence || '—' end |
#thread_title(thread) ⇒ String
Format a thread subject with its message count for sidebar display.
Truncation is handled by the sidebar_item helper.
thread_title(thread) # => "Hello (3)"
35 36 37 38 |
# File 'app/helpers/protege/threads_helper.rb', line 35 def thread_title(thread) subject = thread.subject.presence || '(no subject)' thread. > 1 ? "#{thread.persona.name} - #{subject} (#{thread.})" : subject end |