From 87db2523e12d7aa4a5e1f86a86c47d3d323c4964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 10 Aug 2019 19:04:47 +0200 Subject: [PATCH] Show symbols for different file types. --- .../Parts/info/_attachments_info.html.twig | 9 ++--- templates/helper.twig | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/templates/Parts/info/_attachments_info.html.twig b/templates/Parts/info/_attachments_info.html.twig index 6c49cb63..a4e4fc92 100644 --- a/templates/Parts/info/_attachments_info.html.twig +++ b/templates/Parts/info/_attachments_info.html.twig @@ -1,3 +1,5 @@ +{% import "helper.twig" as helper %} + @@ -13,15 +15,10 @@ - {% for attachment in part.attachments %} diff --git a/templates/helper.twig b/templates/helper.twig index dfb49c7a..8b2066e2 100644 --- a/templates/helper.twig +++ b/templates/helper.twig @@ -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) %} + + + + {% elseif not attachment_helper.fileExisting(attachment) %} + + {% endif %} {% endmacro %} \ No newline at end of file
- {% if attachment_helper.fileExisting(attachment) %} - - {% else %} - - {% endif %} + {{ helper.attachment_icon(attachment, attachment_helper) }} {{ attachment.name }} {{ attachment.type.fullPath }}