2016-10-04 18:34:43 +08:00
|
|
|
module FileIconsHelper
|
|
|
|
def wopi_file?(asset)
|
2019-07-02 05:30:20 +08:00
|
|
|
file_ext = asset.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
|
|
|
def file_fa_icon_class(asset)
|
2019-07-02 05:30:20 +08:00
|
|
|
file_ext = asset.file_name.split('.').last
|
2019-04-26 14:58:01 +08:00
|
|
|
|
|
|
|
if Extends::FILE_FA_ICON_MAPPINGS[file_ext] # Check for custom mappings or possible overrides
|
|
|
|
return Extends::FILE_FA_ICON_MAPPINGS[file_ext]
|
|
|
|
elsif Constants::FILE_TEXT_FORMATS.include?(file_ext)
|
|
|
|
return 'fa-file-word'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_TABLE_FORMATS.include?(file_ext)
|
2019-04-26 14:58:01 +08:00
|
|
|
return 'fa-file-excel'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_PRESENTATION_FORMATS.include?(file_ext)
|
2019-04-26 14:58:01 +08:00
|
|
|
return 'fa-file-powerpoint'
|
2018-04-13 15:43:14 +08:00
|
|
|
elsif %w(pdf).include?(file_ext)
|
2019-04-26 14:58:01 +08:00
|
|
|
return 'fa-file-pdf'
|
2018-04-13 15:43:14 +08:00
|
|
|
elsif %w(txt csv tab tex).include?(file_ext)
|
2019-04-23 17:13:16 +08:00
|
|
|
return 'fa-file-alt'
|
|
|
|
elsif Constants::WHITELISTED_IMAGE_TYPES.include?(file_ext)
|
|
|
|
return 'fa-image'
|
|
|
|
else
|
|
|
|
return 'fa-paperclip'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-04 18:34:43 +08:00
|
|
|
# For showing next to file
|
|
|
|
def file_extension_icon(asset)
|
2019-07-02 05:30:20 +08:00
|
|
|
file_ext = asset.file_name.split('.').last
|
2019-01-01 01:10:12 +08:00
|
|
|
if Constants::FILE_TEXT_FORMATS.include?(file_ext)
|
2016-10-04 18:34:43 +08:00
|
|
|
image_link = 'office/Word-docx_20x20x32.png'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_TABLE_FORMATS.include?(file_ext)
|
2016-10-04 18:34:43 +08:00
|
|
|
image_link = 'office/Excel-xlsx_20x20x32.png'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_PRESENTATION_FORMATS.include?(file_ext)
|
2016-10-04 18:34:43 +08:00
|
|
|
image_link = 'office/PowerPoint-pptx_20x20x32.png'
|
|
|
|
end
|
|
|
|
|
2018-02-26 21:23:02 +08:00
|
|
|
# Now check for custom mappings or possible overrides
|
2019-07-02 05:30:20 +08:00
|
|
|
image_link = Extends::FILE_ICON_MAPPINGS[file_ext] if Extends::FILE_ICON_MAPPINGS[file_ext]
|
2018-02-26 21:23:02 +08:00
|
|
|
|
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)
|
2019-07-09 16:28:15 +08:00
|
|
|
file_ext = asset.file_name.split('.').last
|
2019-01-01 01:10:12 +08:00
|
|
|
if Constants::FILE_TEXT_FORMATS.include?(file_ext)
|
2016-10-04 18:34:43 +08:00
|
|
|
image_link = 'office/Word-color_16x16x32.png'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_TABLE_FORMATS.include?(file_ext)
|
2016-10-04 18:34:43 +08:00
|
|
|
image_link = 'office/Excel-color_16x16x32.png'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_PRESENTATION_FORMATS.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)
|
2019-07-09 16:28:15 +08:00
|
|
|
file_ext = asset.file_name.split('.').last
|
2019-01-01 01:10:12 +08:00
|
|
|
if Constants::FILE_TEXT_FORMATS.include?(file_ext)
|
2016-10-04 18:34:43 +08:00
|
|
|
app = 'Word Online'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_TABLE_FORMATS.include?(file_ext)
|
2016-10-04 18:34:43 +08:00
|
|
|
app = 'Excel Online'
|
2019-01-01 01:10:12 +08:00
|
|
|
elsif Constants::FILE_PRESENTATION_FORMATS.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
|
2019-03-18 02:23:17 +08:00
|
|
|
|
|
|
|
# Returns correct content type for given extension
|
|
|
|
def wopi_content_type(extension)
|
|
|
|
case extension
|
|
|
|
when 'docx'
|
|
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
|
|
when 'xlsx'
|
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
|
when 'pptx'
|
|
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
|
|
|
end
|
|
|
|
end
|
2016-10-04 18:34:43 +08:00
|
|
|
end
|