Class: Crm::ActivityCardComponent

Inherits:
ApplicationComponent show all
Includes:
ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper, ActionView::RecordIdentifier
Defined in:
app/components/crm/activity_card_component.rb

Overview

ViewComponent: renders the activity card block.

Delegated Instance Attributes collapse

Methods inherited from ApplicationComponent

#cms_link, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#fetch_or_fallback

Constructor Details

#initialize(activity:, selected_activity_id: nil, context_object: nil) ⇒ ActivityCardComponent

Returns a new instance of ActivityCardComponent.

Parameters:

  • activity (Activity)

    the activity to render

  • selected_activity_id (Integer, nil) (defaults to: nil)

    id of the activity that should
    render expanded (used when deep-linking to a specific activity)

  • context_object (Object, nil) (defaults to: nil)

    the record the card is embedded on,
    used to suppress links pointing back at itself



24
25
26
27
28
29
# File 'app/components/crm/activity_card_component.rb', line 24

def initialize(activity:, selected_activity_id: nil, context_object: nil)
  super()
  @activity = activity
  @context_object = context_object
  @pre_open = activity.persisted? && selected_activity_id == activity.id
end

Instance Method Details

#notes_previewString?

Strips HTML and normalises whitespace for the collapsed summary row.
Visual truncation is handled by CSS line-clamp; the full text is kept
in the DOM so the "Activities" toggle can reveal it without a fetch.
Returns nil when there is no previewable text.

Nokogiri's text serialisation both strips tags and decodes entities
(so   collapses into the surrounding whitespace) — strip_tags
alone leaves " " as literal text in the preview.

Returns:

  • (String, nil)

    plain-text preview, or nil when there is no text



46
47
48
49
50
51
52
53
54
# File 'app/components/crm/activity_card_component.rb', line 46

def notes_preview
  text = activity.notes.presence || activity.description.presence
  return unless text

  Nokogiri::HTML::DocumentFragment
    .parse(text.gsub(%r{</(p|div|br|li|h\d)>}i, " "))
    .text
    .gsub(/[[:space:]]+/, " ").strip.presence
end

#pre_open?Boolean

Whether the card should render expanded on first paint.

Returns:

  • (Boolean)


33
34
35
# File 'app/components/crm/activity_card_component.rb', line 33

def pre_open?
  @pre_open
end

#render_activity_formObject

Alias for Helpers#render_activity_form

Returns:

  • (Object)

    Helpers#render_activity_form

See Also:



17
# File 'app/components/crm/activity_card_component.rb', line 17

delegate :truncate, :render_date, :render_activity_form, to: :helpers

#render_dateObject

Alias for Helpers#render_date

Returns:

  • (Object)

    Helpers#render_date

See Also:



17
# File 'app/components/crm/activity_card_component.rb', line 17

delegate :truncate, :render_date, :render_activity_form, to: :helpers

#truncateObject

Alias for Helpers#truncate

Returns:

  • (Object)

    Helpers#truncate

See Also:



17
# File 'app/components/crm/activity_card_component.rb', line 17

delegate :truncate, :render_date, :render_activity_form, to: :helpers