src/app/core/basic-datatypes/discrete/discrete.datatype.ts
Abstract base for datatypes that hold a discrete set of values.
This provides import config and mapping definitions that work across all such types.
Properties |
|
Methods |
|
| importConfigComponent |
Type : string
|
Default value : "DiscreteImportConfig"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:15
|
| Static dataType |
Type : string
|
Default value : ""
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:42
|
|
Key for this datatype that must be specified in the DatabaseField annotation to use this transformation. for example If you set the name to a TypeScript type, class properties with this type will automatically use
that EntitySchemaDatatype without the need to explicitly state the dataType config in the annotation
(e.g. |
| editComponent |
Type : string
|
Default value : "EditText"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:101
|
| Readonly importAllowsMultiMapping |
Type : boolean
|
Default value : false
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:80
|
|
Whether this datatype allows multiple values to be mapped to the same entity field during import. |
| Static label |
Type : string
|
Default value : $localize`:datatype-label:any`
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:89
|
|
The human-readable name for this dataType, used in config UIs. |
| viewComponent |
Type : string
|
Default value : "DisplayText"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:100
|
|
The default component how this datatype should be displayed in lists and forms. The edit component has to be a registered component. Components that are registered contain the |
| importIncompleteAdditionalConfigBadge | ||||||
importIncompleteAdditionalConfigBadge(col: ColumnMapping)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:51
|
||||||
|
Parameters :
Returns :
string
|
| Async importMapFunction | ||||||||||||
importMapFunction(val: unknown, schemaField: EntitySchemaField, additional: DiscreteColumnMappingAdditional)
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:29
|
||||||||||||
|
Parameters :
Returns :
unknown
|
| Abstract transformToDatabaseFormat | ||||||||||||
transformToDatabaseFormat(value: unknown, schemaField?: EntitySchemaField, parent?: Entity)
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:17
|
||||||||||||
|
Parameters :
Returns :
any
|
| Abstract transformToObjectFormat | ||||||||||||
transformToObjectFormat(value: unknown, schemaField?: EntitySchemaField, parent?: any)
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:23
|
||||||||||||
|
Parameters :
Returns :
any
|
| Async anonymize | ||||||||||||||||
anonymize(value: EntityType, schemaField: EntitySchemaField, parent: any)
|
||||||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||||||
|
Defined in
DefaultDatatype:190
|
||||||||||||||||
|
(Partially) anonymize to "retain-anonymized" for reporting purposes without personal identifiable information.
Parameters :
Returns :
Promise<any>
|
| Static detectFieldInEntity | ||||||||||||
detectFieldInEntity(entityOrType: Entity | EntityConstructor, dataTypes: string | string[])
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:57
|
||||||||||||
|
Detect the first field of the given datatype(s) in an entity's schema. Scans the schema for a field whose Subclasses typically override this without the extra
Parameters :
Returns :
string | undefined
The field name of the first matching field, or |
| normalizeSchemaField | ||||||||
normalizeSchemaField(schemaField: EntitySchemaField)
|
||||||||
|
Inherited from
DefaultDatatype
|
||||||||
|
Defined in
DefaultDatatype:182
|
||||||||
|
Return the (potentially adjusted) schema field for this datatype. Called when schema fields are set up (e.g. from config), allowing the datatype to normalize or fill in required settings. Override this in a subclass to enforce constraints
(e.g. always setting
Parameters :
Returns :
EntitySchemaField
The schema field to use (default: unchanged) |
import { DefaultDatatype } from "../../entity/default-datatype/default.datatype";
import { EntitySchemaField } from "../../entity/schema/entity-schema-field";
import { ColumnMapping } from "../../import/column-mapping";
import { Entity } from "../../entity/model/entity";
/**
* Abstract base for datatypes that hold a discrete set of values.
*
* This provides import config and mapping definitions that work across all such types.
*/
export abstract class DiscreteDatatype<
EntityType,
DBType,
> extends DefaultDatatype<EntityType, DBType> {
override importConfigComponent = "DiscreteImportConfig";
abstract override transformToDatabaseFormat(
value,
schemaField?: EntitySchemaField,
parent?: Entity,
);
abstract override transformToObjectFormat(
value,
schemaField?: EntitySchemaField,
parent?: any,
);
override async importMapFunction(
val,
schemaField: EntitySchemaField,
additional: DiscreteColumnMappingAdditional,
) {
const valueMappings = additional?.values;
// If mapping dialog was skipped entirely,
// treat as raw string value and let transformToObjectFormat handle it
if (!valueMappings) {
return super.importMapFunction(val, schemaField);
}
// If mapping dialog was opened but this specific value was not mapped,
// skip the property by returning undefined
if (valueMappings[val] === undefined) {
return undefined;
}
return super.importMapFunction(valueMappings[val], schemaField);
}
override importIncompleteAdditionalConfigBadge(col: ColumnMapping): string {
const valueMappings = (col.additional as DiscreteColumnMappingAdditional)
?.values;
if (!valueMappings) {
return "?";
}
const unmappedValues = Object.values(valueMappings).filter(
(v) => v === undefined,
);
if (unmappedValues.length > 0) {
return unmappedValues.length.toString();
}
return undefined;
}
}
/**
* Structure for the `additional` field of a ColumnMapping for discrete datatypes.
*/
export interface DiscreteColumnMappingAdditional {
/** Whether to split values by the configured separator (for array/multi-select fields). */
enableSplitting?: boolean;
/** Key-value mapping from raw import values to target entity values. */
values: { [key: string]: any };
}