From fcd958b992d3c200f5fa4c93a86266d129acbbe7 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Fri, 6 Feb 2026 13:06:38 +0900 Subject: [PATCH 2/2] Update attachments list to show MIME type icons instead of clip icons --- app/assets/javascripts/attachments.js | 2 +- app/helpers/icons_helper.rb | 27 ++++++++++++++--------- app/views/attachments/_form.html.erb | 4 ++-- app/views/attachments/_links.html.erb | 2 +- app/views/attachments/edit_all.html.erb | 2 +- app/views/issues/_edit.html.erb | 2 +- app/views/wiki/edit.html.erb | 2 +- test/functional/issues_controller_test.rb | 15 +++++++++++++ test/helpers/icons_helper_test.rb | 10 +++++++++ 9 files changed, 48 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/attachments.js b/app/assets/javascripts/attachments.js index ef04b4315..b710af8b0 100644 --- a/app/assets/javascripts/attachments.js +++ b/app/assets/javascripts/attachments.js @@ -80,7 +80,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) { ajaxUpload.uploading--; fileSpan.removeClass('ajax-loading'); attachmentIcon.removeClass('svg-loader'); - updateSVGIcon(attachmentIcon[0], 'attachment'); + updateSVGIcon(attachmentIcon[0], 'file'); var form = fileSpan.parents('form'); if (form.queue('upload').length == 0 && ajaxUpload.uploading == 0) { $('input:submit', form).removeAttr('disabled'); diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 3940896b5..5a7e12c1e 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -90,6 +90,22 @@ module IconsHelper sprite_icon(icon_name, **) end + def mime_type_icon(mime_type, ...) + icon_name = icon_for_mime_type(mime_type) + sprite_icon(icon_name, ...) + end + + 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('/', '-') + else + "file" + end + end + private def svg_sprite_icon(icon_name, size: DEFAULT_ICON_SIZE, style: :outline, sprite: DEFAULT_SPRITE, css_class: nil, rtl: false) @@ -107,15 +123,4 @@ module IconsHelper } ) end - - 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('/', '-') - else - "file" - end - end end diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index 11c3ebf76..ae55d7576 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -9,7 +9,7 @@ @@ -17,7 +17,7 @@ <% if saved_attachments.present? %> <% saved_attachments.each_with_index do |attachment, i| %> - <%= sprite_icon('attachment', icon_only: true, size: 16, css_class: 'svg-attachment') %> + <%= sprite_icon('file', icon_only: true, size: 16, css_class: 'svg-attachment') %> <%= text_field_tag("#{attachment_param}[p#{i}][filename]", attachment.filename, :class => 'filename') %> <% if attachment.container_id.present? %> <%= link_to sprite_icon('del', l(:button_delete), icon_only: true), "#", :onclick => "$(this).closest('.attachments_form').find('.add_attachment').show(); $(this).parent().remove(); return false;", :class => 'icon-only icon-del' %> diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 93cbddaea..d2341a4a9 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -15,7 +15,7 @@ <% for attachment in attachments %> - <%= link_to_attachment attachment, class: 'icon icon-attachment ', icon: 'attachment' -%> + <%= link_to_attachment attachment, class: 'icon icon-attachment ', icon: icon_for_mime_type(attachment.content_type) -%> (<%= number_to_human_size attachment.filesize %>) <%= link_to_attachment attachment, class: 'icon-only icon-download ', title: l(:button_download), download: true, icon: 'download' -%> diff --git a/app/views/attachments/edit_all.html.erb b/app/views/attachments/edit_all.html.erb index 749b53dbb..15b46c5e0 100644 --- a/app/views/attachments/edit_all.html.erb +++ b/app/views/attachments/edit_all.html.erb @@ -11,7 +11,7 @@ <% @attachments.each do |attachment| %> - <%= sprite_icon('attachment', attachment.filename_was) %> + <%= mime_type_icon(attachment.content_type_was, attachment.filename_was) %> (<%= number_to_human_size attachment.filesize %>) <%= attachment.author %>, <%= format_time(attachment.created_on) %> diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb index a1839636d..78155c9b8 100644 --- a/app/views/issues/_edit.html.erb +++ b/app/views/issues/_edit.html.erb @@ -54,7 +54,7 @@
<% @issue.attachments.each do |attachment| %> - <%= sprite_icon('attachment', size: 12) %> + <%= mime_type_icon(attachment.content_type, size: 12) %> <%= text_field_tag '', attachment.filename, :class => "icon icon-attachment filename", :disabled => true %>