Class: Crm::PublicationPickerComponent

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

Overview

Publication picker as an offcanvas side panel with infinite scroll

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offcanvas_id:, context_object:, context_object_id: nil, context_class_name: nil, controller_path: nil, publications: nil, existing_upload_ids: nil, search_term: nil, cursor: nil, has_more: false, body_only: false, auto_show: false) ⇒ PublicationPickerComponent

Returns a new instance of PublicationPickerComponent.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/crm/publication_picker_component.rb', line 11

def initialize(offcanvas_id:,
               context_object:,
               context_object_id: nil,
               context_class_name: nil,
               controller_path: nil,
               publications: nil,
               existing_upload_ids: nil,
               search_term: nil,
               cursor: nil,
               has_more: false,
               body_only: false,
               auto_show: false)
  super()
  @offcanvas_id = offcanvas_id
  @context_object = context_object
  @context_object_id = context_object_id || context_object.try(:id).to_i
  @explicit_context_class_name = context_class_name
  @controller_path = controller_path
  @publications = publications || []
  @existing_upload_ids = existing_upload_ids || context_object.try(:upload_ids) || []
  @explicit_search_term = search_term
  @cursor = cursor
  @has_more = has_more
  @body_only = body_only
  @auto_show = auto_show
end

Instance Attribute Details

#context_objectObject (readonly)

Returns the value of attribute context_object.



5
6
7
# File 'app/components/crm/publication_picker_component.rb', line 5

def context_object
  @context_object
end

#context_object_idObject (readonly)

Returns the value of attribute context_object_id.



5
6
7
# File 'app/components/crm/publication_picker_component.rb', line 5

def context_object_id
  @context_object_id
end

#existing_upload_idsObject (readonly)

Returns the value of attribute existing_upload_ids.



5
6
7
# File 'app/components/crm/publication_picker_component.rb', line 5

def existing_upload_ids
  @existing_upload_ids
end

#offcanvas_idObject (readonly)

Returns the value of attribute offcanvas_id.



5
6
7
# File 'app/components/crm/publication_picker_component.rb', line 5

def offcanvas_id
  @offcanvas_id
end

#publicationsObject (readonly)

Returns the value of attribute publications.



5
6
7
# File 'app/components/crm/publication_picker_component.rb', line 5

def publications
  @publications
end

Instance Method Details

#attach_urlObject



84
85
86
# File 'app/components/crm/publication_picker_component.rb', line 84

def attach_url
  helpers.url_for(controller: controller_path, action: :attach)
end

#auto_show?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/components/crm/publication_picker_component.rb', line 60

def auto_show?
  @auto_show
end

#body_only?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/components/crm/publication_picker_component.rb', line 56

def body_only?
  @body_only
end

#context_class_nameObject



38
39
40
41
42
43
44
45
46
# File 'app/components/crm/publication_picker_component.rb', line 38

def context_class_name
  @context_class_name ||= if @explicit_context_class_name.present?
                            @explicit_context_class_name
                          elsif @context_object.present?
                            @context_object.class.name
                          else
                            helpers.controller.controller_name.classify
                          end
end

#controller_pathObject



76
77
78
# File 'app/components/crm/publication_picker_component.rb', line 76

def controller_path
  @controller_path || helpers.controller.controller_name
end

#cursorObject



68
69
70
# File 'app/components/crm/publication_picker_component.rb', line 68

def cursor
  @cursor
end

#display_empty_state_messageObject



106
107
108
# File 'app/components/crm/publication_picker_component.rb', line 106

def display_empty_state_message
  search_term.present? ? "No publications found. Try a different search term." : "Enter a search term to find publications."
end

#frame_idObject



48
49
50
# File 'app/components/crm/publication_picker_component.rb', line 48

def frame_id
  "publication-picker-frame-#{context_object_id}"
end

#has_more?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/components/crm/publication_picker_component.rb', line 72

def has_more?
  @has_more
end

#next_page_urlObject



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/components/crm/publication_picker_component.rb', line 88

def next_page_url
  return nil unless has_more? && cursor.present?

  helpers.url_for(
    controller: controller_path,
    action: "search_library",
    term: search_term,
    cursor: cursor,
    context_class: context_class_name,
    context_object_id: context_object_id,
    append: true
  )
end

#publications_present?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/components/crm/publication_picker_component.rb', line 102

def publications_present?
  publications.present?
end

#results_container_idObject



52
53
54
# File 'app/components/crm/publication_picker_component.rb', line 52

def results_container_id
  "publication-picker-results-#{context_object_id}"
end

#search_termObject



64
65
66
# File 'app/components/crm/publication_picker_component.rb', line 64

def search_term
  @explicit_search_term.presence || helpers.params[:term]
end

#search_urlObject



80
81
82
# File 'app/components/crm/publication_picker_component.rb', line 80

def search_url
  helpers.url_for(controller: controller_path, action: "search_library")
end