scinote-web/app/helpers/file_icons_helper.rb

90 lines
2.9 KiB
Ruby
Raw Normal View History

2016-10-04 18:34:43 +08:00
module FileIconsHelper
def wopi_file?(asset)
file_ext = asset.file_file_name.split('.').last
%w(csv ods xls xlsb xlsm xlsx odp pot potm potx pps ppsm ppsx ppt pptm pptx doc docm docx dot dotm dotx odt rtf).include?(file_ext)
2016-10-04 18:34:43 +08:00
end
2018-03-30 17:50:28 +08:00
# For showing next to file
def file_fa_icon_class(asset)
file_ext = asset.file_file_name.split('.').last
if %w(doc docm docx dot dotm dotx odt rtf).include?(file_ext)
fa_class = 'fa-file-word'
elsif %w(ods xls xlsb xlsm xlsx).include?(file_ext)
2018-03-30 17:50:28 +08:00
fa_class = 'fa-file-excel'
elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext)
fa_class = 'fa-file-powerpoint'
elsif %w(pdf).include?(file_ext)
fa_class = 'fa-file-pdf'
elsif %w(txt csv tab tex).include?(file_ext)
fa_class = 'fa-file-alt'
2018-03-30 17:50:28 +08:00
end
# Now check for custom mappings or possible overrides
if Extends::FILE_ICON_MAPPINGS[file_ext]
fa_class = Extends::FILE_FA_ICON_MAPPINGS[file_ext]
end
fa_class = 'fa-file' if fa_class.blank?
fa_class
end
2016-10-04 18:34:43 +08:00
# For showing next to file
def file_extension_icon(asset)
file_ext = asset.file_file_name.split('.').last
if %w(doc docm docx dot dotm dotx odt rtf).include?(file_ext)
2016-10-04 18:34:43 +08:00
image_link = 'office/Word-docx_20x20x32.png'
elsif %w(csv ods xls xlsb xlsm xlsx).include?(file_ext)
2016-10-04 18:34:43 +08:00
image_link = 'office/Excel-xlsx_20x20x32.png'
elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext)
2016-10-04 18:34:43 +08:00
image_link = 'office/PowerPoint-pptx_20x20x32.png'
end
# Now check for custom mappings or possible overrides
if Extends::FILE_ICON_MAPPINGS[file_ext]
image_link = Extends::FILE_ICON_MAPPINGS[file_ext]
end
2016-10-04 18:34:43 +08:00
if image_link
image_tag image_link
else
''
end
end
# For showing in view/edit buttons (WOPI)
def file_application_icon(asset)
file_ext = asset.file_file_name.split('.').last
if %w(doc docm docx dot dotm dotx odt rtf).include?(file_ext)
2016-10-04 18:34:43 +08:00
image_link = 'office/Word-color_16x16x32.png'
elsif %w(csv ods xls xlsb xlsm xlsx).include?(file_ext)
2016-10-04 18:34:43 +08:00
image_link = 'office/Excel-color_16x16x32.png'
elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext)
2016-10-04 18:34:43 +08:00
image_link = 'office/PowerPoint-Color_16x16x32.png'
end
if image_link
image_tag image_link
else
''
end
end
# Shows correct WOPI application text (Word Online/Excel ..)
def wopi_button_text(asset, action)
file_ext = asset.file_file_name.split('.').last
if %w(doc docm docx dot dotm dotx odt rtf).include?(file_ext)
2016-10-04 18:34:43 +08:00
app = 'Word Online'
elsif %w(csv ods xls xlsb xlsm xlsx).include?(file_ext)
2016-10-04 18:34:43 +08:00
app = 'Excel Online'
elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext)
2016-10-04 18:34:43 +08:00
app = 'PowerPoint Online'
end
if action == 'view'
t('result_assets.wopi_open_file', app: app)
elsif action == 'edit'
t('result_assets.wopi_edit_file', app: app)
end
end
end