Module: ModelFilesHelper
- Includes:
- MemoWise
- Defined in:
- app/helpers/model_files_helper.rb
Instance Method Summary collapse
- #app_icon_tag(handler) ⇒ Object
- #app_links(file) ⇒ Object
- #app_url(handler, file) ⇒ Object
- #can_print?(file) ⇒ Boolean
- #print_hosts_for(mime_type) ⇒ Object
- #print_links(file) ⇒ Object
- #tab_title(file) ⇒ Object
Instance Method Details
#app_icon_tag(handler) ⇒ Object
59 60 61 62 63 |
# File 'app/helpers/model_files_helper.rb', line 59 def app_icon_tag(handler) handler.icon ? vite_image_tag(handler.icon, class: "app-icon", role: "presentation") : Icon(icon: "window", role: "presentation") end |
#app_links(file) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/model_files_helper.rb', line 35 def app_links(file) handlers = FileHandlers.handlers_for(environment: :client, mime_type: file.mime_type) safe_join( handlers.map do |handler| name = handler.name.demodulize.underscore content_tag(:li, role: "presentation") { link_to safe_join( [ app_icon_tag(handler), t("model_files.download.%{name}" % {name: name}) ].compact, " " ), app_url(handler, file), role: "menuitem", class: "dropdown-item", download: "download" } end ) end |
#app_url(handler, file) ⇒ Object
53 54 55 56 57 |
# File 'app/helpers/model_files_helper.rb', line 53 def app_url(handler, file) signed_id = file.signed_id expires_in: 1.hour, purpose: "download" signed_url = model_model_file_by_signed_filename_url(file.model, file.filename, sig: signed_id) handler.open_url_for(signed_url, client_os: -> { client_os }) end |
#can_print?(file) ⇒ Boolean
4 5 6 |
# File 'app/helpers/model_files_helper.rb', line 4 def can_print?(file) policy(file).print? && print_hosts_for(file.mime_type).any? end |
#print_hosts_for(mime_type) ⇒ Object
8 9 10 |
# File 'app/helpers/model_files_helper.rb', line 8 def print_hosts_for(mime_type) policy_scope(PrintHost).all.select { mime_type.in? it.input_types } end |
#print_links(file) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/model_files_helper.rb', line 13 def print_links(file) safe_join( print_hosts_for(file.mime_type).map do |print_host| content_tag(:li, role: "presentation") { link_to safe_join( [ Icon(icon: "printer", role: "presentation"), t("model_files.print.link", print_host_name: print_host.name) ], " " ), print_print_host_path(print_host, file_id: file.public_id), method: "post", role: "menuitem", class: "dropdown-item", data: { confirm: translate("model_files.print.confirm") } } end ) end |
#tab_title(file) ⇒ Object
65 66 67 68 69 70 |
# File 'app/helpers/model_files_helper.rb', line 65 def tab_title(file) [ file.extension.upcase, (file.presupported ? t("activerecord.attributes.model_file.presupported") : nil) ].compact_blank.join(", ") end |