Sha256: ac3543eb63021c0cfa20cb5a10194fd8d09047d38caa7b1fe2239fb4e7100704

Contents?: true

Size: 822 Bytes

Versions: 47

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

class Avo::Fields::Common::Files::ViewType::GridItemComponent < Avo::BaseComponent
  prop :field
  prop :resource
  prop :file
  prop :extra_classes

  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

47 entries across 47 versions & 1 rubygems

Version Path
avo-3.18.1.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.18.1 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.18.0.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.18.0 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.9.beta2 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.9.beta1 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.9.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.9 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.8.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.8 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.7 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.6.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.6 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.5 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.3 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.5.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.4.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.3.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb
avo-3.17.2.tw4 app/components/avo/fields/common/files/view_type/grid_item_component.rb