fix update of @ng-dynamic-forms libs

This commit is contained in:
Giuseppe Digilio
2020-11-19 18:29:40 +01:00
parent 92a4b9fa78
commit 764ad4a0c0
10 changed files with 22 additions and 27 deletions

View File

@@ -23,6 +23,6 @@ export class DynamicDisabledModel extends DsDynamicInputModel {
this.disabled = true; this.disabled = true;
this.hasSelectableMetadata = config.hasSelectableMetadata; this.hasSelectableMetadata = config.hasSelectableMetadata;
this.valueUpdates.next(config.value); this.value = config.value;
} }
} }

View File

@@ -89,14 +89,14 @@ export class DynamicConcatModel extends DynamicFormGroupModel {
Object.assign(new FormFieldMetadataValueObject(), value, { display: v, value: v })); Object.assign(new FormFieldMetadataValueObject(), value, { display: v, value: v }));
if (values[0].value) { if (values[0].value) {
(this.get(0) as DsDynamicInputModel).valueUpdates.next(values[0]); (this.get(0) as DsDynamicInputModel).value = values[0];
} else { } else {
(this.get(0) as DsDynamicInputModel).valueUpdates.next(undefined); (this.get(0) as DsDynamicInputModel).value = undefined;
} }
if (values[1].value) { if (values[1].value) {
(this.get(1) as DsDynamicInputModel).valueUpdates.next(values[1]); (this.get(1) as DsDynamicInputModel).value = values[1];
} else { } else {
(this.get(1) as DsDynamicInputModel).valueUpdates.next(undefined); (this.get(1) as DsDynamicInputModel).value = undefined;
} }
} }

View File

@@ -113,7 +113,7 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
* @param updateValue * @param updateValue
*/ */
dispatchUpdate(updateValue: any) { dispatchUpdate(updateValue: any) {
this.model.valueUpdates.next(updateValue); this.model.value = updateValue;
this.change.emit(updateValue); this.change.emit(updateValue);
} }

View File

@@ -27,7 +27,7 @@ export class DynamicListRadioGroupModel extends DynamicRadioGroupModel<any> {
this.vocabularyOptions = config.vocabularyOptions; this.vocabularyOptions = config.vocabularyOptions;
this.groupLength = config.groupLength || 5; this.groupLength = config.groupLength || 5;
this.repeatable = config.repeatable; this.repeatable = config.repeatable;
this.valueUpdates.next(config.value); this.value = config.value;
} }
get hasAuthority(): boolean { get hasAuthority(): boolean {

View File

@@ -99,7 +99,7 @@ export class DsDynamicListComponent extends DynamicFormControlComponent implemen
this.model.valueUpdates.next(newValue); this.model.valueUpdates.next(newValue);
} }
} else { } else {
(this.model as DynamicListRadioGroupModel).valueUpdates.next(this.optionsList[target.value]); (this.model as DynamicListRadioGroupModel).value = this.optionsList[target.value];
} }
this.change.emit(event); this.change.emit(event);
} }

View File

@@ -21,6 +21,6 @@ export class DynamicLookupModel extends DsDynamicInputModel {
this.autoComplete = AUTOCOMPLETE_OFF; this.autoComplete = AUTOCOMPLETE_OFF;
this.maxOptions = config.maxOptions || 10; this.maxOptions = config.maxOptions || 10;
this.valueUpdates.next(config.value); this.value = config.value;
} }
} }

View File

@@ -74,7 +74,7 @@ export class DsDynamicRelationGroupComponent extends DynamicFormControlComponent
if (!this.model.isEmpty()) { if (!this.model.isEmpty()) {
this.formCollapsed = observableOf(true); 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])))) { if ((isNotEmpty(value) && !(value.length === 1 && hasOnlyEmptyProperties(value[0])))) {
this.collapseForm(); this.collapseForm();
} else { } else {
@@ -124,7 +124,7 @@ export class DsDynamicRelationGroupComponent extends DynamicFormControlComponent
const nextValue = (this.formBuilderService.isInputModel(model) && isNotNull(value) && (typeof value !== 'string')) ? const nextValue = (this.formBuilderService.isInputModel(model) && isNotNull(value) && (typeof value !== 'string')) ?
value.value : value; 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) filter((modelValues: any[]) => this.model.value.length === modelValues.length)
).subscribe((modelValue) => { ).subscribe((modelValue) => {
this.model.valueUpdates.next(modelValue); this.model.value = modelValue;
this.initChips(modelValue); this.initChips(modelValue);
this.cdr.markForCheck(); 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 // Does not emit change if model value is equal to the current value
if (!isEqual(items, this.model.value)) { if (!isEqual(items, this.model.value)) {
if (!(isEmpty(items) && this.model.isEmpty())) { if (!(isEmpty(items) && this.model.isEmpty())) {
this.model.valueUpdates.next(items); this.model.value = items;
this.change.emit(); this.change.emit();
} }
} }

View File

@@ -26,7 +26,6 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel {
@serializable() relationFields: string[]; @serializable() relationFields: string[];
@serializable() scopeUUID: string; @serializable() scopeUUID: string;
@serializable() submissionScope: string; @serializable() submissionScope: string;
@serializable() _value: any[];
@serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP; @serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP;
constructor(config: DynamicRelationGroupModelConfig, layout?: DynamicFormControlLayout) { constructor(config: DynamicRelationGroupModelConfig, layout?: DynamicFormControlLayout) {
@@ -39,15 +38,15 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel {
this.scopeUUID = config.scopeUUID; this.scopeUUID = config.scopeUUID;
this.submissionScope = config.submissionScope; this.submissionScope = config.submissionScope;
const value = config.value || []; const value = config.value || [];
this.valueUpdates.next(value); this.value = value;
} }
get value() { get value() {
return this._value return this.value
} }
set value(value) { set value(value) {
this._value = (isEmpty(value)) ? null : value; this.value = (isEmpty(value)) ? null : value;
} }
isEmpty() { isEmpty() {
@@ -56,7 +55,7 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel {
} }
getGroupValue(): any[] { getGroupValue(): any[] {
if (isEmpty(this._value)) { if (isEmpty(this.value)) {
// If items is empty, last element has been removed // If items is empty, last element has been removed
// so emit an empty value that allows to dispatch // so emit an empty value that allows to dispatch
// a remove JSON PATCH operation // a remove JSON PATCH operation
@@ -68,6 +67,6 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel {
}); });
return [emptyItem]; return [emptyItem];
} }
return this._value return this.value
} }
} }

View File

@@ -21,7 +21,7 @@ export class DynamicTagModel extends DsDynamicInputModel {
this.autoComplete = AUTOCOMPLETE_OFF; this.autoComplete = AUTOCOMPLETE_OFF;
this.minChars = config.minChars || 3; this.minChars = config.minChars || 3;
const value = config.value || []; const value = config.value || [];
this.valueUpdates.next(value); this.value = value;
} }
} }

View File

@@ -127,11 +127,7 @@ export class SubmissionSectionLicenseComponent extends SectionModelComponent {
const model = this.formBuilderService.findById('granted', this.formModel); const model = this.formBuilderService.findById('granted', this.formModel);
// Retrieve license accepted status // Retrieve license accepted status
if ((this.sectionData.data as WorkspaceitemSectionLicenseObject).granted) { (model as DynamicCheckboxModel).value = (this.sectionData.data as WorkspaceitemSectionLicenseObject).granted;
(model as DynamicCheckboxModel).valueUpdates.next(true);
} else {
(model as DynamicCheckboxModel).valueUpdates.next(false);
}
this.licenseText$ = this.collectionDataService.findById(this.collectionId, followLink('license')).pipe( this.licenseText$ = this.collectionDataService.findById(this.collectionId, followLink('license')).pipe(
filter((collectionData: RemoteData<Collection>) => isNotUndefined((collectionData.payload))), filter((collectionData: RemoteData<Collection>) => isNotUndefined((collectionData.payload))),
@@ -149,7 +145,7 @@ export class SubmissionSectionLicenseComponent extends SectionModelComponent {
take(1), take(1),
filter((isReadOnly) => isReadOnly)) filter((isReadOnly) => isReadOnly))
.subscribe(() => { .subscribe(() => {
model.disabledUpdates.next(true); model.disabled = true;
}), }),
this.sectionService.getSectionErrors(this.submissionId, this.sectionData.id).pipe( this.sectionService.getSectionErrors(this.submissionId, this.sectionData.id).pipe(
@@ -192,7 +188,7 @@ export class SubmissionSectionLicenseComponent extends SectionModelComponent {
*/ */
protected getSectionStatus(): Observable<boolean> { protected getSectionStatus(): Observable<boolean> {
const model = this.formBuilderService.findById('granted', this.formModel); const model = this.formBuilderService.findById('granted', this.formModel);
return (model as DynamicCheckboxModel).valueUpdates.pipe( return (model as DynamicCheckboxModel).valueChanges.pipe(
map((value) => value === true), map((value) => value === true),
startWith((model as DynamicCheckboxModel).value)); startWith((model as DynamicCheckboxModel).value));
} }