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

Start rewrite of notification settings page state to use a copy of store data

Benjamin Bädorf9ca1aa4355e5
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 ca82b983f91..1e3f04dbe34 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
@@ -100,6 +100,7 @@
<op-notification-settings-table
*ngIf="userId"
[userId]="userId"
+ [settings]="form.get('projectSettings')"
></op-notification-settings-table>
<div class="generic-table--action-buttons">
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 7e142ffbddb..32d0efa42c2 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
@@ -6,6 +6,7 @@ import {
} from '@angular/core';
import {
FormGroup,
+ FormArray,
FormControl,
} from '@angular/forms';
import { arrayUpdate } from '@datorama/akita';
@@ -30,12 +31,13 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
@Input() userId:string;
public form = new FormGroup({
- involved: new FormControl(false, []),
- workPackageCreated: new FormControl(false, []),
- workPackageProcessed: new FormControl(false, []),
- workPackageScheduled: new FormControl(false, []),
- workPackagePrioritized: new FormControl(false, []),
- workPackageCommented: new FormControl(false, []),
+ involved: new FormControl(false),
+ workPackageCreated: new FormControl(false),
+ workPackageProcessed: new FormControl(false),
+ workPackageScheduled: new FormControl(false),
+ workPackagePrioritized: new FormControl(false),
+ workPackageCommented: new FormControl(false),
+ projectSettings: new FormArray([]),
});
text = {
@@ -104,6 +106,33 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
this.form.get('workPackagePrioritized')?.setValue(settings.workPackagePrioritized);
this.form.get('workPackageCommented')?.setValue(settings.workPackageCommented);
});
+
+ this.query.projectNotifications$
+ .pipe(this.untilDestroyed())
+ .subscribe((settings) => {
+ if (!settings) {
+ return;
+ }
+
+ console.log(settings);
+ const sortedSettings = settings.sort(
+ (a, b):number => a._links.project.title!.localeCompare(b._links.project.title!)
+ );
+
+ const projectSettings = this.form.get("projectSettings") as FormArray;
+ projectSettings.clear();
+ for (let setting of sortedSettings) {
+ projectSettings.push(new FormGroup({
+ project: new FormControl(setting._links.project),
+ involved: new FormControl(setting.involved),
+ workPackageCreated: new FormControl(setting.workPackageCreated),
+ workPackageProcessed: new FormControl(setting.workPackageProcessed),
+ workPackageScheduled: new FormControl(setting.workPackageScheduled),
+ workPackagePrioritized: new FormControl(setting.workPackagePrioritized),
+ workPackageCommented: new FormControl(setting.workPackageCommented),
+ }));
+ }
+ });
}
public saveChanges():void {
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
index 8594c820afa..ace5799e499 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
+++ b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
@@ -1,6 +1,6 @@
<table
class="op-table"
- *ngIf="showTable$ | async"
+ *ngIf="showTable"
>
<thead>
<tr>
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
index 5ae7aff9019..7c211af4564 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
@@ -5,6 +5,7 @@ import {
ChangeDetectionStrategy,
Input,
} from '@angular/core';
+import { FormArray } from '@angular/forms';
import { map } from 'rxjs/operators';
import { KeyValue } from '@angular/common';
import { arrayAdd, arrayUpdate, arrayRemove } from '@datorama/akita';
@@ -26,9 +27,11 @@ import {
export class NotificationSettingsTableComponent {
@Input() userId:string;
- groupedNotificationSettings$ = this.query.notificationsGroupedByProject$;
+ @Input() settings:FormArray;
- showTable$ = this.query.notificationsGroupedByProject$.pipe(map((settings) => Object.keys(settings).length > 0));
+ get showTable() {
+ return this.settings.length > 0;
+ }
text = {
notify_me: this.I18n.t('js.notifications.settings.notify_me'),
@@ -43,10 +46,6 @@ export class NotificationSettingsTableComponent {
work_package_scheduled_header: this.I18n.t('js.notifications.settings.reasons.work_package_scheduled'),
};
- projectOrder = (a:KeyValue<string, unknown>, b:KeyValue<string, unknown>):number => {
- return a.key.localeCompare(b.key);
- };
-
constructor(
private I18n:I18nService,
private store:UserPreferencesStore,
diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.query.ts b/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
index 9306d5975e9..f0d4d82bd49 100644
--- a/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
+++ b/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
@@ -14,8 +14,8 @@ export class UserPreferencesQuery extends Query<UserPreferencesModel> {
notificationsGroupedByProject$:Observable<{ [key:string]:NotificationSetting[] }> = this
.notificationSettings$
.pipe(
- map((notifications) => notifications.filter((setting) => setting.channel === 'in_app' && setting._links.project.href)),
- map((notifications) => _.groupBy(notifications, (setting) => setting._links.project.title)),
+ map((settings) => settings.filter((setting) => setting.channel === 'in_app' && setting._links.project.href)),
+ map((settings) => _.groupBy(settings, (setting) => setting._links.project.title)),
);
/** Notification settings grouped by Project */
@@ -28,7 +28,7 @@ export class UserPreferencesQuery extends Query<UserPreferencesModel> {
projectNotifications$ = this
.notificationSettings$
.pipe(
- map((settings) => settings.filter((notification) => notification._links.project.href !== null)),
+ map((settings) => settings.filter((setting) => setting.channel === 'in_app'&& setting._links.project.href !== null)),
);
/** Selected projects */