2023-12-29 16:04:16 +01:00
|
|
|
import { DatePipe } from "@angular/common";
|
|
|
|
import { Pipe, PipeTransform } from "@angular/core";
|
|
|
|
import { DescriptionTemplateFieldType } from "../common/enum/description-template-field-type";
|
2022-11-24 20:28:18 +01:00
|
|
|
|
|
|
|
@Pipe({
|
|
|
|
name: 'fieldValue'
|
|
|
|
})
|
|
|
|
export class FieldValuePipe implements PipeTransform {
|
|
|
|
|
|
|
|
constructor(private date: DatePipe) {
|
|
|
|
}
|
|
|
|
|
|
|
|
transform(controlValue: any): string | null {
|
|
|
|
let value = controlValue.value;
|
|
|
|
let renderStyle = controlValue.viewStyle?.renderStyle;
|
2022-12-19 17:02:53 +01:00
|
|
|
if (renderStyle && value) {
|
2022-11-24 20:28:18 +01:00
|
|
|
switch (renderStyle) {
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.CURRENCY:
|
2022-11-24 20:28:18 +01:00
|
|
|
if (value) {
|
|
|
|
return JSON.parse(value).name;
|
|
|
|
}
|
|
|
|
break;
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.BOOLEAN_DECISION:
|
2022-11-24 20:28:18 +01:00
|
|
|
return value == 'true' ? 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.YES' : 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.NO';
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.CHECK_BOX:
|
2022-11-24 20:28:18 +01:00
|
|
|
return value ? 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.YES' : 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.NO';
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.RADIO_BOX:
|
2022-11-24 20:28:18 +01:00
|
|
|
if (value && controlValue.data.options) {
|
|
|
|
return controlValue.data.options.find(option => option.value === value).label;
|
|
|
|
}
|
|
|
|
break;
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.DATE_PICKER:
|
2022-11-24 20:28:18 +01:00
|
|
|
return this.date.transform(controlValue.value, 'dd/MM/yyyy');
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.FREE_TEXT:
|
2022-11-24 20:28:18 +01:00
|
|
|
return value;
|
2024-01-31 20:16:39 +01:00
|
|
|
case DescriptionTemplateFieldType.EXTERNAL_SELECT:
|
2024-01-30 18:27:55 +01:00
|
|
|
case DescriptionTemplateFieldType.SELECT:
|
2024-01-31 20:16:39 +01:00
|
|
|
if (value && controlValue.data.options && !controlValue.data.multipleSelect) {
|
2022-11-24 20:28:18 +01:00
|
|
|
return controlValue.data.options.find(option => value == option.value).label;
|
2024-01-31 20:16:39 +01:00
|
|
|
} else if (value && controlValue.data.options && controlValue.data.multipleSelect) {
|
2022-11-24 20:28:18 +01:00
|
|
|
return controlValue.data.options.filter(option => value.includes(option.value)).map(option => option.label).join(',');
|
|
|
|
}
|
|
|
|
break;
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.RICH_TEXT_AREA:
|
|
|
|
if (value) {
|
2022-11-24 20:28:18 +01:00
|
|
|
return value.replace(/ /g, ' ').replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " ").replace(/<[^>]*>/g, '');
|
|
|
|
}
|
|
|
|
break;
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.TEXT_AREA:
|
2022-11-24 20:28:18 +01:00
|
|
|
return value;
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.REGISTRIES:
|
|
|
|
case DescriptionTemplateFieldType.SERVICES:
|
|
|
|
case DescriptionTemplateFieldType.RESEARCHERS:
|
|
|
|
case DescriptionTemplateFieldType.ORGANIZATIONS:
|
|
|
|
case DescriptionTemplateFieldType.EXTERNAL_DATASETS:
|
|
|
|
case DescriptionTemplateFieldType.DATA_REPOSITORIES:
|
|
|
|
case DescriptionTemplateFieldType.PUB_REPOSITORIES:
|
|
|
|
case DescriptionTemplateFieldType.JOURNAL_REPOSITORIES:
|
|
|
|
case DescriptionTemplateFieldType.TAXONOMIES:
|
|
|
|
case DescriptionTemplateFieldType.LICENSES:
|
|
|
|
case DescriptionTemplateFieldType.PUBLICATIONS:
|
|
|
|
case DescriptionTemplateFieldType.TAGS:
|
2022-12-19 17:02:53 +01:00
|
|
|
return this.parseJson(value);
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS:
|
|
|
|
case DescriptionTemplateFieldType.INTERNAL_DMP_ENTRIES_DMPS:
|
|
|
|
case DescriptionTemplateFieldType.INTERNAL_DMP_ENTRIES_DATASETS:
|
2022-12-19 17:02:53 +01:00
|
|
|
return this.parseJson(value, 'label');
|
2023-12-29 16:04:16 +01:00
|
|
|
case DescriptionTemplateFieldType.DATASET_IDENTIFIER:
|
|
|
|
case DescriptionTemplateFieldType.VALIDATION:
|
|
|
|
if (value && value.identifier) {
|
2022-12-19 17:02:53 +01:00
|
|
|
return value.identifier;
|
|
|
|
}
|
|
|
|
break;
|
2022-11-24 20:28:18 +01:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2022-12-19 17:02:53 +01:00
|
|
|
|
|
|
|
public parseJson(value: any, field: string = 'name') {
|
2023-12-29 16:04:16 +01:00
|
|
|
if (Array.isArray(value)) {
|
2022-12-19 17:02:53 +01:00
|
|
|
return value.map(element => JSON.parse(element)[field]).join(',');
|
|
|
|
} else {
|
|
|
|
return JSON.parse(value)[field];
|
|
|
|
}
|
|
|
|
}
|
2022-11-24 20:28:18 +01:00
|
|
|
}
|