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
Improvements to dynamic form handling
Benjamin Bädorf3efb9a99ce59
diff --git a/frontend/src/app/features/invite-user-modal/invite-user.component.ts b/frontend/src/app/features/invite-user-modal/invite-user.component.tsindex 144e510815a..8f3b1e6f5aa 100644--- a/frontend/src/app/features/invite-user-modal/invite-user.component.ts+++ b/frontend/src/app/features/invite-user-modal/invite-user.component.ts@@ -93,7 +93,7 @@ export class InviteUserModalComponent extends OpModalComponent implements OnInit}}- onProjectSelectionSave({ type, project }:{ type:PrincipalType, project:any }) {+ onProjectSelectionSave({ type, project }:{ type:PrincipalType, project:ProjectResource|null }) {this.type = type;this.project = project;this.goTo(Steps.Principal);diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.tsindex 0084138fe77..d58b18064fd 100644--- a/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.ts+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.ts@@ -1,6 +1,6 @@import { AbstractControl } from '@angular/forms';import { of } from 'rxjs';-import { catchError, map, take } from 'rxjs/operators';+import { catchError, map } from 'rxjs/operators';import { CurrentUserService } from 'core-app/core/current-user/current-user.service';import idFromLink from 'core-app/features/hal/helpers/id-from-link';@@ -10,7 +10,6 @@ export const ProjectAllowedValidator = (currentUserService:CurrentUserService) ='memberships/create',idFromLink(control.value.href)).pipe(- take(1),map((isAllowed) => (isAllowed ? null : { lackingPermission: true })),catchError(() => of(null)),);diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.htmlindex 31d9500e7ff..60f0e29d777 100644--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html@@ -10,8 +10,8 @@required><op-project-autocompleter- formControlName="project"slot="input"+ formControlName="project"[APIFilters]="APIFiltersForProjects"[mapResultsFn]="projectFilterFn.bind(this)"></op-project-autocompleter>diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.tsindex a3e0497f4a3..33e2ef6cef3 100644--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts@@ -21,6 +21,8 @@ import { ProjectAllowedValidator } from './project-allowed.validator';import { map } from 'rxjs/operators';import { CapabilityResource } from 'core-app/features/hal/resources/capability-resource';import { IProjectAutocompleteItem } from 'core-app/shared/components/autocompleter/project-autocompleter/project-autocomplete-item';+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';+import idFromLink from 'core-app/features/hal/helpers/id-from-link';@Component({selector: 'op-ium-project-selection',@@ -34,7 +36,7 @@ export class ProjectSelectionComponent implements OnInit {@Output() close = new EventEmitter<void>();- @Output() save = new EventEmitter<{ project:any, type:string }>();+ @Output() save = new EventEmitter<{ project:ProjectResource|null, type:string }>();public text = {title: this.I18n.t('js.invite_user_modal.title.invite'),@@ -82,12 +84,16 @@ export class ProjectSelectionComponent implements OnInit {readonly I18n:I18nService,readonly elementRef:ElementRef,readonly bannersService:BannersService,+ readonly apiV3Service:ApiV3Service,readonly currentUserService:CurrentUserService,) {}ngOnInit() {this.typeControl?.setValue(this.type);- this.projectControl?.setValue(this.project);++ if (this.project) {+ this.projectControl?.setValue({ ...this.project });+ }this.setPlaceholderOption();@@ -123,15 +129,18 @@ export class ProjectSelectionComponent implements OnInit {}}- onSubmit($e:Event) {+ async onSubmit($e:Event) {$e.preventDefault();if (this.projectAndTypeForm.invalid) {this.projectAndTypeForm.markAsDirty();return;}+ const projectId = idFromLink(this.projectControl?.value.href);+ const project = await this.apiV3Service.projects.id(projectId).get().toPromise();+this.save.emit({- project: this.projectControl?.value,+ project,type: this.typeControl?.value,});}@@ -139,11 +148,14 @@ export class ProjectSelectionComponent implements OnInit {APIFiltersForProjects = [['active', '=', true]];projectFilterFn(projects:IProjectAutocompleteItem[]):IProjectAutocompleteItem[] {- const mapped = projects.map((project) => ({- ...project,- disabled: !this.projectInviteCapabilities.find((cap) => cap.context.id === project.id),- disabledReason: this.text.project.noInviteRights,- }));+ const mapped = projects.map((project) => {+ const disabled = !this.projectInviteCapabilities.find((cap) => parseInt(cap.context.id, 10) === project.id);+ return {+ ...project,+ disabled,+ disabledReason: disabled ? this.text.project.noInviteRights : '',+ };+ });mapped.sort((a, b) => (a.disabled ? 1 : 0) - (b.disabled ? 1 : 0),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 4658f44ec4d..63e46d8c027 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@@ -7,7 +7,6 @@ import {} from '@angular/core';import { FormArray } from '@angular/forms';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { Observable } from 'rxjs';import { HalSourceLink } from 'core-app/features/hal/resources/hal-resource';import { IProjectAutocompleteItem } from 'core-app/shared/components/autocompleter/project-autocompleter/project-autocomplete-item';@@ -39,9 +38,7 @@ export class NotificationSettingInlineCreateComponent {};public get APIFilters() {- return [- ['visible', '=', [this.userId]],- ];+ return [['visible', '=', [this.userId]]];}constructor(diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.htmlindex eab086f8be6..22800a06121 100644--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html@@ -21,7 +21,7 @@[name]="name"[id]="id"[attr.accesskey]="accesskey||undefined"- bindLabel="name"+ [bindLabel]="bindLabel"[bindValue]="bindValue"[markFirst]="markFirst"[notFoundText]="notFoundText"@@ -194,4 +194,4 @@[ngOptionHighlight]="search"class="ng-value-label">{{item.name}}</span></ng-container>-</ng-template>\ No newline at end of file+</ng-template>diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.tsindex b1103c030c2..1bd5d48d714 100644--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts@@ -58,6 +58,12 @@ import { ID } from '@datorama/akita';export const projectsAutocompleterSelector = 'op-project-autocompleter';+export interface IProjectAutocompleterData {+ id:ID;+ href:string;+ name:string;+};+@Component({templateUrl: './project-autocompleter.component.html',selector: projectsAutocompleterSelector,@@ -91,20 +97,20 @@ export class ProjectAutocompleterComponent implements OnInit, ControlValueAccess@Input()public mapResultsFn:(projects:IProjectAutocompleteItem[]) => IProjectAutocompleteItem[] = (projects) => projects;- @Input('value') public _value:ID|null = null;+ @Input('value') public _value:IProjectAutocompleterData|null = null;- get value():ID|null {+ get value():IProjectAutocompleterData|null {return this._value;}- set value(value:ID|null) {+ set value(value:IProjectAutocompleterData|null) {this._value = value;this.onChange(value);this.changeEmitter.emit(value);this.onTouched(value);}- @Output('change') changeEmitter = new EventEmitter();+ @Output('change') changeEmitter = new EventEmitter<IProjectAutocompleterData|null>();constructor(public elementRef:ElementRef,@@ -162,19 +168,19 @@ export class ProjectAutocompleterComponent implements OnInit, ControlValueAccess);}- writeValue(value:ID|null) {+ writeValue(value:IProjectAutocompleterData|null) {this.value = value;}- onChange = (_:ID|null):void => {};+ onChange = (_:IProjectAutocompleterData|null):void => {};- onTouched = (_:ID|null):void => {};+ onTouched = (_:IProjectAutocompleterData|null):void => {};- registerOnChange(fn:(_:ID|null) => void):void {+ registerOnChange(fn:(_:IProjectAutocompleterData|null) => void):void {this.onChange = fn;}- registerOnTouched(fn:(_:ID|null) => void):void {+ registerOnTouched(fn:(_:IProjectAutocompleterData|null) => void):void {this.onTouched = fn;}}diff --git a/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.htmlindex f55499d1051..454e1f8b760 100644--- a/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.html+++ b/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.html@@ -1,15 +1,17 @@-<ng-select [items]="requests.output$ | async"- bindLabel="name"- bindValue="id"- [ngModel]="initialSelection"- [virtualScroll]="true"- [trackByFn]="userTracker"- [typeahead]="requests.input$"- [loading]="requests.loading$ | async"- (focus)="onFocus()"- (change)="onModelChange($event)"- [appendTo]="appendTo"- [multiple]="multiple" >+<ng-select+ [items]="requests.output$ | async"+ bindLabel="name"+ bindValue="id"+ [ngModel]="initialSelection"+ [virtualScroll]="true"+ [trackByFn]="userTracker"+ [typeahead]="requests.input$"+ [loading]="requests.loading$ | async"+ (focus)="onFocus()"+ (change)="onModelChange($event)"+ [appendTo]="appendTo"+ [multiple]="multiple"+><ng-template ng-option-tmp let-item="item" let-index="index"><op-principal*ngIf="item && item.href"@@ -19,4 +21,4 @@></op-principal>{{ item.name }}</ng-template>-</ng-select>\ No newline at end of file+</ng-select>diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/project-input/project-input.component.html b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/project-input/project-input.component.htmlnew file mode 100644index 00000000000..f6c5243a881--- /dev/null+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/project-input/project-input.component.html@@ -0,0 +1,6 @@+<op-project-autocompleter+ [formControl]="formControl"+ [formlyAttributes]="field"+ [attr.aria-required]="to.required"+ [attr.required]="to.required"+></op-project-autocompleter>diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/project-input/project-input.component.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/project-input/project-input.component.tsnew file mode 100644index 00000000000..ec53f023380--- /dev/null+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/project-input/project-input.component.ts@@ -0,0 +1,17 @@+import { Component, OnInit } from '@angular/core';+import { FieldType } from '@ngx-formly/core';+import idFromLink from 'core-app/features/hal/helpers/id-from-link';++@Component({+ selector: 'op-project-input',+ templateUrl: './project-input.component.html',+})+export class ProjectInputComponent extends FieldType implements OnInit {+ projectId:string|undefined;++ public ngOnInit():void {+ if (this.model?.project) {+ this.projectId = idFromLink(this.model.project?.href);+ }+ }+}diff --git a/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.ts b/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.tsindex e0516fa2925..87d619ed8cc 100644--- a/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.ts+++ b/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.ts@@ -5,10 +5,10 @@ import { NgOptionHighlightModule } from '@ng-select/ng-option-highlight';import { NgSelectModule } from '@ng-select/ng-select';import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';import { ReactiveFormsModule } from '@angular/forms';-import { ProjectAutocompleterComponent } from 'core-app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component';import { TextInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/text-input/text-input.component';import { IntegerInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component';import { SelectInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/select-input/select-input.component';+import { ProjectInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/project-input/project-input.component';import { SelectProjectStatusInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/select-project-status-input/select-project-status-input.component';import { DatePickerControlModule } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/date-input/components/date-picker-control/date-picker-control.module';import { BooleanInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component';@@ -33,7 +33,7 @@ import { OPSharedModule } from 'core-app/shared/shared.module';{ name: 'textInput', component: TextInputComponent },{ name: 'dateInput', component: DateInputComponent },{ name: 'selectInput', component: SelectInputComponent },- { name: 'projectInput', component: ProjectAutocompleterComponent },+ { name: 'projectInput', component: ProjectInputComponent },{ name: 'selectProjectStatusInput', component: SelectProjectStatusInputComponent },{ name: 'formattableInput', component: FormattableTextareaInputComponent },],@@ -67,6 +67,7 @@ import { OPSharedModule } from 'core-app/shared/shared.module';IntegerInputComponent,TextInputComponent,SelectInputComponent,+ ProjectInputComponent,SelectProjectStatusInputComponent,DateInputComponent,FormattableTextareaInputComponent,