Show symbols for different file types.

This commit is contained in:
Jan Böhmer 2019-08-10 19:04:47 +02:00
parent 6551d3a56b
commit 87db2523e1
2 changed files with 41 additions and 6 deletions

View file

@ -1,3 +1,5 @@
{% import "helper.twig" as helper %}
<table class="table table-striped table-hover">
<thead>
<tr>
@ -13,15 +15,10 @@
<tbody>
{% for attachment in part.attachments %}
<tr>
<td>
{% if attachment_helper.fileExisting(attachment) %}
<i class="fas fa-file fa-3x"></i>
{% else %}
<i class="fas fa-exclamation-triangle fa-3x text-danger"></i>
{% endif %}
{{ helper.attachment_icon(attachment, attachment_helper) }}
</td>
<td class="align-middle">{{ attachment.name }}</td>
<td class="align-middle">{{ attachment.type.fullPath }}</td>

View file

@ -4,4 +4,42 @@
{% else %}
{% trans %}bool.false{% endtrans %}
{% endif %}
{% endmacro %}
{% macro file_extension_to_fa_icon(ext) %}
{% if ext in ['jpeg', 'jpg', 'gif', 'png', 'tiff', 'tif', 'webp', 'bmp', 'svg'] %} {# Images #}
fa-file-image
{% elseif ext in ['pdf'] %} {# PDFs #}
fa-file-pdf
{% elseif ext in ['txt', 'md', 'rtf'] %} {# Text files #}
fa-file-alt
{% elseif ext in ['csv'] %} {# CSV files #}
fa-file-csv
{% elseif ext in ['doc', 'docx', 'odt'] %} {# Documents #}
fa-file-word
{% elseif ext in ['zip', 'rar', 'bz2', 'tar', '7z', 'gz'] %}
fa-file-archive
{% elseif ext in ['mp3', 'wav', 'aac', 'm4a', 'wma'] %}
fa-file-audio
{% elseif ext in ['ppt', 'pptx', 'odp'] %}
fa-file-powerpoint
{% elseif ext in ['xls', 'xlsx', 'ods'] %}
fa-file-excel
{% elseif ext in ['php', 'xml', 'html', 'js', 'ts', 'htm', 'c', 'cpp'] %}
fa-file-code
{% elseif ext in ['webm', 'avi', 'mp4', 'mkv', 'wmv'] %} {# Videos#}
fa-file-video
{% else %}
fa-file
{% endif %}
{% endmacro %}
{% macro attachment_icon(attachment, attachment_helper, class = "fa-fw fas fa-3x", link = true) %}
{% if not attachment_helper or attachment_helper.fileExisting(attachment) %}
<a target="_blank" data-no-ajax href="{% if link %}{{ attachment|entityURL('file_view') }}{% endif %}">
<i class="text-dark {{ class }} {{ _self.file_extension_to_fa_icon(attachment.extension) }}"></i>
</a>
{% elseif not attachment_helper.fileExisting(attachment) %}
<i class="{{ class }} fa-exclamation-triangle text-danger"></i>
{% endif %}
{% endmacro %}