OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Highligh overdue notification in email digest
Dombi Attila41393e9f0252
diff --git a/app/helpers/mail_digest_helper.rb b/app/helpers/mail_digest_helper.rbindex 8a60ed13766..158c9fa8c26 100644--- a/app/helpers/mail_digest_helper.rb+++ b/app/helpers/mail_digest_helper.rb@@ -42,53 +42,14 @@ module MailDigestHelpersummaryend- def date_alerts_text(notification)- work_package = notification.resource- date_value = date_value(notification, work_package)-- alert_text = if date_value- date_is_past = date_value.before?(Time.zone.today)- is_overdue = date_is_past && (notification.reason == "date_alert_due_date" || work_package.milestone?)- days_diff = (date_value - Time.zone.today).to_i.abs-- build_alert_text(days_diff, is_overdue, date_is_past)- else- I18n.t('js.notifications.date_alerts.property_is_deleted')- end-- "#{property_text(notification, is_overdue, days_diff)} #{alert_text}"- end-- def date_value(notification, work_package)- notification.reason == "date_alert_start_date" ? work_package.start_date : work_package.due_date- end-- def property_text(notification, is_overdue, days_diff)- if is_overdue && days_diff > 0- I18n.t('js.notifications.date_alerts.overdue')- else- property_text_helper(notification)- end- end+ def date_alerts_text(notification, html: true)+ date_value = date_value(notification)+ is_past, is_overdue, days_diff = text_modifiers_for(notification, date_value)- def build_alert_text(days_diff, is_overdue, date_is_past)- days_text = I18n.t('js.units.day', count: days_diff)-- return I18n.t('js.notifications.date_alerts.property_today') if days_diff == 0- return I18n.t('js.notifications.date_alerts.overdue_since', difference_in_days: days_text) if is_overdue- return I18n.t('js.notifications.date_alerts.property_was', difference_in_days: days_text) if date_is_past+ alert_text = build_alert_text(date_value, is_past, is_overdue, days_diff)+ property_text = build_property_text(notification, is_overdue, days_diff)- I18n.t('js.notifications.date_alerts.property_is', difference_in_days: days_text)- end-- def property_text_helper(notification)- return I18n.t('js.notifications.date_alerts.milestone_date') if notification.resource.milestone?-- if notification.reason == "date_alert_start_date"- I18n.t('js.work_packages.properties.startDate')- else- I18n.t('js.work_packages.properties.dueDate')- end+ highlight_overdue("#{property_text} #{alert_text}", is_overdue, html)enddef digest_notification_timestamp_text(notification, html: true)@@ -123,4 +84,43 @@ module MailDigestHelperdef number_of_authors(notifications)notifications.group_by { |n| n[:actor_id] }.countend++ def date_value(notification)+ work_package = notification.resource+ notification.reason == "date_alert_start_date" ? work_package.start_date : work_package.due_date+ end++ def text_modifiers_for(notification, value)+ return unless value++ is_past = value.before?(Time.zone.today)+ is_overdue = is_past && notification.reason == "date_alert_due_date"+ difference_in_days = (value - Time.zone.today).to_i.abs+ [is_past, is_overdue, difference_in_days]+ end++ def build_property_text(notification, is_overdue, days_diff)+ return I18n.t('js.notifications.date_alerts.overdue') if is_overdue && days_diff > 0+ return I18n.t('js.notifications.date_alerts.milestone_date') if notification.resource.milestone?+ return I18n.t('js.work_packages.properties.startDate') if notification.reason == "date_alert_start_date"++ I18n.t('js.work_packages.properties.dueDate')+ end++ def build_alert_text(date_value, is_past, is_overdue, days_diff)+ return I18n.t('js.notifications.date_alerts.property_is_deleted') unless date_value+ return I18n.t('js.notifications.date_alerts.property_today') if days_diff == 0++ days_text = I18n.t('js.units.day', count: days_diff)+ return I18n.t('js.notifications.date_alerts.overdue_since', difference_in_days: days_text) if is_overdue+ return I18n.t('js.notifications.date_alerts.property_was', difference_in_days: days_text) if is_past++ I18n.t('js.notifications.date_alerts.property_is', difference_in_days: days_text)+ end++ def highlight_overdue(text, is_overdue, html)+ return text unless html && is_overdue++ content_tag :span, text, style: 'color: #C92A2A'+ endenddiff --git a/app/views/digest_mailer/work_packages.text.erb b/app/views/digest_mailer/work_packages.text.erbindex 7260b50ac0e..8ea6769d5c8 100644--- a/app/views/digest_mailer/work_packages.text.erb+++ b/app/views/digest_mailer/work_packages.text.erb@@ -10,7 +10,7 @@<% unique_reasons = unique_reasons_of_notifications(notifications_by_work_package) %><% unique_reasons.each_with_index do |reason, index| %><%= I18n.t(:"mail.work_packages.reason.#{reason || :unknown}", default: '-') %><%= ', ' unless unique_reasons.size-1 == index %><% end %>: <% if notifications_by_work_package.first.date_alert? %>- <%= date_alerts_text(notifications_by_work_package.first) %>+ <%= date_alerts_text(notifications_by_work_package.first, html: false) %><% else %><%= digest_notification_timestamp_text(notifications_by_work_package.first, html: false) %><% end %>diff --git a/spec/mailers/digest_mailer_spec.rb b/spec/mailers/digest_mailer_spec.rbindex aaa5045b380..35229bc1089 100644--- a/spec/mailers/digest_mailer_spec.rb+++ b/spec/mailers/digest_mailer_spec.rb@@ -132,7 +132,6 @@ describe DigestMailer doenddescribe "#date_alerts_text" do- let!(:color) { create(:color) }let!(:project1) { create(:project) }let!(:recipient) { create(:user) }let(:notifications) { [notification] }@@ -219,7 +218,7 @@ describe DigestMailer doendit 'matches generated text' do- expect(mail_body).to have_text('Overdue since 2 days')+ expect(mail_body).to include('<span style="color: #C92A2A">Overdue since 2 days</span>')endend