From d830f0eb2d7ce1e85c9070b89d32f7c09c0caeae Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 6 Mar 2018 13:52:02 +0100 Subject: [PATCH] UI improvement: Show only real attachments in attachment list. Move original formatted message into footer of article (beside donwload raw message). --- .../ticket_zoom/article_view.coffee | 52 ++++++++++++------- .../sidebar_article_attachments.coffee | 5 +- .../app/models/ticket_article.coffee | 8 +++ .../views/ticket_zoom/article_view.jst.eco | 15 +++--- app/models/channel/email_parser.rb | 2 + 5 files changed, 54 insertions(+), 28 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee index 36ac8f621..e28119972 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee @@ -118,6 +118,26 @@ class ArticleViewItem extends App.ObserverController else @el.removeClass('is-internal') + # check if email link need to be updated + links = clone(article.preferences.links) || [] + if article.type.name is 'email' + link = + name: 'Raw' + url: "#{@Config.get('api_path')}/ticket_article_plain/#{article.id}" + target: '_blank' + links.push link + + # attachments prepare + attachments = App.TicketArticle.contentAttachments(article) + if article.attachments + for attachment in article.attachments + if attachment && attachment.preferences && attachment.preferences['original-format'] is true + link = + url: "#{App.Config.get('api_path')}/ticket_attachment/#{article.ticket_id}/#{article.id}/#{attachment.id}?disposition=attachment" + name: 'Original Formatting' + target: '_blank' + links.push link + # prepare html body if article.content_type is 'text/html' body = article.body @@ -152,36 +172,28 @@ class ArticleViewItem extends App.ObserverController article['html'] = App.Utils.text2html(body) article['html'] = article['html'].replace(signatureDetected, '') - # check if email link need to be updated - if article.type.name is 'email' - if !article.preferences.links - article.preferences.links = [ - { - name: 'Raw' - url: "#{@Config.get('api_path')}/ticket_article_plain/#{article.id}" - target: '_blank' - } - ] - if article.preferences.delivery_message @html App.view('ticket_zoom/article_view_delivery_failed')( - ticket: @ticket - article: article - isCustomer: @permissionCheck('ticket.customer') + ticket: @ticket + article: article + attachments: attachments + links: links ) return if article.sender.name is 'System' #if article.sender.name is 'System' && article.preferences.perform_origin is 'trigger' @html App.view('ticket_zoom/article_view_system')( - ticket: @ticket - article: article - isCustomer: @permissionCheck('ticket.customer') + ticket: @ticket + article: article + attachments: attachments + links: links ) return @html App.view('ticket_zoom/article_view')( - ticket: @ticket - article: article - isCustomer: @permissionCheck('ticket.customer') + ticket: @ticket + article: article + attachments: attachments + links: links ) new App.WidgetAvatar( diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_article_attachments.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_article_attachments.coffee index 1d3ebe037..1dbac63ea 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_article_attachments.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_article_attachments.coffee @@ -19,8 +19,9 @@ class SidebarArticleAttachments extends App.Controller html = '' for ticket_article_id, index in @ticket.article_ids article = App.TicketArticle.find(ticket_article_id) - if article && article.attachments && !_.isEmpty(article.attachments) - html = App.view('ticket_zoom/sidebar_article_attachment')(article: article) + html + attachments = App.TicketArticle.contentAttachments(article) + if !_.isEmpty(attachments) + html = App.view('ticket_zoom/sidebar_article_attachment')(article: article, attachments: attachments) + html @el.html(html) @el.delegate('.js-attachments img', 'click', (e) => @imageView(e) diff --git a/app/assets/javascripts/app/models/ticket_article.coffee b/app/assets/javascripts/app/models/ticket_article.coffee index 6a4230742..604ba4485 100644 --- a/app/assets/javascripts/app/models/ticket_article.coffee +++ b/app/assets/javascripts/app/models/ticket_article.coffee @@ -47,3 +47,11 @@ class App.TicketArticle extends App.Model else if item.type is 'update' return App.i18n.translateContent('%s updated Article for |%s|', item.created_by.displayName(), item.title) return "Unknow action for (#{@objectDisplayName()}/#{item.type}), extend activityMessage() of model." + + @contentAttachments: (article) -> + return [] if !article.attachments + attachments = [] + for attachment in article.attachments + if attachment && (!attachment.preferences || attachment.preferences && attachment.preferences['original-format'] isnt true) + attachments.push attachment + attachments diff --git a/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco index 4eebc79a6..b15af6400 100644 --- a/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco @@ -51,11 +51,11 @@
<%- @T('See more') %>
- <% if !_.isEmpty(@article.attachments): %> + <% if !_.isEmpty(@attachments): %>
<%- @Icon('paperclip') %> -
<%- @article.attachments.length %> <%- @T('Attached Files') %>
- <% for attachment in @article.attachments: %> +
<%- @attachments.length %> <%- @T('Attached Files') %>
+ <% for attachment in @attachments: %> <% if !@C('ui_ticket_zoom_attachments_preview'): %>
<%= attachment.filename %> @@ -93,9 +93,12 @@ diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 6916facbd..0bc69704a 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -180,6 +180,7 @@ class Channel::EmailParser filename = 'message.html' headers_store = { 'content-alternative' => true, + 'original-format' => true, } if mail.mime_type headers_store['Mime-Type'] = mail.html_part.mime_type @@ -225,6 +226,7 @@ class Channel::EmailParser # add body as attachment headers_store = { 'content-alternative' => true, + 'original-format' => true, } if mail.mime_type headers_store['Mime-Type'] = mail.mime_type