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
Saving and loading works with reactive forms
Benjamin Bädorf95b1ff935a64
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex a40f4b9ae78..2d533da48de 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -577,7 +577,7 @@ en:total_count_warning: "Showing the %{newest_count} most recent notifications. %{more_count} more are not displayed."settings:title: "Notification settings"- notity_me: "Notify me"+ notify_me: "Notify me"reasons:mentioned:title: 'I am @mentioned'diff --git a/frontend/src/app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component.tsindex 396e97a4760..21d80100e11 100644--- a/frontend/src/app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component.ts+++ b/frontend/src/app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component.ts@@ -5,6 +5,7 @@ import {Input,Output,} from '@angular/core';+import { FormArray } from '@angular/forms';import { I18nService } from 'core-app/core/i18n/i18n.service';import { Observable } from 'rxjs';import {@@ -29,6 +30,8 @@ export interface NotificationSettingProjectOption {export class NotificationSettingInlineCreateComponent {@Input() userId:string;+ @Input() settings:FormArray;+@Output() selected = new EventEmitter<HalSourceLink>();/** Active inline-create mode */@@ -72,12 +75,11 @@ export class NotificationSettingInlineCreateComponent {.filtered(filters).get().pipe(- withLatestFrom(this.query.selectedProjects$),- map(([collection, selected]) => collection.elements.map(- (project) => (- { href: project.href || '', name: project.name, disabled: selected.has(project.href) }- ),- )),+ map((collection) => collection.elements.map((project) => ({+ href: project.href || '',+ name: project.name,+ disabled: !!this.settings.controls.find((projectSetting) => projectSetting.get('project')!.value.href === project.href),+ }))),);}}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.htmlindex 1e3f04dbe34..94340cdc8f3 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,7 +100,9 @@<op-notification-settings-table*ngIf="userId"[userId]="userId"- [settings]="form.get('projectSettings')"+ [settings]="form.controls.projectSettings"+ formArrayName="projectSettings"+ class="op-notification-settings-page--table"></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.tsindex 32d0efa42c2..48b4e561411 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@@ -1,5 +1,6 @@import {ChangeDetectionStrategy,+ ChangeDetectorRef,Component,Input,OnInit,@@ -9,7 +10,6 @@ import {FormArray,FormControl,} from '@angular/forms';-import { arrayUpdate } from '@datorama/akita';import { take } from 'rxjs/internal/operators/take';import { UIRouterGlobals } from '@uirouter/core';import { I18nService } from 'core-app/core/i18n/i18n.service';@@ -22,6 +22,26 @@ import { NotificationSetting } from 'core-app/features/user-preferences/state/noexport const myNotificationsPageComponentSelector = 'op-notifications-page';+interface INotificationSettingsFormValue {+ involved:boolean;+ workPackageCreated:boolean;+ workPackageProcessed:boolean;+ workPackageScheduled:boolean;+ workPackagePrioritized:boolean;+ workPackageCommented:boolean;+}++interface IProjectNotificationSettingsValue extends INotificationSettingsFormValue {+ project: {+ title:string;+ href:string;+ };+}++interface IFullNotificationSettingsValue extends INotificationSettingsFormValue {+ projectSettings:IProjectNotificationSettingsValue[];+}+@Component({selector: myNotificationsPageComponentSelector,templateUrl: './notifications-settings-page.component.html',@@ -71,6 +91,7 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl};constructor(+ private changeDetectorRef: ChangeDetectorRef,private I18n:I18nService,private stateService:UserPreferencesService,private query:UserPreferencesQuery,@@ -114,12 +135,11 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin implreturn;}- 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;+ const projectSettings = new FormArray([]);projectSettings.clear();for (let setting of sortedSettings) {projectSettings.push(new FormGroup({@@ -132,28 +152,54 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin implworkPackageCommented: new FormControl(setting.workPackageCommented),}));}++ this.form.setControl('projectSettings', projectSettings);+ this.changeDetectorRef.detectChanges();});}public saveChanges():void {- this.update(this.form.value);- const prefs = this.query.getValue();- this.stateService.update(this.userId, prefs);- }+ const prefs = this.store.getValue();+ const notificationSettings:IFullNotificationSettingsValue = this.form.value;+ const globalPrefs:NotificationSetting = {+ _links: { project: { href: null } },+ channel: 'in_app',+ watched: true,+ mentioned: true,+ involved: notificationSettings.involved,+ workPackageCreated: notificationSettings.workPackageCreated,+ workPackageProcessed: notificationSettings.workPackageProcessed,+ workPackageScheduled: notificationSettings.workPackageScheduled,+ workPackagePrioritized: notificationSettings.workPackagePrioritized,+ workPackageCommented: notificationSettings.workPackageCommented,+ all: false,+ };++ const projectPrefs:NotificationSetting[] = notificationSettings.projectSettings.map((settings) => ({+ _links: { project: { href: settings.project.href } },+ channel: 'in_app',+ watched: true,+ mentioned: true,+ involved: settings.involved,+ workPackageCreated: settings.workPackageCreated,+ workPackageProcessed: settings.workPackageProcessed,+ workPackageScheduled: settings.workPackageScheduled,+ workPackagePrioritized: settings.workPackagePrioritized,+ workPackageCommented: settings.workPackageCommented,+ all: false,+ }));- private update(delta:Partial<NotificationSetting>) {- this.store.update(- ({ notifications }) => ({- notifications: arrayUpdate(- notifications,- (notification:NotificationSetting) => notification._links.project.href === null,- {- ...delta,- mentioned: true,- watched: true,- },- ),- }),- );+ this.stateService.update(this.userId, {+ ...prefs,+ notifications: [+ globalPrefs,+ ...projectPrefs,+ ].reduce((total, next) => [+ ...total,+ next,+ { ...next, channel: 'mail' },+ { ...next, channel: 'mail_digest' },+ ], []),+ });}}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.htmlindex ace5799e499..f8ecc9bef35 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,32 +1,31 @@<tableclass="op-table"- *ngIf="showTable"+ *ngIf="settings.length > 0"><thead><tr><th class="op-table--cell op-table--cell_heading">{{ text.notify_me }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">- <th class="op-table--cell op-table--cell_heading">{{ item.key }}</th>+ <ng-container *ngFor="let item of settings.controls">+ <th class="op-table--cell op-table--cell_heading">{{ item.controls.project.value.title }}</th></ng-container></tr></thead><tbody><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.mentioned_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">+ <ng-container *ngFor="let item of settings.controls"><td class="op-table--cell"><input type="checkbox" disabled checked /></td></ng-container></tr><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.involved_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">- <td class="op-table--cell" *ngIf="item.value[0]">+ <ng-container *ngFor="let item of settings.controls">+ <td class="op-table--cell" [formGroup]="item"><inputtype="checkbox"- [checked]="item.value[0].involved"- (change)="update({ involved: $event.target.checked }, item.value[0]._links.project.href)"+ formControlName="involved"data-qa-project-notification-type="involved"[attr.data-qa-project]="item.key"/>@@ -35,18 +34,17 @@</tr><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.watched_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">+ <ng-container *ngFor="let item of settings.controls"><td class="op-table--cell"><input type="checkbox" disabled checked /></td></ng-container></tr><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.work_package_created_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">- <td class="op-table--cell" *ngIf="item.value[0]">+ <ng-container *ngFor="let item of settings.controls">+ <td class="op-table--cell" [formGroup]="item"><inputtype="checkbox"- [checked]="item.value[0].workPackageCreated"- (change)="update({ workPackageCreated: $event.target.checked }, item.value[0]._links.project.href)"+ formControlName="workPackageCreated"data-qa-project-notification-type="work_package_created"[attr.data-qa-project]="item.key"/>@@ -55,12 +53,11 @@</tr><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.work_package_processed_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">- <td class="op-table--cell" *ngIf="item.value[0]">+ <ng-container *ngFor="let item of settings.controls">+ <td class="op-table--cell" [formGroup]="item"><inputtype="checkbox"- [checked]="item.value[0].workPackageProcessed"- (change)="update({ workPackageProcessed: $event.target.checked }, item.value[0]._links.project.href)"+ formControlName="workPackageProcessed"data-qa-project-notification-type="work_package_processed"[attr.data-qa-project]="item.key"/>@@ -69,12 +66,11 @@</tr><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.work_package_scheduled_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">- <td class="op-table--cell" *ngIf="item.value[0]">+ <ng-container *ngFor="let item of settings.controls">+ <td class="op-table--cell" [formGroup]="item"><inputtype="checkbox"- [checked]="item.value[0].workPackageScheduled"- (change)="update({ workPackageScheduled: $event.target.checked }, item.value[0]._links.project.href)"+ formControlName="workPackageScheduled"data-qa-project-notification-type="work_package_scheduled"[attr.data-qa-project]="item.key"/>@@ -83,12 +79,11 @@</tr><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.work_package_prioritized_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">- <td class="op-table--cell" *ngIf="item.value[0]">+ <ng-container *ngFor="let item of settings.controls">+ <td class="op-table--cell" [formGroup]="item"><inputtype="checkbox"- [checked]="item.value[0].workPackagePrioritized"- (change)="update({ workPackagePrioritized: $event.target.checked }, item.value[0]._links.project.href)"+ formControlName="workPackagePrioritized"data-qa-project-notification-type="work_package_prioritized"[attr.data-qa-project]="item.key"/>@@ -97,12 +92,11 @@</tr><tr><th class="op-table--cell op-table--cell_soft-heading">{{ text.work_package_commented_header }}</th>- <ng-container *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">- <td class="op-table--cell" *ngIf="item.value[0]">+ <ng-container *ngFor="let item of settings.controls">+ <td class="op-table--cell" [formGroup]="item"><inputtype="checkbox"- [checked]="item.value[0].workPackageCommented"- (change)="update({ workPackageCommented: $event.target.checked }, item.value[0]._links.project.href)"+ formControlName="workPackageCommented"data-qa-project-notification-type="work_package_commented"[attr.data-qa-project]="item.key"/>@@ -111,14 +105,12 @@</tr><tr><th class="op-table--cell op-table--cell_soft-heading"></th>- <ng-container- *ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue"- >- <td class="op-table--cell" *ngIf="item.value[0]">+ <ng-container *ngFor="let item of settings.controls; let index = index">+ <td class="op-table--cell"><buttontype="button"class="op-link"- (click)="removeProjectSettings(item.value[0]._links.project.href)"+ (click)="removeProjectSettings(index)">Remove Project Settings</button></td></ng-container>@@ -129,6 +121,7 @@<op-notification-setting-inline-create*ngIf="userId"[userId]="userId"- (selected)="addRow($event)"+ [settings]="settings"+ (selected)="addProjectSettings($event)"data-qa-selector="notification-setting-inline-create"></op-notification-setting-inline-create>\ No newline at end of filediff --git a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.sass b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.sassindex 9d08340dffd..166a2a80072 100644--- a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.sass+++ b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.sass@@ -1,6 +1,2 @@-.op-notifications-settings-table- &--spacer-- // The default table styles are a mess- td- padding: 0 !important\ No newline at end of file+.op-table+ margin-bottom: 1rem\ No newline at end of filediff --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.tsindex 7c211af4564..28db947bdf4 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,18 +5,9 @@ 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';+import { FormArray, FormGroup, FormControl } from '@angular/forms';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { UserPreferencesStore } from 'core-app/features/user-preferences/state/user-preferences.store';-import { UserPreferencesQuery } from 'core-app/features/user-preferences/state/user-preferences.query';import { HalSourceLink } from 'core-app/features/hal/resources/hal-resource';-import {- buildNotificationSetting,- NotificationSetting,-} from 'core-app/features/user-preferences/state/notification-setting.model';@Component({selector: 'op-notification-settings-table',@@ -29,10 +20,6 @@ export class NotificationSettingsTableComponent {@Input() settings:FormArray;- get showTable() {- return this.settings.length > 0;- }-text = {notify_me: this.I18n.t('js.notifications.settings.notify_me'),save: this.I18n.t('js.button_save'),@@ -46,43 +33,21 @@ export class NotificationSettingsTableComponent {work_package_scheduled_header: this.I18n.t('js.notifications.settings.reasons.work_package_scheduled'),};- constructor(- private I18n:I18nService,- private store:UserPreferencesStore,- private query:UserPreferencesQuery,- ) {}-- addRow(project:HalSourceLink):void {- const added:NotificationSetting[] = [- buildNotificationSetting(project, { channel: 'in_app' }),- buildNotificationSetting(project, { channel: 'mail' }),- buildNotificationSetting(project, { channel: 'mail_digest' }),- ];-- this.store.update(- ({ notifications }) => ({- notifications: arrayAdd(notifications, added),- }),- );- }-- update(delta:Partial<NotificationSetting>, projectHref:string):void {- this.store.update(- ({ notifications }) => ({- notifications: arrayUpdate(- notifications,- (notification:NotificationSetting) => notification._links.project.href === projectHref,- delta,- ),- }),- );+ constructor(private I18n:I18nService) {}++ addProjectSettings(project:HalSourceLink):void {+ this.settings.push(new FormGroup({+ project: new FormControl(project),+ involved: new FormControl(false),+ workPackageCreated: new FormControl(false),+ workPackageProcessed: new FormControl(false),+ workPackageScheduled: new FormControl(false),+ workPackagePrioritized: new FormControl(false),+ workPackageCommented: new FormControl(false),+ }));}- removeProjectSettings(projectHref:string):void {- this.store.update(- ({ notifications }) => ({- notifications: arrayRemove(notifications, (notification:NotificationSetting) => notification._links.project.href === projectHref),- }),- );+ removeProjectSettings(index:number):void {+ this.settings.removeAt(index);}}