From 7d2af5313dc884d7a0479f198d5e08cb00550663 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Mon, 9 Feb 2026 13:21:05 +0900 Subject: [PATCH 1/2] Add file-type icons for audio, image, and video media types --- app/assets/images/icons.svg | 44 +++++++++++++++---------------- app/helpers/icons_helper.rb | 12 ++++++--- config/icon_source.yml | 14 +++++----- test/helpers/icons_helper_test.rb | 9 +++++++ 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/app/assets/images/icons.svg b/app/assets/images/icons.svg index a1c94656c..b209a135e 100644 --- a/app/assets/images/icons.svg +++ b/app/assets/images/icons.svg @@ -215,6 +215,12 @@ + + + + + + @@ -244,28 +250,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -339,6 +323,16 @@ + + + + + + + + + + @@ -352,6 +346,12 @@ + + + + + + diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index bcd887be1..5558bdb2a 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -116,11 +116,17 @@ module IconsHelper def icon_for_mime_type(mime) if %w(text/plain text/x-c text/x-csharp text/x-java text/x-php text/x-ruby text/xml text/css text/html text/css text/html - image/gif image/jpeg image/png image/tiff application/pdf application/zip application/gzip application/javascript).include?(mime) - mime.tr('/', '-') + icon_name = mime.tr('/', '-') else - "file" + top_level_type, subtype = mime.to_s.split('/') + icon_name = + case top_level_type # rubocop:disable Style/HashLikeCase + when 'audio' then 'file-music' + when 'image' then 'photo' + when 'video' then 'movie' + end end + icon_name || 'file' end end diff --git a/config/icon_source.yml b/config/icon_source.yml index d5c540e85..98fe995ab 100644 --- a/config/icon_source.yml +++ b/config/icon_source.yml @@ -185,14 +185,6 @@ svg: file-type-css - name: text-html svg: file-type-html -- name: image-gif - svg: file -- name: image-jpeg - svg: file-type-jpg -- name: image-png - svg: file-type-png -- name: image-tiff - svg: file - name: application-javascript svg: file-type-js - name: application-pdf @@ -252,3 +244,9 @@ svg: arrow-narrow-left - name: arrow-narrow-right svg: arrow-narrow-right +- name: photo + svg: photo +- name: movie + svg: movie +- name: file-music + svg: file-music diff --git a/test/helpers/icons_helper_test.rb b/test/helpers/icons_helper_test.rb index 7c66b5a2f..329cc7618 100644 --- a/test/helpers/icons_helper_test.rb +++ b/test/helpers/icons_helper_test.rb @@ -139,6 +139,15 @@ class IconsHelperTest < Redmine::HelperTest assert_equal 'application-pdf', icon_for_mime_type('application/pdf') end + def test_icon_for_mime_type_should_return_icon_for_top_level_types + assert_equal 'file-music', icon_for_mime_type('audio/aac') + assert_equal 'file-music', icon_for_mime_type('audio/mpeg') + assert_equal 'photo', icon_for_mime_type('image/jpeg') + assert_equal 'photo', icon_for_mime_type('image/png') + assert_equal 'movie', icon_for_mime_type('video/raw') + assert_equal 'movie', icon_for_mime_type('video/mp4') + end + def test_icon_for_mime_type_should_return_generic_file_icon_for_unknown_mime_types assert_equal 'file', icon_for_mime_type('unknown-type') end -- 2.50.1