Module: UploadsHelper
- Defined in:
- app/helpers/uploads_helper.rb
Overview
== Schema Information
Table name: uploads
id :integer not null, primary key
category :string(255)
resource_id :integer
resource_type :string(255)
note :text
created_at :datetime
updated_at :datetime
reference_number :string(255)
attachment_content_type :string(255)
attachment_file_name :string(255)
attachment_file_size :integer
attachment_updated_at :datetime
type :string(30)
attachment_processing :boolean
attachment_uid :string
attachment_name :string
attachment_size :integer
Instance Method Summary collapse
-
#fancybox_type_for_upload(upload) ⇒ Object
Determine the correct Fancybox type based on file mime type Returns 'image' for image files, 'pdf' for PDFs, 'iframe' for everything else Uses the stored attachment_mime_type column to avoid HTTP calls to storage.
- #render_item_links(items, context_object) ⇒ Object
- #smart_communication_link(upload, return_path = nil) ⇒ Object
- #upload_actions(upload, _default_link_options = {}) ⇒ Object
- #upload_thumbnail(upload, dimensions: '300x300#') ⇒ Object
Instance Method Details
#fancybox_type_for_upload(upload) ⇒ Object
Determine the correct Fancybox type based on file mime type
Returns 'image' for image files, 'pdf' for PDFs, 'iframe' for everything else
Uses the stored attachment_mime_type column to avoid HTTP calls to storage
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/uploads_helper.rb', line 42 def fancybox_type_for_upload(upload) return 'iframe' unless upload # Use the database column instead of upload.attachment.mime_type # to avoid HTTP calls to remote storage (S3/Wasabi) mime_type = upload. return 'iframe' unless mime_type if mime_type.start_with?('image/') 'image' elsif mime_type == 'application/pdf' 'pdf' else 'iframe' end end |
#render_item_links(items, context_object) ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/helpers/uploads_helper.rb', line 59 def render_item_links(items, context_object) links = items.map do |item| label = item == context_object ? content_tag(:strong, item.sku) : item.sku link_to(label, item_path(item)) end safe_join(links, ', ') end |
#smart_communication_link(upload, return_path = nil) ⇒ Object
25 26 27 28 29 |
# File 'app/helpers/uploads_helper.rb', line 25 def smart_communication_link(upload, return_path = nil) = { upload_id: upload.id, resource: upload.resource, current_user: current_user } com_params = CommunicationBuilder.new().to_params new_communication_path(com_params.merge({ return_path: return_path })) end |
#upload_actions(upload, _default_link_options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/uploads_helper.rb', line 67 def upload_actions(upload, = {}) actions = [] actions << link_to(fa_icon('file', text: 'View'), upload..url, target: '_blank', rel: 'noopener') actions << link_to(fa_icon('envelope', text: 'Send'), smart_communication_link(upload, request.fullpath)) if can?(:update, upload) && upload.persisted? actions << link_to(fa_icon('pen-to-square', text: 'Edit'), edit_upload_path(upload, return_path: request.fullpath)) actions << link_to(fa_icon('download', text: 'Download'), download_upload_path(upload)) end actions << link_to(fa_icon('trash', text: 'Delete'), upload_path(upload, return_path: request.fullpath), data: { turbo_method: :delete, turbo_confirm: 'Are you sure you want to delete this attachment?' }) if can?(:destroy, upload) actions << link_to(fa_icon('eye', text: 'Audit Trail'), upload_audit_trails_path(upload)) end |
#upload_thumbnail(upload, dimensions: '300x300#') ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/helpers/uploads_helper.rb', line 31 def upload_thumbnail(upload, dimensions: '300x300#') if (turl = upload.thumbnail_url(dimensions: dimensions)) image_tag(turl, class: 'card-img-top') else fa_icon('paperclip', text: upload.) end end |