Class: Crm::PublicationPickerComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Crm::PublicationPickerComponent
- Defined in:
- app/components/crm/publication_picker_component.rb
Overview
Publication picker as an offcanvas side panel with infinite scroll
Instance Attribute Summary collapse
-
#context_object ⇒ Object
readonly
Returns the value of attribute context_object.
-
#context_object_id ⇒ Object
readonly
Returns the value of attribute context_object_id.
-
#existing_upload_ids ⇒ Object
readonly
Returns the value of attribute existing_upload_ids.
-
#offcanvas_id ⇒ Object
readonly
Returns the value of attribute offcanvas_id.
-
#publications ⇒ Object
readonly
Returns the value of attribute publications.
Instance Method Summary collapse
- #attach_url ⇒ Object
- #auto_show? ⇒ Boolean
- #body_only? ⇒ Boolean
- #context_class_name ⇒ Object
- #controller_path ⇒ Object
- #cursor ⇒ Object
- #display_empty_state_message ⇒ Object
- #frame_id ⇒ Object
- #has_more? ⇒ Boolean
-
#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
constructor
A new instance of PublicationPickerComponent.
- #next_page_url ⇒ Object
- #publications_present? ⇒ Boolean
- #results_container_id ⇒ Object
- #search_term ⇒ Object
- #search_url ⇒ Object
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_object ⇒ Object (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_id ⇒ Object (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_ids ⇒ Object (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_id ⇒ Object (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 |
#publications ⇒ Object (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_url ⇒ Object
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
60 61 62 |
# File 'app/components/crm/publication_picker_component.rb', line 60 def auto_show? @auto_show end |
#body_only? ⇒ Boolean
56 57 58 |
# File 'app/components/crm/publication_picker_component.rb', line 56 def body_only? @body_only end |
#context_class_name ⇒ Object
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_path ⇒ Object
76 77 78 |
# File 'app/components/crm/publication_picker_component.rb', line 76 def controller_path @controller_path || helpers.controller.controller_name end |
#cursor ⇒ Object
68 69 70 |
# File 'app/components/crm/publication_picker_component.rb', line 68 def cursor @cursor end |
#display_empty_state_message ⇒ Object
106 107 108 |
# File 'app/components/crm/publication_picker_component.rb', line 106 def search_term.present? ? "No publications found. Try a different search term." : "Enter a search term to find publications." end |
#frame_id ⇒ Object
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
72 73 74 |
# File 'app/components/crm/publication_picker_component.rb', line 72 def has_more? @has_more end |
#next_page_url ⇒ Object
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
102 103 104 |
# File 'app/components/crm/publication_picker_component.rb', line 102 def publications_present? publications.present? end |
#results_container_id ⇒ Object
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_term ⇒ Object
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_url ⇒ Object
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 |