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
Start implementing the form state and submit
Benjamin Bädorf65d018e60bbd
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 ec7b94a3360..507d3867a11 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@@ -6,25 +6,19 @@<h2>Notify me immediately</h2><p>These settings apply to all projects. You can create project-specific exceptions below.</p>- <div class="op-form-field op-form-field_checkbox">- <label class="op-form-field--label-wrap">- <div class="op-form-field--label">I am @mentioned</div>+ <op-checkbox-field label="I am @Mentioned"><inputdisabledcheckedtype="checkbox"+ slot="input"/>- </label>- <div class="op-form-field--description"><p slot="description">Receive a notification every time someone mentions me anywhere</p>- </div>- </div>+ </op-checkbox-field>- <op-form-field+ <op-checkbox-fieldlabel="Assigned to me or accountable"- [checkbox]="true"[control]="form.get('assignedToMeOrAccountable')"- [noWrapLabel]="false"><inputslot="input"@@ -34,88 +28,65 @@<p slot="description">Receive notifications for all activities on work packages for which I am assignee or accountable.</p>- </op-form-field>+ </op-checkbox-field><h2>Also notify me for</h2><p>Receive notifications for these activities on work packages in all projects:</p>- <div class="op-form-field op-form-field_checkbox">- <label class="op-form-field--label-wrap">+ <op-checkbox-field><inputdisabledcheckedtype="checkbox"+ slot="input"/>- </label>- <div class="op-form-field--description"><p slot="description">Updates on watched items</p>- </div>- </div>+ </op-checkbox-field>- <op-form-field- [checkbox]="true"- [control]="form.get('newWorkPackages')"- [noWrapLabel]="false"- >+ <op-checkbox-field [control]="form.get('newWorkPackages')"><inputslot="input"type="checkbox"formControlName="newWorkPackages"/><p slot="description">New work packages</p>- </op-form-field>+ </op-checkbox-field>- <op-form-field- [checkbox]="true"- [control]="form.get('allStatusChanges')"- [noWrapLabel]="false"- >+ <op-checkbox-field [control]="form.get('allStatusChanges')"><inputslot="input"type="checkbox"formControlName="allStatusChanges"/><p slot="description">All status changes</p>- </op-form-field>+ </op-checkbox-field>- <op-form-field- [checkbox]="true"- [control]="form.get('allDateChanges')"- [noWrapLabel]="false"- >+ <op-checkbox-field [control]="form.get('allDateChanges')"><inputslot="input"type="checkbox"formControlName="allDateChanges"/><p slot="description">All date changes</p>- </op-form-field>+ </op-checkbox-field>- <op-form-field- [checkbox]="true"- [control]="form.get('allPriorityChanges')"- [noWrapLabel]="false"- >+ <op-checkbox-field [control]="form.get('allPriorityChanges')"><inputslot="input"type="checkbox"formControlName="allPriorityChanges"/><p slot="description">All priority changes</p>- </op-form-field>+ </op-checkbox-field>- <op-form-field- [checkbox]="true"- [control]="form.get('allNewComments')"- [noWrapLabel]="false"- >+ <op-checkbox-field [control]="form.get('allNewComments')"><inputslot="input"type="checkbox"formControlName="allNewComments"/><p slot="description">All new comments</p>- </op-form-field>+ </op-checkbox-field><hr />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 d5438cc1840..2f9e65e0b26 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@@ -48,8 +48,7 @@ export class NotificationsSettingsPageComponent implements OnInit {private query:UserPreferencesQuery,private currentUserService:CurrentUserService,private uiRouterGlobals:UIRouterGlobals,- ) {- }+ ) {}ngOnInit():void {this.userId = this.userId || this.uiRouterGlobals.params.userId;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 fdcc7ca74f8..c1bce8ccd41 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@@ -4,7 +4,7 @@><thead><tr>- <th class="op-table-cell op-table--cell_heading"></th>+ <th class="op-table--cell op-table--cell_heading"></th><ng-container*ngFor="let item of (groupedNotificationSettings$ | async) | keyvalue">@@ -22,10 +22,11 @@<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[0]">+ <td class="op-table--cell" *ngIf="item.value[0]"><inputtype="checkbox"- [checked]="item[0].involved"+ [checked]="item.value[0].involved"+ (change)="update({ involved: $event.target.checked }, item.value[0]._links.project.href)"/></td></ng-container>@@ -39,10 +40,11 @@<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[0]">+ <td class="op-table--cell" *ngIf="item.value[0]"><inputtype="checkbox"- [checked]="item[0].workPackageCreated"+ [checked]="item.value[0].workPackageCreated"+ (change)="update({ workPackageCreated: $event.target.checked }, item.value[0]._links.project.href)"/></td></ng-container>@@ -50,10 +52,11 @@<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[0]">+ <td class="op-table--cell" *ngIf="item.value[0]"><inputtype="checkbox"- [checked]="item[0].workPackageProcessed"+ [checked]="item.value[0].workPackageProcessed"+ (change)="update({ workPackageProcessed: $event.target.checked }, item.value[0]._links.project.href)"/></td></ng-container>@@ -61,10 +64,11 @@<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[0]">+ <td class="op-table--cell" *ngIf="item.value[0]"><inputtype="checkbox"- [checked]="item[0].workPackageScheduled"+ [checked]="item.value[0].workPackageScheduled"+ (change)="update({ workPackageScheduled: $event.target.checked }, item.value[0]._links.project.href)"/></td></ng-container>@@ -72,10 +76,11 @@<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[0]">+ <td class="op-table--cell" *ngIf="item.value[0]"><inputtype="checkbox"- [checked]="item[0].workPackagePrioritized"+ [checked]="item.value[0].workPackagePrioritized"+ (change)="update({ workPackagePrioritized: $event.target.checked }, item.value[0]._links.project.href)"/></td></ng-container>@@ -83,14 +88,28 @@<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[0]">+ <td class="op-table--cell" *ngIf="item.value[0]"><inputtype="checkbox"- [checked]="item[0].workPackageCommented"+ [checked]="item.value[0].workPackageCommented"+ (change)="update({ workPackageCommented: $event.target.checked }, item.value[0]._links.project.href)"/></td></ng-container></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]">+ <button+ type="button"+ class="op-link"+ >Restore defaults</button>+ </td>+ </ng-container>+ </tr></tbody></table>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.tsindex 75829738de3..788ba5aa376 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,8 +5,9 @@ import {ChangeDetectionStrategy,Input,} from '@angular/core';-import { map, tap } from 'rxjs/operators';+import { map } from 'rxjs/operators';import { KeyValue } from '@angular/common';+import { arrayAdd, arrayUpdate } from '@datorama/akita';import { I18nService } from 'core-app/core/i18n/i18n.service';import { UserPreferencesService } from 'core-app/features/user-preferences/state/user-preferences.service';import { UserPreferencesStore } from 'core-app/features/user-preferences/state/user-preferences.store';@@ -16,7 +17,6 @@ import {buildNotificationSetting,NotificationSetting,} from 'core-app/features/user-preferences/state/notification-setting.model';-import { arrayAdd } from '@datorama/akita';@Component({selector: 'op-notification-settings-table',@@ -71,4 +71,21 @@ export class NotificationSettingsTableComponent {}),);}++ update(delta:Partial<NotificationSetting>, projectHref: string) {+ this.store.update(+ ({ notifications }) => ({+ notifications: arrayUpdate(+ notifications, this.getStoreMatcherFn(delta, projectHref), delta,+ ),+ }),+ );+ }++ private getStoreMatcherFn(delta:Partial<NotificationSetting>, projectHref: string) {+ return (notification:NotificationSetting) => {+ return notification._links.project.href === projectHref+ && notification.channel === delta.channel;+ };+ }}diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-field-wrapper/dynamic-field-wrapper.component.html b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-field-wrapper/dynamic-field-wrapper.component.htmlindex 20f71264646..e715cfa8ac1 100644--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-field-wrapper/dynamic-field-wrapper.component.html+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-field-wrapper/dynamic-field-wrapper.component.html@@ -1,10 +1,10 @@<op-form-field+ *ngIf="field.type !== 'booleanInput'"[control]="field?.formControl"[label]="to?.label"[hidden]="field?.hide"[noWrapLabel]="to?.noWrapLabel"[required]="to?.required"- [checkbox]="field.type === 'booleanInput'"[helpTextAttribute]="to?.property"[helpTextAttributeScope]="to?.helpTextAttributeScope || dynamicFormComponent?.helpTextAttributeScope"[showValidationErrorOn]="to?.showValidationErrorOn || dynamicFormComponent?.showValidationErrorsOn"@@ -18,3 +18,23 @@slot="errors"></formly-validation-message></op-form-field>++<op-checkbox-field+ *ngIf="field.type === 'booleanInput'"+ [control]="field?.formControl"+ [label]="to?.label"+ [hidden]="field?.hide"+ [required]="to?.required"+ [helpTextAttribute]="to?.property"+ [helpTextAttributeScope]="to?.helpTextAttributeScope || dynamicFormComponent?.helpTextAttributeScope"+ [showValidationErrorOn]="to?.showValidationErrorOn || dynamicFormComponent?.showValidationErrorsOn"+ [attr.data-qa-field-name]="to?.property"+>+ <ng-container #fieldComponent slot="input"></ng-container>++ <formly-validation-message+ class="op-form-field--error"+ [field]="field"+ slot="errors"+ ></formly-validation-message>+</op-checkbox-field>diff --git a/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.component.html b/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.component.htmlnew file mode 100644index 00000000000..28c4bf069c4--- /dev/null+++ b/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.component.html@@ -0,0 +1,42 @@+<ng-container *ngIf="!hidden">+ <label class="op-form-field--label-wrap op-checkbox-field--label-wrap">+ <div+ class="op-form-field--input op-checkbox-field--input"+ [attr.aria-describedby]="describedByID"+ >+ <ng-content select="[slot=input]"></ng-content>+ </div>++ <div class="op-form-field--label op-checkbox-field--label">+ <span+ *ngIf="showErrorMessage"+ class="Hidden for sighted"+ >Invalid</span>+ {{ label }}+ <span *ngIf="required" class="op-form-field--label-indicator">*</span>+ <attribute-help-text+ [attribute]="helpTextAttribute"+ [attributeScope]="helpTextAttributeScope"+ ></attribute-help-text>+ </div>++ <div+ class="op-form-field--description op-checkbox-field--description"+ [id]="descriptionID"+ >+ <ng-content select="[slot=description]"></ng-content>+ </div>+ </label>++ <div class="op-form-field--help-text">+ <ng-content select="[slot=help-text]"></ng-content>+ </div>++ <div+ class="op-form-field--errors"+ *ngIf="showErrorMessage"+ [id]="errorsID"+ >+ <ng-content select="[slot=errors]"></ng-content>+ </div>+</ng-container>diff --git a/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.component.ts b/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.component.tsnew file mode 100644index 00000000000..2d3a23ec9ef--- /dev/null+++ b/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.component.ts@@ -0,0 +1,72 @@+import {+ Component, ContentChild, HostBinding, Input, Optional,+} from '@angular/core';+import { AbstractControl, FormGroupDirective, NgControl } from '@angular/forms';++@Component({+ selector: 'op-checkbox-field',+ templateUrl: './checkbox-field.component.html',+})+export class OpCheckboxFieldComponent {+ @HostBinding('class.op-form-field') className = true;++ @HostBinding('class.op-checkbox-field') classNameCheckbox = true;++ @HostBinding('class.op-form-field_invalid') get errorClassName() {+ return this.showErrorMessage;+ }++ @Input() label = '';++ @Input() hidden = false;++ @Input() required = false;++ @Input() showValidationErrorOn:'change' | 'blur' | 'submit' | 'never' = 'submit';++ @Input() control?:AbstractControl;++ @Input() helpTextAttribute?:string;++ @Input() helpTextAttributeScope?:string;++ @ContentChild(NgControl) ngControl:NgControl;++ internalID = `op-checkbox-field-${+new Date()}`;++ get errorsID() {+ return `${this.internalID}-errors`;+ }++ get descriptionID() {+ return `${this.internalID}-description`;+ }++ get describedByID() {+ return this.showErrorMessage ? this.errorsID : this.descriptionID;+ }++ get formControl():AbstractControl|undefined|null {+ return this.ngControl?.control || this.control;+ }++ get showErrorMessage():boolean {+ if (!this.formControl) {+ return false;+ }++ if (this.showValidationErrorOn === 'submit') {+ return this.formControl.invalid && this._formGroupDirective?.submitted;+ } if (this.showValidationErrorOn === 'blur') {+ return this.formControl.invalid && this.formControl.touched;+ } if (this.showValidationErrorOn === 'change') {+ return this.formControl.invalid && this.formControl.dirty;+ }++ return false;+ }++ constructor(+ @Optional() private _formGroupDirective:FormGroupDirective,+ ) {}+}diff --git a/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.sass b/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.sassnew file mode 100644index 00000000000..b13c14eb78b--- /dev/null+++ b/frontend/src/app/shared/components/forms/checkbox-field/checkbox-field.sass@@ -0,0 +1,28 @@+.op-checkbox-field+ &--label-wrap+ display: grid+ grid-template-columns: auto 1fr+ grid-template-rows: auto auto++ &--input+ grid-column-start: 1+ grid-column-end: 2+ grid-row-start: 1+ grid-row-end: 3+ padding-right: 1rem+ padding-top: 0.2rem++ &--label+ grid-column-start: 2+ grid-column-end: 2+ grid-row-start: 1+ grid-row-end: 2+ margin-bottom: 0++ &--description+ grid-column-start: 2+ grid-column-end: 2+ grid-row-start: 2+ grid-row-end: 3+ margin-bottom: 0+diff --git a/frontend/src/app/shared/components/forms/form-field/form-field.component.ts b/frontend/src/app/shared/components/forms/form-field/form-field.component.tsindex 1f374d89b00..3af606f09fa 100644--- a/frontend/src/app/shared/components/forms/form-field/form-field.component.ts+++ b/frontend/src/app/shared/components/forms/form-field/form-field.component.ts@@ -14,18 +14,12 @@ export class OpFormFieldComponent {return this.showErrorMessage;}- @HostBinding('class.op-form-field_checkbox') get checkboxClassName() {- return this.checkbox;- }-@Input() label = '';@Input() noWrapLabel = false;@Input() required = false;- @Input() checkbox = false;-@Input() hidden = false;@Input() showValidationErrorOn:'change' | 'blur' | 'submit' | 'never' = 'submit';diff --git a/frontend/src/app/shared/components/forms/form-field/form-field.sass b/frontend/src/app/shared/components/forms/form-field/form-field.sassindex 1cd3a42f313..50f178df615 100644--- a/frontend/src/app/shared/components/forms/form-field/form-field.sass+++ b/frontend/src/app/shared/components/forms/form-field/form-field.sass@@ -20,7 +20,7 @@margin: 0&--label- font-size: 14px+ font-size: 1remfont-weight: boldline-height: 1.2@@ -48,19 +48,3 @@&--errors&:emptydisplay: none-- // Checkbox mode- $off: &- &_checkbox- #{$off}--label-wrap- flex-direction: row- flex-wrap: wrap-- #{$off}--input- order: 1- margin-right: 1rem- #{$off}--label- order: 2- #{$off}--description- order: 3-diff --git a/frontend/src/app/shared/components/forms/index.sass b/frontend/src/app/shared/components/forms/index.sassindex f67b666db2d..406b7ebdd2d 100644--- a/frontend/src/app/shared/components/forms/index.sass+++ b/frontend/src/app/shared/components/forms/index.sass@@ -1,4 +1,5 @@@import './form-field/form-field'+@import './checkbox-field/checkbox-field'@import './form'@import './fieldset'@import './highlighted-input'diff --git a/frontend/src/app/shared/components/table/table.sass b/frontend/src/app/shared/components/table/table.sassindex 67df3dfa0a1..d4f2d69e7b3 100644--- a/frontend/src/app/shared/components/table/table.sass+++ b/frontend/src/app/shared/components/table/table.sass@@ -15,3 +15,5 @@&_soft-headingbackground-color: transparent+ text-align: left+ font-weight: normaldiff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.tsindex 8644d227b5a..528576d3484 100644--- a/frontend/src/app/shared/shared.module.ts+++ b/frontend/src/app/shared/shared.module.ts@@ -69,6 +69,7 @@ import { RemoteFieldUpdaterComponent } from './components/remote-field-updater/rimport { ShowSectionDropdownComponent } from './components/hide-section/show-section-dropdown.component';import { SlideToggleComponent } from './components/slide-toggle/slide-toggle.component';import { DynamicBootstrapModule } from './components/dynamic-bootstrap/dynamic-bootstrap.module';+import { OpCheckboxFieldComponent } from './components/forms/checkbox-field/checkbox-field.component';import { OpFormFieldComponent } from './components/forms/form-field/form-field.component';import { OpPopoutComponent } from './components/popout/popout.component';import { OpFormBindingDirective } from './components/forms/form-field/form-binding.directive';@@ -171,7 +172,7 @@ export function bootstrapModule(injector:Injector) {SlideToggleComponent,- // Autocompleter+ OpCheckboxFieldComponent,OpFormFieldComponent,OpFormBindingDirective,OpOptionListComponent,@@ -225,6 +226,7 @@ export function bootstrapModule(injector:Injector) {// filterSlideToggleComponent,+ OpCheckboxFieldComponent,OpFormFieldComponent,OpFormBindingDirective,OpOptionListComponent,