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

Dynamic form, project component type improvements

Alexander Brandon Colesd36c9f38dcb8
diff --git a/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts b/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts
index b20ce6bb486..8ae7e9eb437 100644
--- a/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts
+++ b/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts
@@ -103,9 +103,9 @@ export class CopyProjectComponent extends UntilDestroyedMixin implements OnInit
return false;
}
- const nameOrParent = ['name', 'parent'].includes(templateOptions.property as string);
+ const nameOrParent = ['name', 'parent'].includes(templateOptions.property!);
const noPayload = templateOptions.payloadValue == null
- || (templateOptions.payloadValue as { href?:string|null })?.href == null;
+ || templateOptions.payloadValue?.href == null;
return (templateOptions.required && !templateOptions.hasDefault && noPayload) || nameOrParent;
}
diff --git a/frontend/src/app/features/projects/components/new-project/new-project.component.ts b/frontend/src/app/features/projects/components/new-project/new-project.component.ts
index f5b496b384a..8092274bf64 100644
--- a/frontend/src/app/features/projects/components/new-project/new-project.component.ts
+++ b/frontend/src/app/features/projects/components/new-project/new-project.component.ts
@@ -175,9 +175,9 @@ export class NewProjectComponent extends UntilDestroyedMixin implements OnInit {
return false;
}
- const nameOrParent = ['name', 'parent'].includes(templateOptions.property as string);
+ const nameOrParent = ['name', 'parent'].includes(templateOptions.property!);
const noPayload = templateOptions.payloadValue == null
- || (templateOptions.payloadValue as { href?:string|null })?.href == null;
+ || templateOptions.payloadValue?.href == null;
return (templateOptions.required && !templateOptions.hasDefault && noPayload) || nameOrParent;
}
diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-form/dynamic-form.component.spec.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-form/dynamic-form.component.spec.ts
index 2f9f85a1aa2..f169bdef59c 100644
--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-form/dynamic-form.component.spec.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-form/dynamic-form.component.spec.ts
@@ -41,6 +41,7 @@ import { SpotFormFieldComponent } from 'core-app/spot/components/form-field/form
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { DynamicFieldWrapperComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-field-wrapper/dynamic-field-wrapper.component';
import { ConfirmDialogService } from "core-app/shared/components/modals/confirm-dialog/confirm-dialog.service";
+import { IOPDynamicFormSettings } from 'core-app/shared/components/dynamic-forms/typings';
@Component({
template: `
@@ -112,7 +113,7 @@ describe('DynamicFormComponent', () => {
},
},
};
- const dynamicFormSettings:any = {
+ const dynamicFormSettings:IOPDynamicFormSettings = {
fields: [
{
type: 'textInput',
diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.spec.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.spec.ts
index 6c75036d2cc..0b5bcab1455 100644
--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.spec.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.spec.ts
@@ -3,12 +3,13 @@ import {
createDynamicInputFixture,
testDynamicInputControValueAccessor,
} from 'core-app/shared/components/dynamic-forms/spec/helpers';
+import { IOPFormlyFieldSettings } from 'core-app/shared/components/dynamic-forms/typings';
describe('BooleanInputComponent', () => {
it('should load the field', fakeAsync(() => {
- const fieldsConfig = [
+ const fieldsConfig:IOPFormlyFieldSettings[] = [
{
- type: 'booleanInput' as const,
+ type: 'booleanInput',
key: 'testControl',
templateOptions: {
required: true,
@@ -16,7 +17,7 @@ describe('BooleanInputComponent', () => {
},
},
];
- const formModel = {
+ const formModel:IOPFormModel = {
testControl: true,
};
const testModel = {
diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/components/formattable-control/formattable-control.component.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/components/formattable-control/formattable-control.component.ts
index 5a9ef021fd0..f6ec6c3d48f 100644
--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/components/formattable-control/formattable-control.component.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/components/formattable-control/formattable-control.component.ts
@@ -1,13 +1,12 @@
import { Component, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { FormlyTemplateOptions } from '@ngx-formly/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { OpCkeditorComponent } from 'core-app/shared/components/editor/components/ckeditor/op-ckeditor.component';
import {
ICKEditorContext,
ICKEditorInstance,
} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';
-import { ICKEditorType } from 'core-app/shared/components/editor/components/ckeditor/ckeditor-setup.service';
+import { IOPFormlyTemplateOptions } from 'core-app/shared/components/dynamic-forms/typings';
@Component({
selector: 'op-formattable-control',
@@ -22,7 +21,7 @@ import { ICKEditorType } from 'core-app/shared/components/editor/components/cked
],
})
export class FormattableControlComponent implements ControlValueAccessor, OnInit {
- @Input() templateOptions:FormlyTemplateOptions;
+ @Input() templateOptions:IOPFormlyTemplateOptions;
@ViewChild(OpCkeditorComponent, { static: true }) editor:OpCkeditorComponent;
@@ -43,13 +42,13 @@ export class FormattableControlComponent implements ControlValueAccessor, OnInit
public get ckEditorContext():ICKEditorContext {
return {
- type: this.templateOptions.editorType as ICKEditorType,
- field: this.templateOptions.name as string,
+ type: this.templateOptions.editorType!,
+ field: this.templateOptions.name,
// This is a very project resource specific hack to allow macros on description and statusExplanation but
// disable it for custom fields. As the formly based approach is currently limited to projects, and that is to be removed,
// such a "pragmatic" approach should be ok.
- macros: (this.templateOptions.property as string).startsWith('customField') ? 'none' : 'resource',
- options: { rtl: this.templateOptions?.rtl },
+ macros: this.templateOptions.property?.startsWith('customField') ? 'none' : 'resource',
+ options: { rtl: this.templateOptions.rtl },
};
}
@@ -61,8 +60,8 @@ export class FormattableControlComponent implements ControlValueAccessor, OnInit
ngOnInit():void {
this.text = {
attachmentLabel: this.I18n.t('js.label_formattable_attachment_hint'),
- save: this.I18n.t('js.inplace.button_save', { attribute: this.templateOptions?.name }),
- cancel: this.I18n.t('js.inplace.button_cancel', { attribute: this.templateOptions?.name }),
+ save: this.I18n.t('js.inplace.button_save', { attribute: this.templateOptions.name }),
+ cancel: this.I18n.t('js.inplace.button_cancel', { attribute: this.templateOptions.name }),
};
}
diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.spec.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.spec.ts
index 5e3e527cc69..59228b4d185 100644
--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.spec.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.spec.ts
@@ -1,12 +1,13 @@
import { discardPeriodicTasks, fakeAsync, flush, tick } from '@angular/core/testing';
import { createDynamicInputFixture } from 'core-app/shared/components/dynamic-forms/spec/helpers';
import { By } from '@angular/platform-browser';
+import { IOPFormlyFieldSettings } from 'core-app/shared/components/dynamic-forms/typings';
describe('FormattableTextareaInputComponent', () => {
it('should load the field', fakeAsync(() => {
- const fieldsConfig = [
+ const fieldsConfig:IOPFormlyFieldSettings[] = [
{
- type: 'formattableInput' as const,
+ type: 'formattableInput',
key: 'testControl',
templateOptions: {
required: true,
@@ -17,10 +18,11 @@ describe('FormattableTextareaInputComponent', () => {
bindLabel: 'name',
bindValue: 'value',
noWrapLabel: true,
+ editorType: 'full'
},
},
];
- const formModel = {
+ const formModel:IOPFormModel = {
testControl: {
html: '<p>tesValue</p>',
raw: 'tesValue',
diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.spec.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.spec.ts
index a7f45e259d0..ba71742457b 100644
--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.spec.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.spec.ts
@@ -3,12 +3,13 @@ import {
createDynamicInputFixture,
testDynamicInputControValueAccessor,
} from 'core-app/shared/components/dynamic-forms/spec/helpers';
+import { IOPFormlyFieldSettings } from 'core-app/shared/components/dynamic-forms/typings';
describe('IntegerInputComponent', () => {
it('should load the field', fakeAsync(() => {
- const fieldsConfig = [
+ const fieldsConfig:IOPFormlyFieldSettings[] = [
{
- type: 'integerInput' as const,
+ type: 'integerInput',
key: 'testControl',
templateOptions: {
required: true,
@@ -16,7 +17,7 @@ describe('IntegerInputComponent', () => {
},
},
];
- const formModel = {
+ const formModel:IOPFormModel = {
testControl: 'testValue',
};
const testModel = {
diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.spec.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.spec.ts
index 781f645b83c..9169a7fb236 100644
--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.spec.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.spec.ts
@@ -2,6 +2,7 @@ import { fakeAsync, flush } from '@angular/core/testing';
import { createDynamicInputFixture } from 'core-app/shared/components/dynamic-forms/spec/helpers';
import { By } from '@angular/platform-browser';
import { of } from 'rxjs';
+import { IOPFormlyFieldSettings } from 'core-app/shared/components/dynamic-forms/typings';
describe('SelectInputComponent', () => {
it('should load the field', fakeAsync(() => {
@@ -15,9 +16,9 @@ describe('SelectInputComponent', () => {
value: 2,
},
];
- const fieldsConfig = [
+ const fieldsConfig:IOPFormlyFieldSettings[] = [
{
- type: 'selectInput' as const,
+ type: 'selectInput',
key: 'testControl',
templateOptions: {
required: true,
@@ -31,7 +32,7 @@ describe('SelectInputComponent', () => {
},
},
];
- const formModel = {
+ const formModel:IOPFormModel = {
testControl: selectOptions[0],
};
const testModel = {
diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.spec.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.spec.ts
index f7e43423184..83ea9ce9e42 100644
--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.spec.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.spec.ts
@@ -3,12 +3,13 @@ import {
createDynamicInputFixture,
testDynamicInputControValueAccessor,
} from 'core-app/shared/components/dynamic-forms/spec/helpers';
+import { IOPFormlyFieldSettings } from 'core-app/shared/components/dynamic-forms/typings';
describe('TextInputComponent', () => {
it('should load the field', fakeAsync(() => {
- const fieldsConfig = [
+ const fieldsConfig:IOPFormlyFieldSettings[] = [
{
- type: 'textInput' as const,
+ type: 'textInput',
key: 'testControl',
templateOptions: {
required: true,
@@ -19,7 +20,7 @@ describe('TextInputComponent', () => {
},
},
];
- const formModel = {
+ const formModel:IOPFormModel = {
testControl: 'testValue',
};
const testModel = {
diff --git a/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.spec.ts b/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.spec.ts
index 15e772f2cef..7e2b93fff83 100644
--- a/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.spec.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.spec.ts
@@ -29,7 +29,7 @@ describe('DynamicFieldsService', () => {
});
it('should generate a proper dynamic form schema', () => {
- const formPayload = {
+ const formPayload:IOPFormModel = {
name: 'Project 1',
_links: {
parent: {
@@ -38,7 +38,7 @@ describe('DynamicFieldsService', () => {
},
},
};
- const formSchema = {
+ const formSchema:IOPFormSchema = {
name: {
type: 'String',
name: 'Name',
@@ -82,7 +82,7 @@ describe('DynamicFieldsService', () => {
});
it('should format the form model (add the name property to resources (_links: single and multiple))', () => {
- const formPayload = {
+ const formPayload:IOPFormModel = {
title: 'Project 1',
_links: {
parent: {
@@ -101,7 +101,7 @@ describe('DynamicFieldsService', () => {
],
},
};
- const formSchema = {
+ const formSchema:IOPFormSchema = {
title: {
type: 'String',
name: 'Name',
@@ -152,7 +152,7 @@ describe('DynamicFieldsService', () => {
});
it('should generate a proper dynamic form config', () => {
- const formPayload = {
+ const formPayload:IOPFormModel = {
name: 'Project 1',
_links: {
parent: {
@@ -161,7 +161,7 @@ describe('DynamicFieldsService', () => {
},
},
};
- const formSchema = {
+ const formSchema:IOPFormSchema = {
parent: {
type: 'Project',
name: 'Subproject of',
@@ -197,7 +197,7 @@ describe('DynamicFieldsService', () => {
};
// @ts-ignore
const formlyConfig = service.getConfig(formSchema, formPayload);
- const formlyFields = formlyConfig.reduce((result, formlyField) => (formlyField.fieldGroup ? [...result, ...formlyField.fieldGroup] : [...result, formlyField]), [] as IOPFormlyFieldSettings[]);
+ const formlyFields = formlyConfig.reduce((result:IOPFormSettings[], formlyField) => (formlyField.fieldGroup ? [...result, ...formlyField.fieldGroup] : [...result, formlyField]), []);
const formGroup = formlyConfig[1];
expect(formlyFields[1].templateOptions!.label).toBe('Name', 'should set the correct label');
diff --git a/frontend/src/app/shared/components/dynamic-forms/spec/helpers.ts b/frontend/src/app/shared/components/dynamic-forms/spec/helpers.ts
index 8b371ca9185..d74ed574b39 100644
--- a/frontend/src/app/shared/components/dynamic-forms/spec/helpers.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/spec/helpers.ts
@@ -59,7 +59,7 @@ const ickEditorWatchdogStub:ICKEditorWatchdog = {
state: 'ready'
}
-export function createDynamicInputFixture(fields:IOPFormlyFieldSettings[], model:any, providers?:any[]):ComponentFixture<any> {
+export function createDynamicInputFixture(fields:IOPFormlyFieldSettings[], model:IOPFormModel, providers?:any[]):ComponentFixture<any> {
@Component({
template: `
<form [formGroup]="form">
diff --git a/frontend/src/app/shared/components/dynamic-forms/typings.d.ts b/frontend/src/app/shared/components/dynamic-forms/typings.d.ts
index e499e2f1c67..f6a5a3bf186 100644
--- a/frontend/src/app/shared/components/dynamic-forms/typings.d.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/typings.d.ts
@@ -1,5 +1,6 @@
-import { FormlyFieldConfig, FormlyTemplateOptions } from '@ngx-formly/core';
+import { FormlyFieldConfig, FormlyFieldProps } from '@ngx-formly/core';
import { FormGroup } from '@angular/forms';
+import { ICKEditorType } from '../editor/components/ckeditor/ckeditor-setup.service';
export interface IOPDynamicFormSettings {
fields:IOPFormlyFieldSettings[];
@@ -15,9 +16,10 @@ export interface IOPFormlyFieldSettings extends FormlyFieldConfig {
[key:string]:any;
}
-export interface IOPFormlyTemplateOptions extends FormlyTemplateOptions {
+export interface IOPFormlyTemplateOptions extends FormlyFieldProps {
+ type?:'checkbox' | 'number' | 'password' | 'selectInput' | 'text';
+ name?:string;
property?:string;
- label?:string;
hasDefault?:boolean;
fieldGroup?:string;
isFieldGroup?:boolean;
@@ -25,6 +27,23 @@ export interface IOPFormlyTemplateOptions extends FormlyTemplateOptions {
collapsibleFieldGroupsCollapsed?:boolean;
helpTextAttributeScope?:string;
showValidationErrorOn?:'change' | 'blur' | 'submit' | 'never';
+ payloadValue?:{ href?:string|null };
+ rtl?:boolean;
+ locale?:string;
+ bindLabel?:string;
+ bindValue?:string;
+ searchable?:boolean;
+ editorType?:ICKEditorType;
+ noWrapLabel?:boolean;
+ virtualScroll?:boolean;
+ clearOnBackspace?:boolean;
+ clearSearchOnAdd?:boolean;
+ hideSelected?:boolean;
+ text?:Record<string, string>;
+ typeahead?:boolean;
+ inlineLabel?:boolean;
+ clearable?:boolean;
+ multiple?:boolean;
}
type OPInputType = 'formattableInput'|'selectInput'|'textInput'|'integerInput'|