Class: Avo::Fields::Common::SingleFileViewerComponent
Instance Method Summary
collapse
#can_delete_file?, #can_download_file?, #can_upload_file?
#a_button, #a_link, #button_classes, #empty_state, #get_model_class, #input_classes, #mount_path, #render_license_warning, #render_license_warnings, #root_path_without_url, #svg, #white_panel_classes
Constructor Details
Returns a new instance of SingleFileViewerComponent.
7
8
9
10
11
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 7
def initialize(field:, resource:, file: nil)
@file = file
@field = field
@resource = resource
end
|
Instance Method Details
#destroy_path ⇒ Object
13
14
15
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 13
def destroy_path
Avo::Services::URIService.parse(@resource.record_path).append_paths("active_storage_attachments", id, file.id).to_s
end
|
#file ⇒ Object
21
22
23
24
25
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 21
def file
@file || @field.value.attachment
rescue
nil
end
|
#id ⇒ Object
17
18
19
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 17
def id
@field.id
end
|
#is_audio? ⇒ Boolean
33
34
35
36
37
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 33
def is_audio?
file.audio? || @field.is_audio
rescue
false
end
|
#is_image? ⇒ Boolean
27
28
29
30
31
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 27
def is_image?
file.image? || @field.is_image
rescue
false
end
|
#is_video? ⇒ Boolean
39
40
41
42
43
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 39
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
50
51
52
53
54
55
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 50
def record_persisted?
return true if @resource.model.persisted?
ActiveStorage::Blob.destroy(file.blob_id) if file.blob_id.present?
false
end
|
#render? ⇒ Boolean
45
46
47
|
# File 'app/components/avo/fields/common/single_file_viewer_component.rb', line 45
def render?
record_persisted?
end
|