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
The record publications are attached to.
-
#context_object_id ⇒ Integer
readonly
Id of the context record (+0+ when none).
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#existing_upload_ids ⇒ Array<Integer>
readonly
Upload ids already attached to the context.
-
#offcanvas_id ⇒ String
readonly
DOM id of the offcanvas panel.
-
#publications ⇒ Array<Publication>
readonly
Publications for the current page.
Delegated Instance Attributes collapse
-
#publications_present? ⇒ Boolean
Whether any publications were loaded for the current page.
Instance Method Summary collapse
-
#attach_url ⇒ String
URL of the endpoint attaching a publication to the context.
-
#auto_show? ⇒ Boolean
Whether the offcanvas opens automatically on render.
-
#body_only? ⇒ Boolean
Whether only the offcanvas body is rendered.
-
#context_class_name ⇒ String
Class name of the context record, used in search/attach requests.
-
#controller_path ⇒ String
Controller path used to build the search/attach URLs.
-
#display_empty_state_message ⇒ String
Message shown when the results list is empty.
-
#frame_id ⇒ String
DOM id of the picker's turbo frame.
-
#has_more? ⇒ Boolean
Whether more results are available.
-
#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 ⇒ String?
URL for the next page of results, or nil when there are no more pages.
-
#results_container_id ⇒ String
DOM id of the results container appended during infinite scroll.
-
#search_term ⇒ String?
The active library search term.
-
#search_url ⇒ String
URL of the publication library search endpoint.
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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/components/crm/publication_picker_component.rb', line 36 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 record publications are attached to.
17 |
# File 'app/components/crm/publication_picker_component.rb', line 17 attr_reader :offcanvas_id, :context_object, :context_object_id, :publications, :existing_upload_ids, :cursor |
#context_object_id ⇒ Integer (readonly)
Returns id of the context record (+0+ when none).
17 |
# File 'app/components/crm/publication_picker_component.rb', line 17 attr_reader :offcanvas_id, :context_object, :context_object_id, :publications, :existing_upload_ids, :cursor |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
17 |
# File 'app/components/crm/publication_picker_component.rb', line 17 attr_reader :offcanvas_id, :context_object, :context_object_id, :publications, :existing_upload_ids, :cursor |
#existing_upload_ids ⇒ Array<Integer> (readonly)
Returns upload ids already attached to the context.
17 |
# File 'app/components/crm/publication_picker_component.rb', line 17 attr_reader :offcanvas_id, :context_object, :context_object_id, :publications, :existing_upload_ids, :cursor |
#offcanvas_id ⇒ String (readonly)
Returns DOM id of the offcanvas panel.
17 18 19 |
# File 'app/components/crm/publication_picker_component.rb', line 17 def offcanvas_id @offcanvas_id end |
#publications ⇒ Array<Publication> (readonly)
Returns publications for the current page.
17 |
# File 'app/components/crm/publication_picker_component.rb', line 17 attr_reader :offcanvas_id, :context_object, :context_object_id, :publications, :existing_upload_ids, :cursor |
Instance Method Details
#attach_url ⇒ String
Returns URL of the endpoint attaching a publication to the context.
116 117 118 |
# File 'app/components/crm/publication_picker_component.rb', line 116 def attach_url helpers.url_for(controller: controller_path, action: :attach) end |
#auto_show? ⇒ Boolean
Returns whether the offcanvas opens automatically on render.
91 92 93 |
# File 'app/components/crm/publication_picker_component.rb', line 91 def auto_show? @auto_show end |
#body_only? ⇒ Boolean
Returns whether only the offcanvas body is rendered.
86 87 88 |
# File 'app/components/crm/publication_picker_component.rb', line 86 def body_only? @body_only end |
#context_class_name ⇒ String
Class name of the context record, used in search/attach requests.
65 66 67 68 69 70 71 72 73 |
# File 'app/components/crm/publication_picker_component.rb', line 65 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 ⇒ String
Returns controller path used to build the search/attach URLs.
106 107 108 |
# File 'app/components/crm/publication_picker_component.rb', line 106 def controller_path @controller_path || helpers.controller.controller_name end |
#display_empty_state_message ⇒ String
Returns message shown when the results list is empty.
141 142 143 |
# File 'app/components/crm/publication_picker_component.rb', line 141 def search_term.present? ? "No publications found. Try a different search term." : "Enter a search term to find publications." end |
#frame_id ⇒ String
Returns DOM id of the picker's turbo frame.
76 77 78 |
# File 'app/components/crm/publication_picker_component.rb', line 76 def frame_id "publication-picker-frame-#{context_object_id}" end |
#has_more? ⇒ Boolean
Returns whether more results are available.
101 102 103 |
# File 'app/components/crm/publication_picker_component.rb', line 101 def has_more? @has_more end |
#next_page_url ⇒ String?
Returns URL for the next page of results, or nil when there
are no more pages.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/components/crm/publication_picker_component.rb', line 122 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 whether any publications were loaded for the current page.
138 |
# File 'app/components/crm/publication_picker_component.rb', line 138 delegate :present?, to: :publications, prefix: true |
#results_container_id ⇒ String
Returns DOM id of the results container appended during infinite scroll.
81 82 83 |
# File 'app/components/crm/publication_picker_component.rb', line 81 def results_container_id "publication-picker-results-#{context_object_id}" end |
#search_term ⇒ String?
Returns the active library search term.
96 97 98 |
# File 'app/components/crm/publication_picker_component.rb', line 96 def search_term @explicit_search_term.presence || helpers.params[:term] end |
#search_url ⇒ String
Returns URL of the publication library search endpoint.
111 112 113 |
# File 'app/components/crm/publication_picker_component.rb', line 111 def search_url helpers.url_for(controller: controller_path, action: "search_library") end |