Add header block for daily email with general information like salutation and number of notifications

pull/9613/head
Henriette Darge 3 years ago
parent 35004d4b35
commit 9086bc3963
  1. 42
      app/helpers/mail_digest_helper.rb
  2. 2
      app/mailers/digest_mailer.rb
  3. 88
      app/views/digest_mailer/work_packages.html.erb
  4. 4
      config/locales/en.yml

@ -31,34 +31,27 @@
module MailDigestHelper
include ::ColorsHelper
def digest_timespan_text
end_time = Time.parse(Setting.notification_email_digest_time)
def digest_timespan_text(notification_count, wp_count)
date = Time.parse(Setting.notification_email_digest_time)
I18n.t(:"mail.digests.time_frame",
start: format_time(end_time - 1.day),
end: format_time(end_time))
time: Setting.notification_email_digest_time,
weekday: day_name(date.wday),
date: ::I18n.l(date.to_date, format: :long),
number_unread: notification_count,
number_work_packages: wp_count)
end
def digest_notification_timestamp_text(notification, html: true, extended_text: false)
journal = notification.journal
user = html ? link_to_user(journal.user, only_path: false) : journal.user.name
if extended_text
raw(I18n.t(:"mail.digests.work_packages.#{journal.initial? ? 'created' : 'updated'}") +
' ' +
I18n.t(:"mail.digests.work_packages.#{journal.initial? ? 'created_at' : 'updated_at'}",
user: user,
timestamp: time_ago_in_words(journal.created_at)))
else
raw(I18n.t(:"mail.digests.work_packages.#{journal.initial? ? 'created_at' : 'updated_at'}",
user: user,
timestamp: time_ago_in_words(journal.created_at)))
end
timestamp_text(user, journal, extended_text)
end
def unique_reasons_of_notifications(notifications)
notifications
.map { |notification| notification.reason_mail_digest }
.map(&:reason_mail_digest)
.uniq
end
@ -75,4 +68,21 @@ module MailDigestHelper
color_id = selected_color(object)
Color.find(color_id).color_styles.map { |k, v| "#{k}:#{v};" }.join(' ')
end
private
def timestamp_text(user, journal, extended)
value = journal.initial? ? "created" : "updated"
if extended
raw(I18n.t(:"mail.digests.work_packages.#{value}") +
' ' +
I18n.t(:"mail.digests.work_packages.#{value}",
user: user,
timestamp: time_ago_in_words(journal.created_at)))
else
raw(I18n.t(:"mail.digests.work_packages.#{value}",
user: user,
timestamp: time_ago_in_words(journal.created_at)))
end
end
end

@ -54,6 +54,8 @@ class DigestMailer < ApplicationMailer
open_project_headers User: recipient.name
message_id nil, recipient
@user = recipient
@notification_ids = notification_ids
@aggregated_notifications = load_notifications(notification_ids)
.sort_by(&:created_at)
.reverse

@ -1,5 +1,27 @@
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid #cccccc; margin-bottom: 30px;">
<tr>
<td style="font-size: 24px; color: #333333; padding-bottom: 10px;">
<%= I18n.t(:'mail.digests.salutation', user: @user.firstname) %>
</td>
</tr>
<tr>
<td style="font-size:14px; color: #1A67A3; font-weight: bold; padding-bottom: 10px;">
<%= digest_timespan_text(@notification_ids.length, @aggregated_notifications.length) %>
</td>
</tr>
<tr>
<td style="padding: 10px 0 25px 0;">
<a href="<%= notifications_center_url %>"
target="_blank"
style="background: #D1E5F5; padding: 8px 12px; color: #1A67A3; border: 1px solid #1A67A3; border-radius: 16px; text-decoration: none;">
<%= I18n.t(:'mail.digests.center') %>
</a>
</td>
</tr>
</table>
<% @aggregated_notifications.each do | work_package, notifications_by_work_package| %>
<a style="border: 1px solid #dadada;
<a style="border: 1px solid #E0E0E0;
margin-bottom: 15px;
padding: 10px;
border-radius: 10px;
@ -49,7 +71,7 @@
<td style="color: <%= type_color(work_package.type) %>;">
<%= work_package.type.to_s.upcase %>
</td>
<td width="100%" style="padding-left: 5px; color: #3a3a3a;">
<td width="100%" style="padding-left: 5px; color: #333333;">
<%= work_package.subject %>
</td>
</tr>
@ -68,65 +90,3 @@
</table>
</a>
<% end %>
<!--
<div style="color: #777; font-weight: bold">
<%#= digest_timespan_text %>
</div>
<%# @notifications_by_project.each do |project, notifications_by_work_package| %>
<section style="margin-bottom: 3em; margin-top: 5em">
<h1 style="font-size: 2em; margin-bottom: 1.5em"><%#= link_to_project(project, only_path: false) %></h1>
<%# notifications_by_work_package.each do |work_package, notifications| %>
<section style="margin-bottom: 3em;">
<h2 style="margin-bottom: 1em; font-size: 1.5em;"><%#= link_to_work_package work_package, status: true, only_path: false, no_hidden: true %></h2>
<%# notifications.sort_by(&:created_at).each do |notification| %>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20px"></td>
<td style="font-weight: normal; font-size: 1.1em;">
<%#= digest_notification_timestamp_text(notification) %>
</td>
<td style="text-align: right">
<%#= I18n.t(
:"mail.digests.work_packages.reason.#{notification.reason_mail_digest || :unknown}",
default: '-') %>
</td>
<td width="20px"></td>
</tr>
</table>
<%# journal = notification.journal %>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20px"></td>
<td>
<%#= format_text(journal.notes,
only_path: false,
object: notification.resource,
project: notification.project) %>
<%# if journal.notes.present? && journal.details.any? %>
<div style="margin-bottom: 2em"></div>
<%# end %>
<ul>
<%# journal.details.each do |detail| %>
<li><%#= journal.render_detail(detail, only_path: false) %></li>
<%# end %>
</ul>
</td>
</tr>
</table>
<div style="margin-bottom: 3em"></div>
<%# end %>
</section>
<%# end %>
</section>
<%# end %>
-->

@ -1967,7 +1967,9 @@ en:
mail:
actions: 'Actions'
digests:
time_frame: 'Summary of all events you subscribed to in the period between %{start} and %{end}'
center: 'Notification center'
time_frame: "At %{time} on %{weekday}, %{date}, you have %{number_unread} unread notifications in %{number_work_packages} work packages"
salutation: 'Hey %{user}!'
work_packages:
created: 'Created'
created_at: 'by %{user} %{timestamp} ago'

Loading…
Cancel
Save