Sha256: a60e41360e559cfb654c2a95cb6d17e5fa2dc5e2e1941aea85d214958538bc30

Contents?: true

Size: 895 Bytes

Versions: 31

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

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

  def initialize(field:, resource:, file: nil)
    @file = file
    @field = field
    @resource = resource
  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

31 entries across 31 versions & 1 rubygems

Version Path
avo-3.0.1.beta17 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta18 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta19 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta15 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta16 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta14 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta12 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta13 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta10 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta11 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.0.pre19 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta8 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta9 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta6 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta7 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta5 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta2 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta4 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.1.beta3 app/components/avo/fields/common/files/view_type/grid_component.rb
avo-3.0.0.beta1 app/components/avo/fields/common/files/view_type/grid_component.rb