From 0c8acfb5b610b2190ac7a944db1b195cb3a248af 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/application_helper.rb | 1 + app/helpers/icons_helper.rb | 5 +++++ 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 ++++++++++ 10 files changed, 38 insertions(+), 7 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/application_helper.rb b/app/helpers/application_helper.rb index 009f148ea..c04a97e4d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -126,6 +126,7 @@ module ApplicationHelper # Options: # * :text - Link text (default to attachment filename) # * :download - Force download (default: false) + # * :icon - Sprite icon name def link_to_attachment(attachment, options={}) text = options.delete(:text) || attachment.filename icon = options.delete(:icon) diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 3940896b5..bcd887be1 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -90,6 +90,11 @@ 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 + private def svg_sprite_icon(icon_name, size: DEFAULT_ICON_SIZE, style: :outline, sprite: DEFAULT_SPRITE, css_class: nil, rtl: false) 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 %>