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

Move to reactive forms for the notification settings reminder stuff

Benjamin Bädorf7a7a0fab758e
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html
index ccb3d666541..af8cdcc65f4 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html
+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html
@@ -54,48 +54,57 @@
</spot-selector-field>
<h5>Date alerts</h5>
- <div class="op-reminder-settings-daily-time--row">
+ <div
+ class="op-reminder-settings-daily-time--row"
+ formGroupName="startDate"
+ >
<input
type="checkbox"
- [ngModel]="isActive('startDate')"
- [ngModelOptions]="{standalone: true}"
+ formControlName="active"
class="op-reminder-settings-daily-time--active"
- attr.data-qa-selector="op-settings-start-date">
+ attr.data-qa-selector="op-settings-start-date"
+ />
<label
class="op-reminder-settings-daily-time--label"
[textContent]="text.startDate"
- attr.for="op-reminder-settings-daily-time">
- </label>
+ attr.for="op-reminder-settings-daily-time"
+ ></label>
<select
- (ngModelChange)="changeTime($event, 'startDate')"
+ formControlName="time"
class="op-reminder-settings-daily-time--time form--select -narrow"
attr.id="op-reminder-settings-daily-time"
- required="true">
+ required="true"
+ >
<option
*ngFor="let availableTime of availableTimes"
- [value]="availableTime">
+ [value]="availableTime"
+ >
{{availableTime}}
</option>
</select>
</div>
- <div class="op-reminder-settings-daily-time--row">
+ <div
+ class="op-reminder-settings-daily-time--row"
+ formGroupName="dueDate"
+ >
<input
type="checkbox"
- [ngModel]="isActive('dueDate')"
- [ngModelOptions]="{standalone: true}"
+ formControlName="active"
class="op-reminder-settings-daily-time--active"
- attr.data-qa-selector="op-settings-start-date">
+ attr.data-qa-selector="op-settings-start-date"
+ />
<label
class="op-reminder-settings-daily-time--label"
[textContent]="text.dueDate"
- attr.for="op-reminder-settings-daily-time">
- </label>
+ attr.for="op-reminder-settings-daily-time"
+ ></label>
<select
- (ngModelChange)="changeTime($event, 'dueDate')"
+ formControlName="time"
class="op-reminder-settings-daily-time--time form--select -narrow"
attr.id="op-reminder-settings-daily-time"
- required="true">
+ required="true"
+ >
<option
*ngFor="let availableTime of availableTimes"
[value]="availableTime">
@@ -104,23 +113,26 @@
</select>
</div>
- <div class="op-reminder-settings-daily-time--row">
+ <div
+ class="op-reminder-settings-daily-time--row"
+ formGroupName="overdue"
+ >
<input
+ formControlName="active"
type="checkbox"
- [ngModel]="isActive('overdue')"
- [ngModelOptions]="{standalone: true}"
class="op-reminder-settings-daily-time--active"
attr.data-qa-selector="op-settings-start-date">
<label
class="op-reminder-settings-daily-time--label"
[textContent]="text.overdue"
- attr.for="op-reminder-settings-daily-time">
- </label>
+ attr.for="op-reminder-settings-daily-time"
+ ></label>
<select
- (ngModelChange)="changeTime($event, 'overdue')"
+ formControlName="time"
class="op-reminder-settings-daily-time--time form--select -narrow"
attr.id="op-reminder-settings-daily-time"
- required="true">
+ required="true"
+ >
<option
*ngFor="let availableTime of availableTimesOverdue"
[value]="availableTime">
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
index a650534ae3c..a1073090dfa 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
@@ -50,6 +50,9 @@ interface IFullNotificationSettingsValue extends IToastSettingsValue {
export class NotificationsSettingsPageComponent extends UntilDestroyedMixin implements OnInit {
@Input() userId:string;
+ public availableTimes:string[] = ['PT0S', 'P1D', 'P3D', 'P7D'];
+ public availableTimesOverdue:string[] = ['PT0S', 'P3D', 'P7D'];
+
public form = new FormGroup({
assignee: new FormControl(false),
responsible: new FormControl(false),
@@ -58,15 +61,21 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
workPackageScheduled: new FormControl(false),
workPackagePrioritized: new FormControl(false),
workPackageCommented: new FormControl(false),
- startDate: new FormControl(null),
- dueDate: new FormControl(null),
- overdue: new FormControl(null),
+ startDate: new FormGroup({
+ active: new FormControl(false),
+ time: new FormControl(this.availableTimes[1]),
+ }),
+ dueDate: new FormGroup({
+ active: new FormControl(false),
+ time: new FormControl(this.availableTimes[1]),
+ }),
+ overdue: new FormGroup({
+ active: new FormControl(false),
+ time: new FormControl(this.availableTimesOverdue[0]),
+ }),
projectSettings: new FormArray([]),
});
- public availableTimes:string[] = ['PT0S', 'P1D', 'P3D', 'P1W'];
- public availableTimesOverdue:string[] = ['PT0S', 'P3D', 'P1W'];
-
text = {
notifyImmediately: {
title: this.I18n.t('js.notifications.settings.global.immediately.title'),
@@ -113,6 +122,7 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
}
ngOnInit():void {
+ this.form.disable();
this.userId = this.userId || this.uiRouterGlobals.params.userId;
this
.currentUserService
@@ -123,6 +133,33 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
this.storeService.get(this.userId);
});
+ this.form.get('startDate.active')?.valueChanges.subscribe((newValue) => {
+ const timeCtrl = this.form.get('startDate.time')!
+ if (!newValue) {
+ timeCtrl.disable();
+ } else {
+ timeCtrl.enable();
+ }
+ });
+
+ this.form.get('dueDate.active')?.valueChanges.subscribe((newValue) => {
+ const timeCtrl = this.form.get('dueDate.time')!
+ if (!newValue) {
+ timeCtrl.disable();
+ } else {
+ timeCtrl.enable();
+ }
+ });
+
+ this.form.get('overdue.active')?.valueChanges.subscribe((newValue) => {
+ const timeCtrl = this.form.get('overdue.time')!
+ if (!newValue) {
+ timeCtrl.disable();
+ } else {
+ timeCtrl.enable();
+ }
+ });
+
this.storeService.query.notificationsForGlobal$
.pipe(this.untilDestroyed())
.subscribe((settings) => {
@@ -137,9 +174,17 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
this.form.get('workPackageScheduled')?.setValue(settings.workPackageScheduled);
this.form.get('workPackagePrioritized')?.setValue(settings.workPackagePrioritized);
this.form.get('workPackageCommented')?.setValue(settings.workPackageCommented);
- this.form.get('startDate')?.setValue(settings.startDate);
- this.form.get('dueDate')?.setValue(settings.dueDate);
- this.form.get('overdue')?.setValue(settings.overdue);
+
+ this.form.get('startDate.active')?.setValue(!!settings.startDate);
+ this.form.get('startDate.time')?.setValue(settings.startDate || this.availableTimes[1]);
+
+ this.form.get('dueDate.active')?.setValue(!!settings.dueDate);
+ this.form.get('dueDate.time')?.setValue(settings.dueDate || this.availableTimes[1]);
+
+ this.form.get('overdue.active')?.setValue(!!settings.overdue);
+ this.form.get('overdue.time')?.setValue(settings.overdue || this.availableTimesOverdue[0]);
+
+ this.form.enable();
});
this.storeService.query.projectNotifications$
@@ -197,9 +242,9 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
workPackageScheduled: notificationSettings.workPackageScheduled,
workPackagePrioritized: notificationSettings.workPackagePrioritized,
workPackageCommented: notificationSettings.workPackageCommented,
- startDate: 'P1D',
- dueDate: 'P1D',
- overdue: null,
+ startDate: this.form.get('startDate.active')!.value ? this.form.get('startDate.time')!.value : null,
+ dueDate: this.form.get('dueDate.active')!.value ? this.form.get('dueDate.time')!.value : null,
+ overdue: this.form.get('overdue.active')!.value ? this.form.get('overdue.time')!.value : null,
};
const projectPrefs:INotificationSetting[] = notificationSettings.projectSettings.map((settings) => ({