Fixes #3309 - No icon / thumbnail for attached files when added via API

This commit is contained in:
Mantas 2020-11-30 18:30:56 +02:00 committed by Thorsten Eckel
parent 03b56b8fc8
commit ad66cd9c1f
3 changed files with 12 additions and 7 deletions

View file

@ -155,6 +155,10 @@ App.ViewHelpers =
return marked(string)
App.i18n.translateContent(string)
ContentOrMimeType: (attachment) ->
types = ['Content-Type', 'content_type', 'Mime-Type', 'mime_type']
_.values(_.pick(attachment?.preferences, types))[0]
ContentTypeIcon: (contentType) ->
contentType = App.Utils.contentTypeCleanup(contentType)
icons =

View file

@ -9,7 +9,7 @@
<div class="attachment-size"><%- @humanFileSize(attachment.size) %></div>
</div>
<% else: %>
<% content_type = attachment.preferences['Content-Type'] || attachment.preferences['content_type'] %>
<% content_type = @ContentOrMimeType(attachment) %>
<a class="attachment attachment--preview" href="<%= attachment.url %>" data-type="attachment"<% if @canDownload(content_type): %> download<% else: %>target="_blank"<% end %>>
<div class="attachment-icon">
<% if attachment.preferences && content_type && @ContentTypeIcon(content_type): %>
@ -28,4 +28,4 @@
<% end %>
<% end %>
</div>
<% end %>
<% end %>

View file

@ -1,13 +1,14 @@
<div class="attachments-block js-attachments">
<div class="attachments-block-headline"><%- @humanTime(@article.created_at) %></div>
<% for attachment in @article.attachments: %>
<a class="attachment attachment--preview" title="<%- attachment.preferences['Content-Type'] %>" target="_blank" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>?disposition=attachment" data-type="attachment"<% if @canDownload(attachment.preferences['Content-Type']): %> download<% end %>>
<% content_type = @ContentOrMimeType(attachment) %>
<a class="attachment attachment--preview" title="<%- content_type %>" target="_blank" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>?disposition=attachment" data-type="attachment"<% if @canDownload(content_type): %> download<% end %>>
<div class="attachment-icon">
<% if attachment.preferences && attachment.preferences['Content-Type'] && @ContentTypeIcon(attachment.preferences['Content-Type']): %>
<% if @canPreview(attachment.preferences['Content-Type']): %>
<% if content_type && @ContentTypeIcon(content_type): %>
<% if @canPreview(content_type): %>
<img src="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>?view=preview">
<% else: %>
<%- @Icon( @ContentTypeIcon(attachment.preferences['Content-Type']) ) %>
<%- @Icon( @ContentTypeIcon(content_type) ) %>
<% end %>
<% else: %>
<%- @Icon('file-unknown') %>
@ -17,4 +18,4 @@
<div class="attachment-size"><%- @humanFileSize(attachment.size) %></div>
</a>
<% end %>
</div>
</div>