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.



14
15
16
17
18
19
# File 'app/components/crm/activity_card_component.rb', line 14

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_previewObject

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.



33
34
35
36
37
38
39
40
41
# File 'app/components/crm/activity_card_component.rb', line 33

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

Returns:

  • (Boolean)


21
22
23
# File 'app/components/crm/activity_card_component.rb', line 21

def pre_open?
  @pre_open
end

#render_activity_formObject

Alias for Helpers#render_activity_form

Returns:

  • (Object)

    Helpers#render_activity_form

See Also:



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

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

#render_dateObject

Alias for Helpers#render_date

Returns:

  • (Object)

    Helpers#render_date

See Also:



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

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

#truncateObject

Alias for Helpers#truncate

Returns:

  • (Object)

    Helpers#truncate

See Also:



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

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