Class: Crm::AttachmentsDisplayComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/crm/attachments_display_component.rb

Overview

ViewComponent: renders the attachments display block.

Lists a record's uploads inside a Turbo Frame, wrapping each upload in a
UploadWrapperComponent with deletion disabled.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context_object:, controller_path: nil) ⇒ AttachmentsDisplayComponent

Returns a new instance of AttachmentsDisplayComponent.

Parameters:

  • context_object (Object)

    the record whose uploads are displayed

  • controller_path (String, nil) (defaults to: nil)

    controller path for upload URLs;
    defaults to the tableized class name of +context_object+



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

def initialize(context_object:, controller_path: nil)
  super()
  @context_object = context_object
  @controller_path = controller_path || context_object.class.name.tableize
end

Instance Attribute Details

#context_objectObject, String (readonly)

Returns:

  • (Object)

    the record whose uploads are displayed (must respond to +uploads+)

  • (String)

    controller path used to build upload URLs



10
11
12
# File 'app/components/crm/attachments_display_component.rb', line 10

def context_object
  @context_object
end

#controller_pathObject, String (readonly)

Returns:

  • (Object)

    the record whose uploads are displayed (must respond to +uploads+)

  • (String)

    controller path used to build upload URLs



10
11
12
# File 'app/components/crm/attachments_display_component.rb', line 10

def controller_path
  @controller_path
end

Instance Method Details

#attachments_container_idString

DOM id of the attachments grid container.

Returns:

  • (String)

    e.g. +"attachments-42"+



35
36
37
# File 'app/components/crm/attachments_display_component.rb', line 35

def attachments_container_id
  "attachments-#{context_object_id}"
end

#context_object_idInteger

Numeric id of the context object, used in DOM ids.

Returns:

  • (Integer)

    the context object's id, or +0+ when it has none



23
24
25
# File 'app/components/crm/attachments_display_component.rb', line 23

def context_object_id
  context_object.try(:id).to_i
end

#frame_idString

DOM id of the wrapping Turbo Frame.

Returns:

  • (String)

    e.g. +"attachments-frame-42"+



29
30
31
# File 'app/components/crm/attachments_display_component.rb', line 29

def frame_id
  "attachments-frame-#{context_object_id}"
end