Class: Avo::Fields::Common::SingleFileViewerComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Avo::Fields::Common::SingleFileViewerComponent
show all
- Includes:
- ApplicationHelper
- Defined in:
- app/components/avo/fields/common/single_file_viewer_component.rb
Instance Method Summary
collapse
#a_button, #a_link, #button_classes, #empty_state, #get_model_class, #input_classes, #render_license_warning, #render_license_warnings, #root_path_without_url, #svg, #white_panel_classes
Constructor Details
Returns a new instance of SingleFileViewerComponent.
6
7
8
9
10
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 6
def initialize(file: nil, field:, resource:)
@file = file
@field = field
@resource = resource
end
|
Instance Method Details
#destroy_path ⇒ Object
12
13
14
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 12
def destroy_path
Avo::Services::URIService.parse(@resource.record_path).append_paths("active_storage_attachments", id, file.id).to_s
end
|
#file ⇒ Object
20
21
22
23
24
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 20
def file
@file || @field.value.attachment
rescue
nil
end
|
#id ⇒ Object
16
17
18
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 16
def id
@field.id
end
|
#is_audio? ⇒ Boolean
32
33
34
35
36
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 32
def is_audio?
file.audio? || @field.is_audio
rescue
false
end
|
#is_image? ⇒ Boolean
26
27
28
29
30
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 26
def is_image?
file.image? || @field.is_image
rescue
false
end
|
#is_video? ⇒ Boolean
38
39
40
41
42
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 38
def is_video?
file.video? || @field.is_video
rescue
false
end
|
#record_persisted? ⇒ Boolean
If model is not persistent blob is automatically destroyed otherwise it can be “lost” on storage
49
50
51
52
53
54
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 49
def record_persisted?
return true if @resource.model.persisted?
ActiveStorage::Blob.destroy(file.blob_id) if file.blob_id.present?
false
end
|
#render? ⇒ Boolean
44
45
46
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 44
def render?
record_persisted?
end
|