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

Add date alert deriving value from details

Oliver Günther4aac6978d0d8
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 1ddf117514d..14c413e7c2c 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -591,6 +591,11 @@ en:
processed: 'processed'
prioritized: 'prioritized'
dateAlert: 'Date alert'
+ date_alerts:
+ work_package_is: 'Work package is'
+ overdue_since: 'Overdue since %{difference_in_days}'
+ property_is: '%{property} is in %{difference_in_days}'
+ property_was: '%{property} was %{difference_in_days} ago'
facets:
unread: 'Unread'
unread_title: 'Show unread'
diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notification.model.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notification.model.ts
index 0bc23be67ab..6a5adf47614 100644
--- a/frontend/src/app/core/state/in-app-notifications/in-app-notification.model.ts
+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notification.model.ts
@@ -12,7 +12,21 @@ export interface IInAppNotificationHalResourceLinks extends IHalResourceLinks {
resource:IHalResourceLink;
activity:IHalResourceLink;
}
+
+export type IInAppNotificationDetailsAttribute = 'startDate'|'dueDate'|'date';
+
+export interface IInAppNotificationDetailsResource {
+ property:IInAppNotificationDetailsAttribute;
+ value:string;
+
+ _links:{
+ self:IHalResourceLink;
+ schema:IHalResourceLink;
+ };
+}
+
export interface IInAppNotificationHalResourceEmbedded {
+ details:IInAppNotificationDetailsResource[];
}
export interface INotification {
diff --git a/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.html b/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.html
index 8fe1884cd22..b36f0d2b30a 100644
--- a/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.html
+++ b/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.html
@@ -1 +1,7 @@
-<p>in-app-notification-date-alert works!</p>
+<div
+ class="op-ian-date-alert"
+>
+ <span
+ [ngClass]="{ 'op-ian-date-alert_overdue': isOverdue }"
+ [textContent]="alertText"></span>
+</div>
diff --git a/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.sass b/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.sass
index e69de29bb2d..a7d4459816e 100644
--- a/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.sass
+++ b/frontend/src/app/features/in-app-notifications/entry/date-alert/in-app-notification-date-alert.component.sass
@@ -0,0 +1,3 @@
+.op-ian-date-alert
+ &_overdue
+ color: var(--warn)
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 cf6f61c27ec..5571dd55dfa 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
@@ -1,17 +1,18 @@
import {
- Component,
- OnInit,
ChangeDetectionStrategy,
+ Component,
Input,
+ OnInit,
} from '@angular/core';
-import { INotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';
-import { PrincipalLike } from 'core-app/shared/components/principal/principal-types';
-import { Observable } from 'rxjs';
+import {
+ IInAppNotificationDetailsAttribute,
+ INotification,
+} from 'core-app/core/state/in-app-notifications/in-app-notification.model';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { DeviceService } from 'core-app/core/browser/device.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
-import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
+import * as moment from 'moment';
+import { Moment } from 'moment';
@Component({
selector: 'op-in-app-notification-date-alert',
@@ -26,44 +27,60 @@ export class InAppNotificationDateAlertComponent implements OnInit {
@Input() workPackage:WorkPackageResource;
+ alertText:string;
+
+ dateIsPast:boolean;
+
+ isOverdue:boolean;
+
+ private propertyText:string;
+
+ private daysDiff:string;
+
text = {
- and: this.I18n.t('js.notifications.center.label_actor_and'),
- and_other_singular: this.I18n.t('js.notifications.center.and_more_users.one'),
- and_other_plural: (count:number):string => this.I18n.t('js.notifications.center.and_more_users.other',
- { count }),
- loading: this.I18n.t('js.ajax.loading'),
- placeholder: this.I18n.t('js.placeholders.default'),
- mark_as_read: this.I18n.t('js.notifications.center.mark_as_read'),
- updated_by_at: (age:string):string => this.I18n.t('js.notifications.center.text_update_date',
- { date: age }),
+ work_package_is: this.I18n.t('js.notifications.date_alerts.work_package_is'),
+ overdue_since: (difference_in_days:string) => this.I18n.t('js.notifications.date_alerts.overdue_since', { difference_in_days }),
+ property_is: (property:string, difference_in_days:string) =>
+ this.I18n.t('js.notifications.date_alerts.property_is', { property, difference_in_days }),
+ property_was: (property:string, difference_in_days:string) =>
+ this.I18n.t('js.notifications.date_alerts.property_was', { property, difference_in_days }),
+ startDate: this.I18n.t('js.work_packages.properties.startDate'),
+ dueDate: this.I18n.t('js.work_packages.properties.dueDate'),
+ date: this.I18n.t('js.work_packages.properties.date'),
};
constructor(
private I18n:I18nService,
private timezoneService:TimezoneService,
- private deviceService:DeviceService,
- private schemaCache:SchemaCacheService,
) { }
ngOnInit():void {
- this.buildAlertText();
+ const detail = this.notification._embedded.details[0];
+ const property = detail.property;
+ const dateValue = this.timezoneService.parseISODate(detail.value);
+ this.dateIsPast = dateValue.isBefore();
+ this.isOverdue = this.dateIsPast && ['date', 'dueDate'].includes(property);
+ this.daysDiff = this.dateDiff(dateValue);
+ this.propertyText = this.text[property] || property;
+ this.alertText = this.buildAlertText();
}
- private buildAlertText() {
+ private buildAlertText():string {
if (this.isOverdue) {
- return;
+ return this.text.overdue_since(this.daysDiff);
}
- if (this.isMilestone) {
-
+ if (this.dateIsPast) {
+ return this.text.property_was(this.propertyText, this.daysDiff);
}
- }
- private get isOverdue():boolean {
- return false;
+ return this.text.property_is(this.propertyText, this.daysDiff);
}
- private get isMilestone():boolean {
- return this.schemaCache.of(this.workPackage).isMilestone as boolean;
+ private dateDiff(reference:Moment):string {
+ const now = moment().startOf('day');
+ const count = Math.abs(now.diff(reference, 'days'));
+
+ return this.I18n.t('js.units.day', { count });
}
}
diff --git a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts
index 29b1b0caf4c..bcd8876f981 100644
--- a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts
+++ b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts
@@ -45,7 +45,6 @@ export class InAppNotificationEntryComponent implements OnInit {
.storeService
.activeReason$
.pipe(
- tap((x) => console.warn(x)),
map((reason) => reason === 'date_alert'),
startWith(false),
);