Class: Avo::MediaLibrary::ListComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Avo::MediaLibrary::ListComponent
- Includes:
- ApplicationHelper, Pagy::Method
- Defined in:
- app/components/avo/media_library/list_component.rb
Constant Summary collapse
- NUMBER_DELIMITER =
Avo::PaginatorComponent::NUMBER_DELIMITER
Constants included from Concerns::FindAssociationField
Concerns::FindAssociationField::ASSOCIATIONS
Instance Method Summary collapse
- #controller ⇒ Object
- #formatted_count ⇒ Object
- #formatted_series_nav ⇒ Object
-
#initialize(attaching: false, turbo_frame: nil) ⇒ ListComponent
constructor
A new instance of ListComponent.
- #limit ⇒ Object
- #query ⇒ Object
Methods included from ApplicationHelper
#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #rtl?, #text_direction, #ui, #wrap_in_modal
Methods included from ResourcesHelper
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table
Methods inherited from BaseComponent
#component_name, #hotkey_badge
Methods included from Concerns::FindAssociationField
Constructor Details
#initialize(attaching: false, turbo_frame: nil) ⇒ ListComponent
Returns a new instance of ListComponent.
11 12 13 14 15 16 |
# File 'app/components/avo/media_library/list_component.rb', line 11 def initialize(attaching: false, turbo_frame: nil) @attaching = attaching @pagy, @blobs = pagy(:offset, query, limit:) turbo_frame ||= params[:turbo_frame] @turbo_frame = turbo_frame.present? ? CGI.escapeHTML(turbo_frame.to_s) : :_top end |
Instance Method Details
#controller ⇒ Object
18 |
# File 'app/components/avo/media_library/list_component.rb', line 18 def controller = Avo::Current.view_context.controller |
#formatted_count ⇒ Object
29 30 31 |
# File 'app/components/avo/media_library/list_component.rb', line 29 def formatted_count formatted_number(@pagy.count) end |
#formatted_series_nav ⇒ Object
33 34 35 36 37 |
# File 'app/components/avo/media_library/list_component.rb', line 33 def formatted_series_nav @pagy.series_nav(anchor_string: %(data-turbo-frame="#{@turbo_frame}")) .gsub(/>(\d{4,})</) { |match| match.sub($1, formatted_number($1)) } .html_safe end |
#limit ⇒ Object
27 |
# File 'app/components/avo/media_library/list_component.rb', line 27 def limit = @attaching ? 12 : 24 |
#query ⇒ Object
20 21 22 23 24 25 |
# File 'app/components/avo/media_library/list_component.rb', line 20 def query # ignore blobs who are just a variant to avoid "n+1" blob creation ActiveStorage::Blob.includes(:attachments) .where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").select(:blob_id)) .order(created_at: :desc) end |