Class: QuickSearch::ActivityPresenter

Inherits:
PinPresenter
  • Object
show all
Defined in:
app/presenters/quick_search/activity_presenter.rb

Overview

Presents an Activity as a quick search result / pinned item.

See Also:

Instance Method Summary collapse

Instance Method Details

#activity_destination_pathString

Destination for "open this activity" links (pinned offcanvas, search results,
etc.). Mirrors what ActivitiesController#show would redirect to, so the
client doesn't pay for a 302 hop on every click. Falls back to activity_path
if the parent isn't routable, letting the controller's redirect handle it.

Returns:

  • (String)

    the activity or parent path



24
25
26
27
28
29
30
31
# File 'app/presenters/quick_search/activity_presenter.rb', line 24

def activity_destination_path
  parent = result.resource || result.party
  return activity_path(result) unless parent

  polymorphic_path(parent, tab: 'activities', selected_activity: result.id)
rescue StandardError
  activity_path(result)
end

#presenting_context?(context_type, context_id) ⇒ Boolean

Whether this activity belongs to the record currently being viewed.

Matches against the activity's resource, the resource's own resource, or
the resource's party.

Parameters:

  • context_type (String)

    the class name of the viewed record

  • context_id (Integer, String)

    the id of the viewed record

Returns:

  • (Boolean)

    true when the activity is attached to the context



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/presenters/quick_search/activity_presenter.rb', line 41

def presenting_context?(context_type, context_id)
  return false unless context_type.present? && context_id.present?

  match = (result.resource_type == context_type.to_s and result.resource_id == context_id.to_i)
  match ||= (result.resource.resource_type == context_type.to_s and result.resource.resource_id == context_id.to_i) if result.resource.resource_id
  begin
    match ||= (result.resource.party_id == context_id.to_i) if result.resource.party_id && context_type.constantize.find(context_id.to_i)
  rescue StandardError
    nil
  end
  match
end

#set_attributesvoid

This method returns an undefined value.

Sets the card title, sub-header (timezone, state, due date), and link.



10
11
12
13
14
15
16
# File 'app/presenters/quick_search/activity_presenter.rb', line 10

def set_attributes
  @title = [result.display_type, result.party&.full_name, result.resource&.to_s].compact_blank.join(" \u2022 ")
  due_date = result.target_datetime&.to_date ? "Due #{result.target_datetime.to_date}" : nil
  @sub_header = [result.party&.timezone_name, result.party&.state_code, due_date].compact_blank.join(" \u2022 ")
  # @sub_header ||= result&.resource.to_s
  @link = activity_destination_path
end