Class: Avo::MediaLibrary::ListComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Avo::MediaLibrary::ListComponent
- Includes:
- ApplicationHelper, Pagy::Backend
- Defined in:
- app/components/avo/media_library/list_component.rb
Constant Summary
Constants included from Concerns::FindAssociationField
Concerns::FindAssociationField::ASSOCIATIONS
Instance Method Summary collapse
- #controller ⇒ 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, #button_classes, #card_classes, #chart_color, #container_classes, #container_is_full_width?, #d, #decode_filter_params, #e, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #pagy_major_version, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #svg, #white_panel_classes
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, #has_with_trial
Methods included from Concerns::FindAssociationField
Constructor Details
#initialize(attaching: false, turbo_frame: nil) ⇒ ListComponent
Returns a new instance of ListComponent.
9 10 11 12 13 14 |
# File 'app/components/avo/media_library/list_component.rb', line 9 def initialize(attaching: false, turbo_frame: nil) @attaching = attaching @pagy, @blobs = pagy(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
16 |
# File 'app/components/avo/media_library/list_component.rb', line 16 def controller = Avo::Current.view_context.controller |
#limit ⇒ Object
25 |
# File 'app/components/avo/media_library/list_component.rb', line 25 def limit = @attaching ? 12 : 24 |
#query ⇒ Object
18 19 20 21 22 23 |
# File 'app/components/avo/media_library/list_component.rb', line 18 def query ActiveStorage::Blob.includes(:attachments) # ignore blobs who are just a variant to avoid "n+1" blob creation .where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").select(:blob_id)) .order(created_at: :desc) end |