Feature #43797 » 0002-Update-attachments-list-to-show-MIME-type-icons-inst.patch
| app/assets/javascripts/attachments.js | ||
|---|---|---|
|
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');
|
||
| app/helpers/application_helper.rb | ||
|---|---|---|
|
# Options:
|
||
|
# * :text - Link text (default to attachment filename)
|
||
|
# * :download - Force download (default: false)
|
||
|
# * :icon - Sprite icon name or :auto to auto-select icon by the attachment content_type
|
||
|
def link_to_attachment(attachment, options={})
|
||
|
text = options.delete(:text) || attachment.filename
|
||
|
icon = options.delete(:icon)
|
||
|
use_mime_type_icon = (icon == :auto)
|
||
|
if options.delete(:download)
|
||
|
route_method = :download_named_attachment_url
|
||
| ... | ... | |
|
options[:only_path] = true unless options.key?(:only_path)
|
||
|
url = send(route_method, attachment, options)
|
||
|
label = icon ? sprite_icon(icon, text) : text
|
||
|
label = if use_mime_type_icon
|
||
|
mime_type_icon(attachment.content_type, text)
|
||
|
else
|
||
|
icon ? sprite_icon(icon, text) : text
|
||
|
end
|
||
|
link_to label, url, html_options
|
||
|
end
|
||
| app/helpers/icons_helper.rb | ||
|---|---|---|
|
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)
|
||
| app/views/attachments/_form.html.erb | ||
|---|---|---|
|
<span class="attachments_form">
|
||
|
<span class="attachments_icons hidden">
|
||
|
<%= sprite_icon('del', icon_only: true, css_class: 'svg-del') %>
|
||
|
<%= sprite_icon('attachment', icon_only: true, size: 16, css_class: 'svg-attachment') %>
|
||
|
<%= sprite_icon('file', icon_only: true, size: 16, css_class: 'svg-attachment') %>
|
||
|
<%= sprite_icon('loader', icon_only: true, size: 16, css_class: 'svg-loader') %>
|
||
|
<%= sprite_icon('hourglass', icon_only: true, size: 16, css_class: 'svg-hourglass') %>
|
||
|
</span>
|
||
| ... | ... | |
|
<% if saved_attachments.present? %>
|
||
|
<% saved_attachments.each_with_index do |attachment, i| %>
|
||
|
<span id="attachments_p<%= 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' %>
|
||
| app/views/attachments/_links.html.erb | ||
|---|---|---|
|
<% for attachment in attachments %>
|
||
|
<tr>
|
||
|
<td>
|
||
|
<%= link_to_attachment attachment, class: 'icon icon-attachment ', icon: 'attachment' -%>
|
||
|
<%= link_to_attachment attachment, class: 'icon icon-attachment ', icon: :auto -%>
|
||
|
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||
|
<%= link_to_attachment attachment, class: 'icon-only icon-download ', title: l(:button_download), download: true, icon: 'download' -%>
|
||
|
</td>
|
||
| app/views/attachments/edit_all.html.erb | ||
|---|---|---|
|
<% @attachments.each do |attachment| %>
|
||
|
<tr>
|
||
|
<td colspan="2">
|
||
|
<span class="icon icon-attachment"><%= sprite_icon('attachment', attachment.filename_was) %></span>
|
||
|
<span class="icon icon-attachment"><%= mime_type_icon(attachment.content_type_was, attachment.filename_was) %></span>
|
||
|
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||
|
<span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span>
|
||
|
</td>
|
||
| app/views/issues/_edit.html.erb | ||
|---|---|---|
|
<div id="existing-attachments" style="<%= @issue.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">
|
||
|
<% @issue.attachments.each do |attachment| %>
|
||
|
<span class="existing-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 %>
|
||
|
<label>
|
||
|
<%= check_box_tag 'issue[deleted_attachment_ids][]',
|
||
| app/views/wiki/edit.html.erb | ||
|---|---|---|
|
<div id="existing-attachments" style="<%= @page.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">
|
||
|
<% @page.attachments.each do |attachment| %>
|
||
|
<span class="existing-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 %>
|
||
|
<label class='inline'>
|
||
|
<%= check_box_tag 'wiki_page[deleted_attachment_ids][]',
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_show_should_display_attachment_icons_by_mime_type
|
||
|
@request.session[:user_id] = 2
|
||
|
get(:show, :params => {:id => 3})
|
||
|
assert_response :success
|
||
|
assert_select 'div.attachments' do
|
||
|
assert_select 'a.icon-attachment[href=?]', '/attachments/1' do
|
||
|
assert_select "svg.icon-svg use:match('href', ?)", /assets\/icons-\w+.svg#icon--text-plain/
|
||
|
end
|
||
|
assert_select 'a.icon-attachment[href=?]', '/attachments/6' do
|
||
|
assert_select "svg.icon-svg use:match('href', ?)", /assets\/icons-\w+.svg#icon--application-zip/
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_show_should_display_update_form
|
||
|
@request.session[:user_id] = 2
|
||
|
get(:show, :params => {:id => 1})
|
||
| test/helpers/icons_helper_test.rb | ||
|---|---|---|
|
assert_match expected, activity_event_type_icon('time-entry')
|
||
|
end
|
||
|
def test_mime_type_icon_should_return_specific_icon_for_known_mime_types
|
||
|
expected = %r{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--text-plain"></use></svg>}
|
||
|
assert_match expected, mime_type_icon('text/plain')
|
||
|
end
|
||
|
def test_mime_type_icon_should_return_generic_file_icon_for_unknown_mime_types
|
||
|
expected = %r{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--file"></use></svg>}
|
||
|
assert_match expected, mime_type_icon('unknown-type/unknown-subtype')
|
||
|
end
|
||
|
def test_icon_for_mime_type_should_return_specific_icon_for_known_mime_types
|
||
|
assert_equal 'text-plain', icon_for_mime_type('text/plain')
|
||
|
assert_equal 'application-pdf', icon_for_mime_type('application/pdf')
|
||