Sha256: 2a983d050bbd4ae2417751eaee104c3d55ce8dee3992f3d7b353612f4ed84dba

Contents?: true

Size: 954 Bytes

Versions: 57

Compression:

Stored size: 954 Bytes

Contents

# frozen_string_literal: true

class Avo::Fields::Common::Files::ViewType::GridItemComponent < ViewComponent::Base
  attr_reader :field, :resource

  def initialize(field:, resource:, file: nil, extra_classes: nil)
    @file = file
    @field = field
    @resource = resource
    @extra_classes = extra_classes
  end

  def id
    field.id
  end

  def file
    @file || field.value.attachment
  rescue
    nil
  end

  def is_image?
    file.image? || field.is_image
  rescue
    false
  end

  def is_audio?
    file.audio? || field.is_audio
  rescue
    false
  end

  def is_video?
    file.video? || field.is_video
  rescue
    false
  end

  def render?
    record_persisted?
  end

  # If record is not persistent blob is automatically destroyed otherwise it can be "lost" on storage
  def record_persisted?
    return true if @resource.record.persisted?

    ActiveStorage::Blob.destroy(file.blob_id) if file.blob_id.present?
    false
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
avo-3.2.1 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.2.0 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.7 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.6 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.5 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.3 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.2 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.1 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.1.0 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.0.8 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.0.7 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.0.6 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.0.5 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.0.4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.0.3 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.0.2 app/components/avo/fields/common/files/view_type/grid_item_component.rb