From facd2284d2594025f23128bbae820afe968e70d2 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Thu, 23 Apr 2020 13:16:43 +0200 Subject: [PATCH] fix issue where related entites would be rendered as metadata for one box fields --- .../org-unit-item-metadata-list-element.component.html | 5 ++--- .../ds-dynamic-form-control-container.component.ts | 8 +++++++- .../ds-dynamic-form-ui/models/ds-dynamic-concat.model.ts | 4 ++++ .../ds-dynamic-form-ui/models/ds-dynamic-input.model.ts | 4 ++++ src/app/shared/form/builder/parsers/field-parser.ts | 2 ++ src/app/shared/form/form.component.html | 2 +- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/app/entity-groups/research-entities/metadata-representations/org-unit/org-unit-item-metadata-list-element.component.html b/src/app/entity-groups/research-entities/metadata-representations/org-unit/org-unit-item-metadata-list-element.component.html index d8a4e744e4..de805a64b3 100644 --- a/src/app/entity-groups/research-entities/metadata-representations/org-unit/org-unit-item-metadata-list-element.component.html +++ b/src/app/entity-groups/research-entities/metadata-representations/org-unit/org-unit-item-metadata-list-element.component.html @@ -1,7 +1,6 @@ - + @@ -9,5 +8,5 @@ + [tooltip]="metadataRepresentation.allMetadata(['dc.description']).length > 0 ? descTemplate : null"> diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts index 567e8b387f..dce749aad4 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts @@ -109,6 +109,7 @@ import { paginatedRelationsToItems } from '../../../../+item-page/simple/item-ty import { RelationshipOptions } from '../models/relationship-options.model'; import { FormBuilderService } from '../form-builder.service'; import { modalConfigDefaults } from 'ngx-bootstrap/modal/modal-options.class'; +import { models } from '../../../../core/core.module'; export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type | null { switch (model.type) { @@ -292,7 +293,12 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo this.subs.push(subscription); } - this.value = Object.assign(new MetadataValue(), this.model.value); + if (hasValue(this.model.metadataValue)) { + this.value = Object.assign(new MetadataValue(), this.model.metadataValue); + } else { + this.value = Object.assign(new MetadataValue(), this.model.value); + } + if (hasValue(this.value) && this.value.isVirtual) { const relationship$ = this.relationshipService.findById(this.value.virtualValue, followLink('leftItem'), followLink('rightItem'), followLink('relationshipType')) .pipe( 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 a34d701f25..7d4b58c95d 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 @@ -6,6 +6,7 @@ import { hasNoValue, isNotEmpty } from '../../../../empty.util'; import { DsDynamicInputModel } from './ds-dynamic-input.model'; import { FormFieldMetadataValueObject } from '../../models/form-field-metadata-value.model'; import { RelationshipOptions } from '../../models/relationship-options.model'; +import { MetadataValue } from '../../../../../core/shared/metadata.models'; export const CONCAT_GROUP_SUFFIX = '_CONCAT_GROUP'; export const CONCAT_FIRST_INPUT_SUFFIX = '_CONCAT_FIRST_INPUT'; @@ -21,6 +22,7 @@ export interface DynamicConcatModelConfig extends DynamicFormGroupModelConfig { metadataFields: string[]; submissionId: string; hasSelectableMetadata: boolean; + metadataValue?: MetadataValue; } export class DynamicConcatModel extends DynamicFormGroupModel { @@ -34,6 +36,7 @@ export class DynamicConcatModel extends DynamicFormGroupModel { @serializable() metadataFields: string[]; @serializable() submissionId: string; @serializable() hasSelectableMetadata: boolean; + @serializable() metadataValue: MetadataValue; isCustomGroup = true; valueUpdates: Subject; @@ -49,6 +52,7 @@ export class DynamicConcatModel extends DynamicFormGroupModel { this.metadataFields = config.metadataFields; this.submissionId = config.submissionId; this.hasSelectableMetadata = config.hasSelectableMetadata; + this.metadataValue = config.metadataValue; this.valueUpdates = new Subject(); this.valueUpdates.subscribe((value: string) => this.value = value); } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts index ed7f399085..7573b67912 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts @@ -6,6 +6,7 @@ import { AuthorityOptions } from '../../../../../core/integration/models/authori import { hasValue } from '../../../../empty.util'; import { FormFieldMetadataValueObject } from '../../models/form-field-metadata-value.model'; import { RelationshipOptions } from '../../models/relationship-options.model'; +import { MetadataValue } from '../../../../../core/shared/metadata.models'; export interface DsDynamicInputModelConfig extends DynamicInputModelConfig { authorityOptions?: AuthorityOptions; @@ -18,6 +19,7 @@ export interface DsDynamicInputModelConfig extends DynamicInputModelConfig { metadataFields: string[]; submissionId: string; hasSelectableMetadata: boolean; + metadataValue?: MetadataValue; } @@ -32,6 +34,7 @@ export class DsDynamicInputModel extends DynamicInputModel { @serializable() metadataFields: string[]; @serializable() submissionId: string; @serializable() hasSelectableMetadata: boolean; + @serializable() metadataValue: MetadataValue; constructor(config: DsDynamicInputModelConfig, layout?: DynamicFormControlLayout) { super(config, layout); @@ -43,6 +46,7 @@ export class DsDynamicInputModel extends DynamicInputModel { this.relationship = config.relationship; this.submissionId = config.submissionId; this.hasSelectableMetadata = config.hasSelectableMetadata; + this.metadataValue = config.metadataValue; this.language = config.language; if (!this.language) { diff --git a/src/app/shared/form/builder/parsers/field-parser.ts b/src/app/shared/form/builder/parsers/field-parser.ts index e7a269db7e..6ba27eebfa 100644 --- a/src/app/shared/form/builder/parsers/field-parser.ts +++ b/src/app/shared/form/builder/parsers/field-parser.ts @@ -305,6 +305,7 @@ export abstract class FieldParser { } public setValues(modelConfig: DsDynamicInputModelConfig, fieldValue: any, forceValueAsObj: boolean = false, groupModel?: boolean) { + console.log('modelConfig.id', modelConfig.id); if (isNotEmpty(fieldValue)) { if (groupModel) { // Array, values is an array @@ -317,6 +318,7 @@ export abstract class FieldParser { } if (typeof fieldValue === 'object') { + modelConfig.metadataValue = fieldValue; modelConfig.language = fieldValue.language; modelConfig.place = fieldValue.place; if (forceValueAsObj) { diff --git a/src/app/shared/form/form.component.html b/src/app/shared/form/form.component.html index 3d4c12797f..15ab6f87fb 100644 --- a/src/app/shared/form/form.component.html +++ b/src/app/shared/form/form.component.html @@ -24,7 +24,7 @@ -