FileTree: Show more distinct icons where possible
This commit is contained in:

committed by
Sebastian Serth

parent
1f95324029
commit
ad8743a7d0
@ -7,8 +7,14 @@ class FileType < ApplicationRecord
|
|||||||
include DefaultValues
|
include DefaultValues
|
||||||
|
|
||||||
AUDIO_FILE_EXTENSIONS = %w[.aac .flac .m4a .mp3 .ogg .wav .wma].freeze
|
AUDIO_FILE_EXTENSIONS = %w[.aac .flac .m4a .mp3 .ogg .wav .wma].freeze
|
||||||
|
COMPRESSED_FILE_EXTENSIONS = %w[.7z .bz2 .gz .rar .tar .zip].freeze
|
||||||
|
CSV_FILE_EXTENSIONS = %w[.csv].freeze
|
||||||
|
EXCEL_FILE_EXTENSIONS = %w[.xls .xlsx].freeze
|
||||||
IMAGE_FILE_EXTENSIONS = %w[.bmp .gif .jpeg .jpg .png].freeze
|
IMAGE_FILE_EXTENSIONS = %w[.bmp .gif .jpeg .jpg .png].freeze
|
||||||
|
PDF_FILE_EXTENSIONS = %w[.pdf].freeze
|
||||||
|
POWERPOINT_FILE_EXTENSIONS = %w[.ppt .pptx].freeze
|
||||||
VIDEO_FILE_EXTENSIONS = %w[.avi .flv .mkv .mp4 .m4v .ogv .webm].freeze
|
VIDEO_FILE_EXTENSIONS = %w[.avi .flv .mkv .mp4 .m4v .ogv .webm].freeze
|
||||||
|
WORD_FILE_EXTENSIONS = %w[.doc .docx].freeze
|
||||||
|
|
||||||
after_initialize :set_default_values
|
after_initialize :set_default_values
|
||||||
|
|
||||||
@ -23,7 +29,7 @@ class FileType < ApplicationRecord
|
|||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :renderable, boolean_presence: true
|
validates :renderable, boolean_presence: true
|
||||||
|
|
||||||
%i[audio image video].each do |type|
|
%i[audio compressed csv excel image pdf powerpoint video word].each do |type|
|
||||||
define_method("#{type}?") do
|
define_method("#{type}?") do
|
||||||
self.class.const_get("#{type.upcase}_FILE_EXTENSIONS").include?(file_extension)
|
self.class.const_get("#{type.upcase}_FILE_EXTENSIONS").include?(file_extension)
|
||||||
end
|
end
|
||||||
|
@ -4,16 +4,26 @@ class FileTree
|
|||||||
def file_icon(file)
|
def file_icon(file)
|
||||||
if file.file_type.audio?
|
if file.file_type.audio?
|
||||||
'fa-regular fa-file-audio'
|
'fa-regular fa-file-audio'
|
||||||
|
elsif file.file_type.compressed?
|
||||||
|
'fa-regular fa-file-zipper'
|
||||||
|
elsif file.file_type.excel?
|
||||||
|
'fa-regular fa-file-excel'
|
||||||
elsif file.file_type.image?
|
elsif file.file_type.image?
|
||||||
'fa-regular fa-file-image'
|
'fa-regular fa-file-image'
|
||||||
|
elsif file.file_type.pdf?
|
||||||
|
'fa-regular fa-file-pdf'
|
||||||
|
elsif file.file_type.powerpoint?
|
||||||
|
'fa-regular fa-file-powerpoint'
|
||||||
elsif file.file_type.video?
|
elsif file.file_type.video?
|
||||||
'fa-regular fa-file-video'
|
'fa-regular fa-file-video'
|
||||||
|
elsif file.file_type.word?
|
||||||
|
'fa-regular fa-file-word'
|
||||||
elsif file.read_only?
|
elsif file.read_only?
|
||||||
'fa-solid fa-lock'
|
'fa-solid fa-lock'
|
||||||
elsif file.file_type.executable?
|
elsif file.file_type.executable?
|
||||||
'fa-regular fa-file-code'
|
'fa-regular fa-file-code'
|
||||||
elsif file.file_type.renderable?
|
elsif file.file_type.renderable? || file.file_type.csv?
|
||||||
'fa-regular fa-file-text'
|
'fa-regular fa-file-lines'
|
||||||
else
|
else
|
||||||
'fa-regular fa-file'
|
'fa-regular fa-file'
|
||||||
end
|
end
|
||||||
|
@ -60,7 +60,7 @@ describe FileTree do
|
|||||||
let(:file) { build(:file, file_type: build(:dot_svg)) }
|
let(:file) { build(:file, file_type: build(:dot_svg)) }
|
||||||
|
|
||||||
it 'is a text file icon' do
|
it 'is a text file icon' do
|
||||||
expect(file_icon).to include('fa-file-text')
|
expect(file_icon).to include('fa-file-lines')
|
||||||
expect(file_icon).to include('fa-regular')
|
expect(file_icon).to include('fa-regular')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user