From 764ad4a0c0c0ec3e2e5bf15ece8adce80362a966 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 19 Nov 2020 18:29:40 +0100 Subject: [PATCH] fix update of @ng-dynamic-forms libs --- .../models/disabled/dynamic-disabled.model.ts | 2 +- .../models/ds-dynamic-concat.model.ts | 8 ++++---- .../models/dynamic-vocabulary.component.ts | 2 +- .../models/list/dynamic-list-radio-group.model.ts | 2 +- .../models/list/dynamic-list.component.ts | 2 +- .../models/lookup/dynamic-lookup.model.ts | 2 +- .../dynamic-relation-group.components.ts | 8 ++++---- .../relation-group/dynamic-relation-group.model.ts | 11 +++++------ .../models/tag/dynamic-tag.model.ts | 2 +- .../sections/license/section-license.component.ts | 10 +++------- 10 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.model.ts index 5eb9aa8dd2..42e6917323 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.model.ts @@ -23,6 +23,6 @@ export class DynamicDisabledModel extends DsDynamicInputModel { this.disabled = true; this.hasSelectableMetadata = config.hasSelectableMetadata; - this.valueUpdates.next(config.value); + this.value = config.value; } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-concat.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-concat.model.ts index 7d4b58c95d..1c568dbd32 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-concat.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-concat.model.ts @@ -89,14 +89,14 @@ export class DynamicConcatModel extends DynamicFormGroupModel { Object.assign(new FormFieldMetadataValueObject(), value, { display: v, value: v })); if (values[0].value) { - (this.get(0) as DsDynamicInputModel).valueUpdates.next(values[0]); + (this.get(0) as DsDynamicInputModel).value = values[0]; } else { - (this.get(0) as DsDynamicInputModel).valueUpdates.next(undefined); + (this.get(0) as DsDynamicInputModel).value = undefined; } if (values[1].value) { - (this.get(1) as DsDynamicInputModel).valueUpdates.next(values[1]); + (this.get(1) as DsDynamicInputModel).value = values[1]; } else { - (this.get(1) as DsDynamicInputModel).valueUpdates.next(undefined); + (this.get(1) as DsDynamicInputModel).value = undefined; } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-vocabulary.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-vocabulary.component.ts index 8f7ca5edf1..77a4ab5ad0 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-vocabulary.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-vocabulary.component.ts @@ -113,7 +113,7 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom * @param updateValue */ dispatchUpdate(updateValue: any) { - this.model.valueUpdates.next(updateValue); + this.model.value = updateValue; this.change.emit(updateValue); } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-radio-group.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-radio-group.model.ts index a4a0fb7749..6f51eed2ac 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-radio-group.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-radio-group.model.ts @@ -27,7 +27,7 @@ export class DynamicListRadioGroupModel extends DynamicRadioGroupModel { this.vocabularyOptions = config.vocabularyOptions; this.groupLength = config.groupLength || 5; this.repeatable = config.repeatable; - this.valueUpdates.next(config.value); + this.value = config.value; } get hasAuthority(): boolean { diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts index ad305cb17a..e7f9f83e47 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts @@ -99,7 +99,7 @@ export class DsDynamicListComponent extends DynamicFormControlComponent implemen this.model.valueUpdates.next(newValue); } } else { - (this.model as DynamicListRadioGroupModel).valueUpdates.next(this.optionsList[target.value]); + (this.model as DynamicListRadioGroupModel).value = this.optionsList[target.value]; } this.change.emit(event); } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.model.ts index e14dedb2ac..3d3a91d3d9 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.model.ts @@ -21,6 +21,6 @@ export class DynamicLookupModel extends DsDynamicInputModel { this.autoComplete = AUTOCOMPLETE_OFF; this.maxOptions = config.maxOptions || 10; - this.valueUpdates.next(config.value); + this.value = config.value; } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.components.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.components.ts index 4b66d3f789..e3a696c3e7 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.components.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.components.ts @@ -74,7 +74,7 @@ export class DsDynamicRelationGroupComponent extends DynamicFormControlComponent if (!this.model.isEmpty()) { this.formCollapsed = observableOf(true); } - this.model.valueUpdates.subscribe((value: any[]) => { + this.model.valueChanges.subscribe((value: any[]) => { if ((isNotEmpty(value) && !(value.length === 1 && hasOnlyEmptyProperties(value[0])))) { this.collapseForm(); } else { @@ -124,7 +124,7 @@ export class DsDynamicRelationGroupComponent extends DynamicFormControlComponent const nextValue = (this.formBuilderService.isInputModel(model) && isNotNull(value) && (typeof value !== 'string')) ? value.value : value; - model.valueUpdates.next(nextValue); + model.value = nextValue; }); }); @@ -276,7 +276,7 @@ export class DsDynamicRelationGroupComponent extends DynamicFormControlComponent }, []), filter((modelValues: any[]) => this.model.value.length === modelValues.length) ).subscribe((modelValue) => { - this.model.valueUpdates.next(modelValue); + this.model.value = modelValue; this.initChips(modelValue); this.cdr.markForCheck(); })); @@ -296,7 +296,7 @@ export class DsDynamicRelationGroupComponent extends DynamicFormControlComponent // Does not emit change if model value is equal to the current value if (!isEqual(items, this.model.value)) { if (!(isEmpty(items) && this.model.isEmpty())) { - this.model.valueUpdates.next(items); + this.model.value = items; this.change.emit(); } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model.ts index afa03a8e4e..bfc3017412 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model.ts @@ -26,7 +26,6 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel { @serializable() relationFields: string[]; @serializable() scopeUUID: string; @serializable() submissionScope: string; - @serializable() _value: any[]; @serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP; constructor(config: DynamicRelationGroupModelConfig, layout?: DynamicFormControlLayout) { @@ -39,15 +38,15 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel { this.scopeUUID = config.scopeUUID; this.submissionScope = config.submissionScope; const value = config.value || []; - this.valueUpdates.next(value); + this.value = value; } get value() { - return this._value + return this.value } set value(value) { - this._value = (isEmpty(value)) ? null : value; + this.value = (isEmpty(value)) ? null : value; } isEmpty() { @@ -56,7 +55,7 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel { } getGroupValue(): any[] { - if (isEmpty(this._value)) { + if (isEmpty(this.value)) { // If items is empty, last element has been removed // so emit an empty value that allows to dispatch // a remove JSON PATCH operation @@ -68,6 +67,6 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel { }); return [emptyItem]; } - return this._value + return this.value } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.model.ts index dfc350bd2f..50a40fc2f6 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.model.ts @@ -21,7 +21,7 @@ export class DynamicTagModel extends DsDynamicInputModel { this.autoComplete = AUTOCOMPLETE_OFF; this.minChars = config.minChars || 3; const value = config.value || []; - this.valueUpdates.next(value); + this.value = value; } } diff --git a/src/app/submission/sections/license/section-license.component.ts b/src/app/submission/sections/license/section-license.component.ts index 1132d68502..00af9f9774 100644 --- a/src/app/submission/sections/license/section-license.component.ts +++ b/src/app/submission/sections/license/section-license.component.ts @@ -127,11 +127,7 @@ export class SubmissionSectionLicenseComponent extends SectionModelComponent { const model = this.formBuilderService.findById('granted', this.formModel); // Retrieve license accepted status - if ((this.sectionData.data as WorkspaceitemSectionLicenseObject).granted) { - (model as DynamicCheckboxModel).valueUpdates.next(true); - } else { - (model as DynamicCheckboxModel).valueUpdates.next(false); - } + (model as DynamicCheckboxModel).value = (this.sectionData.data as WorkspaceitemSectionLicenseObject).granted; this.licenseText$ = this.collectionDataService.findById(this.collectionId, followLink('license')).pipe( filter((collectionData: RemoteData) => isNotUndefined((collectionData.payload))), @@ -149,7 +145,7 @@ export class SubmissionSectionLicenseComponent extends SectionModelComponent { take(1), filter((isReadOnly) => isReadOnly)) .subscribe(() => { - model.disabledUpdates.next(true); + model.disabled = true; }), this.sectionService.getSectionErrors(this.submissionId, this.sectionData.id).pipe( @@ -192,7 +188,7 @@ export class SubmissionSectionLicenseComponent extends SectionModelComponent { */ protected getSectionStatus(): Observable { const model = this.formBuilderService.findById('granted', this.formModel); - return (model as DynamicCheckboxModel).valueUpdates.pipe( + return (model as DynamicCheckboxModel).valueChanges.pipe( map((value) => value === true), startWith((model as DynamicCheckboxModel).value)); }