Skip to content

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

Fix text if date is today

Oliver Günther335c30bd4d91
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 3c3c50b9776..c9f16912a00 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -595,6 +595,7 @@ en:
milestone_date: 'Milestone date'
overdue: 'Overdue'
overdue_since: 'since %{difference_in_days}'
+ property_today: 'is today'
property_is: 'is in %{difference_in_days}'
property_was: 'was %{difference_in_days} ago'
property_is_deleted: 'is deleted'
diff --git a/frontend/src/app/features/in-app-notifications/entry/actors-line/in-app-notification-actors-line.component.ts b/frontend/src/app/features/in-app-notifications/entry/actors-line/in-app-notification-actors-line.component.ts
index e3bef1d92f2..eadfcc365f5 100644
--- a/frontend/src/app/features/in-app-notifications/entry/actors-line/in-app-notification-actors-line.component.ts
+++ b/frontend/src/app/features/in-app-notifications/entry/actors-line/in-app-notification-actors-line.component.ts
@@ -70,9 +70,9 @@ export class InAppNotificationActorsLineComponent implements OnInit {
text_for_additional_authors(number:number):string {
if (number === 1) {
return this.text.and_other_singular;
- } else {
- return this.text.and_other_plural(number);
}
+
+ return this.text.and_other_plural(number);
}
private buildTime() {
diff --git a/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.ts b/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.ts
index acdde40d1ec..877f2b592be 100644
--- a/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.ts
+++ b/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.ts
@@ -35,8 +35,6 @@ export class InAppNotificationDateAlertComponent implements OnInit {
propertyText:string;
- private daysDiff:string;
-
text = {
work_package_is: this.I18n.t('js.notifications.date_alerts.work_package_is'),
overdue: this.I18n.t('js.notifications.date_alerts.overdue'),
@@ -50,6 +48,7 @@ export class InAppNotificationDateAlertComponent implements OnInit {
startDate: this.I18n.t('js.work_packages.properties.startDate'),
dueDate: this.I18n.t('js.work_packages.properties.dueDate'),
date: this.I18n.t('js.notifications.date_alerts.milestone_date'),
+ due_today: this.I18n.t('js.notifications.date_alerts.property_today'),
};
constructor(
@@ -73,31 +72,35 @@ export class InAppNotificationDateAlertComponent implements OnInit {
}
private deriveDueDate(value:string, property:'startDate'|'dueDate'|'date') {
- const dateValue = this.timezoneService.parseISODate(value);
- this.dateIsPast = dateValue.isBefore();
+ const dateValue = this.timezoneService.parseISODate(value).startOf('day');
+ const today = moment();
+ this.dateIsPast = dateValue.isBefore(today, 'day');
this.isOverdue = this.dateIsPast && ['date', 'dueDate'].includes(property);
- this.daysDiff = this.dateDiff(dateValue);
- this.propertyText = this.isOverdue ? this.text.overdue : this.text[property];
- this.alertText = this.buildAlertText();
+ const diff = this.dateDiff(dateValue);
+ this.propertyText = (this.isOverdue && diff > 0) ? this.text.overdue : this.text[property];
+ this.alertText = this.buildAlertText(diff);
}
- private buildAlertText():string {
+ private buildAlertText(daysDiff:number):string {
+ if (daysDiff === 0) {
+ return this.text.due_today;
+ }
+
+ const daysText = this.I18n.t('js.units.day', { count: daysDiff });
if (this.isOverdue) {
- return this.text.overdue_since(this.daysDiff);
+ return this.text.overdue_since(daysText);
}
if (this.dateIsPast) {
- return this.text.property_was(this.daysDiff);
+ return this.text.property_was(daysText);
}
- return this.text.property_is(this.daysDiff);
+ return this.text.property_is(daysText);
}
- private dateDiff(reference:Moment):string {
+ private dateDiff(reference:Moment):number {
const now = moment().startOf('day');
- const count = Math.abs(now.diff(reference, 'days'));
-
- return this.I18n.t('js.units.day', { count });
+ return Math.abs(now.diff(reference, 'days'));
}
private deriveMostRelevantAlert(aggregatedNotifications:INotification[]) {
diff --git a/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb b/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
index f42a73145a2..690664c1756 100644
--- a/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
@@ -25,6 +25,8 @@ describe "Notification center date alerts", js: true, with_settings: { journal_a
shared_let(:wp_unset_date) { create(:work_package, subject: 'Unset date', project:, due_date: nil) }
+ shared_let(:wp_due_today) { create(:work_package, subject: 'Due today', project:, due_date: Time.zone.today) }
+
shared_let(:wp_double_alert) do
create(:work_package, subject: 'Double alert', project:, start_date: 1.day.ago, due_date: 1.day.from_now)
end
@@ -117,6 +119,14 @@ describe "Notification center date alerts", js: true, with_settings: { journal_a
project:)
end
+ shared_let(:notification_wp_due_today) do
+ create(:notification,
+ reason: :date_alert_due_date,
+ recipient: user,
+ resource: wp_due_today,
+ project:)
+ end
+
let(:center) { ::Pages::Notifications::Center.new }
let(:side_menu) { ::Components::Notifications::Sidemenu.new }
@@ -137,6 +147,8 @@ describe "Notification center date alerts", js: true, with_settings: { journal_a
center.expect_item(notification_wp_unset_date, 'Finish date is deleted')
+ center.expect_item(notification_wp_due_today, 'Finish date is today')
+
# Doesn't show the date alert for the mention, not the alert
center.expect_item(notification_wp_double_mention, /(seconds|minutes) ago by Anonymous/)
center.expect_no_item(notification_wp_double_date_alert)