diff --git a/dmp-frontend/src/app/core/pipes/field-value.pipe.ts b/dmp-frontend/src/app/core/pipes/field-value.pipe.ts index ef9777c0c..68e3e2c67 100644 --- a/dmp-frontend/src/app/core/pipes/field-value.pipe.ts +++ b/dmp-frontend/src/app/core/pipes/field-value.pipe.ts @@ -1,17 +1,27 @@ import { DatePipe } from "@angular/common"; import { Pipe, PipeTransform } from "@angular/core"; import { DescriptionTemplateFieldType } from "../common/enum/description-template-field-type"; -import { Reference } from "../model/reference/reference"; -import { DescriptionTemplateField, DescriptionTemplateRadioBoxData, DescriptionTemplateReferenceTypeData, DescriptionTemplateSelectData } from "../model/description-template/description-template"; +import { DescriptionTemplateField, DescriptionTemplateLabelAndMultiplicityData, DescriptionTemplateRadioBoxData, DescriptionTemplateReferenceTypeData, DescriptionTemplateSelectData } from "../model/description-template/description-template"; import { DescriptionFieldPersist } from "../model/description/description"; -import { Observable, of } from "rxjs"; +import { Observable, map, of } from "rxjs"; +import { TagService } from "../services/tag/tag.service"; +import { Guid } from "@common/types/guid"; +import { DmpService } from "../services/dmp/dmp.service"; +import { DescriptionService } from "../services/description/description.service"; +import { StorageFileService } from "../services/storage-file/storage-file.service"; +import { nameof } from "ts-simple-nameof"; +import { StorageFile } from "../model/storage-file/storage-file"; @Pipe({ name: 'fieldValue' }) export class FieldValuePipe implements PipeTransform { - constructor(private date: DatePipe) { + constructor(private date: DatePipe, + private tagService: TagService, + private dmpService: DmpService, + private storageFileService: StorageFileService, + private descriptionService: DescriptionService) { } transform(controlValue: DescriptionFieldPersist, field: DescriptionTemplateField): Observable { @@ -57,11 +67,37 @@ export class FieldValuePipe implements PipeTransform { } break; } - // case DescriptionTemplateFieldType.TAGS: - // return this.parseJson(value); - // case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS: - // case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DESCRIPTIONS: - // return this.parseJson(value, 'label'); + case DescriptionTemplateFieldType.TAGS: { + if (controlValue.textListValue && controlValue.textListValue.length > 0) { + return this.tagService.query(this.tagService.buildAutocompleteLookup(null, null, controlValue.textListValue.map(x => Guid.parse(x)))).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } + break; + } + case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS: { + const data = field.data; + if (!data?.multipleSelect && controlValue.textValue && controlValue.textValue.length > 0) { + return this.dmpService.query(this.dmpService.buildAutocompleteLookup(null, null, [Guid.parse(controlValue.textValue)])).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } else if (data?.multipleSelect && controlValue.references && controlValue.textListValue && controlValue.textListValue.length > 0) { + return this.dmpService.query(this.dmpService.buildAutocompleteLookup(null, null, controlValue.textListValue.map(x => Guid.parse(x)))).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } + break; + } + case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DESCRIPTIONS: + const data = field.data; + if (!data?.multipleSelect && controlValue.textValue && controlValue.textValue.length > 0) { + return this.descriptionService.query(this.descriptionService.buildAutocompleteLookup(null, null, [Guid.parse(controlValue.textValue)])).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } else if (data?.multipleSelect && controlValue.references && controlValue.textListValue && controlValue.textListValue.length > 0) { + return this.descriptionService.query(this.descriptionService.buildAutocompleteLookup(null, null, controlValue.textListValue.map(x => Guid.parse(x)))).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } + break; + case DescriptionTemplateFieldType.UPLOAD: { + if (controlValue.textValue && controlValue.textValue.length > 0) { + return this.storageFileService.getSingle(Guid.parse(controlValue.textValue), [ + nameof(x => x.name) + ]).pipe(map(x => x.name)); + } + break; + } case DescriptionTemplateFieldType.DATASET_IDENTIFIER: case DescriptionTemplateFieldType.VALIDATION: if (controlValue.externalIdentifier?.identifier) { @@ -72,7 +108,7 @@ export class FieldValuePipe implements PipeTransform { return of(null); } } - return null; + return of(null); } public parseJson(value: any, field: string = 'name') { diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html index f5704cbd6..a92f6aea1 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html @@ -23,4 +23,4 @@ {{form.get('data').get('type').getError('backendError').message}} - \ No newline at end of file +