Sha256: 2a9a64c3dee48918e42ec8eb4f1316c4cc5df4c932b673a51a158452a6643cd3
Contents?: true
Size: 878 Bytes
Versions: 3
Compression:
Stored size: 878 Bytes
Contents
# frozen_string_literal: true module Avo module MediaLibrary class ListComponent < Avo::BaseComponent include Avo::ApplicationHelper include Pagy::Backend 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 def controller = Avo::Current.view_context.controller 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").pluck(:blob_id)) .order(created_at: :desc) end def limit = @attaching ? 12 : 24 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
avo-3.16.5 | app/components/avo/media_library/list_component.rb |
avo-3.16.4 | app/components/avo/media_library/list_component.rb |
avo-3.16.3 | app/components/avo/media_library/list_component.rb |