Class: Crm::ActivityCardComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Crm::ActivityCardComponent
- 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
-
#render_activity_form ⇒ Object
Alias for Helpers#render_activity_form.
-
#render_date ⇒ Object
Alias for Helpers#render_date.
-
#truncate ⇒ Object
Alias for Helpers#truncate.
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
-
#initialize(activity:, selected_activity_id: nil, context_object: nil) ⇒ ActivityCardComponent
constructor
A new instance of ActivityCardComponent.
-
#notes_preview ⇒ Object
Strips HTML and normalises whitespace for the collapsed summary row.
- #pre_open? ⇒ Boolean
Methods inherited from ApplicationComponent
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_preview ⇒ Object
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
21 22 23 |
# File 'app/components/crm/activity_card_component.rb', line 21 def pre_open? @pre_open end |
#render_activity_form ⇒ Object
Alias for Helpers#render_activity_form
12 |
# File 'app/components/crm/activity_card_component.rb', line 12 delegate :truncate, :render_date, :render_activity_form, to: :helpers |
#render_date ⇒ Object
Alias for Helpers#render_date
12 |
# File 'app/components/crm/activity_card_component.rb', line 12 delegate :truncate, :render_date, :render_activity_form, to: :helpers |
#truncate ⇒ Object
Alias for Helpers#truncate
12 |
# File 'app/components/crm/activity_card_component.rb', line 12 delegate :truncate, :render_date, :render_activity_form, to: :helpers |