src/app/core/basic-datatypes/configurable-enum/configurable-enum-datatype/configurable-enum.datatype.ts
Properties |
|
Methods |
|
| sortValue | ||||||
sortValue(fieldValue: ConfigurableEnumValue)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:59
|
||||||
|
Sort enum values by their configured ordinal position rather than
alphabetically by their label, so the order matches the admin configuration.
Falls back to default sorting for enums without an ordinal position.
See
Parameters :
Returns :
number | undefined
|
| Public transformToDatabaseFormat | ||||||||
transformToDatabaseFormat(value: ConfigurableEnumValue)
|
||||||||
|
Inherited from
DefaultDatatype
|
||||||||
|
Defined in
DefaultDatatype:25
|
||||||||
|
transforms Objects of InteractionType to strings to save in DB
Parameters :
Returns :
string
|
| Public transformToObjectFormat | ||||||||||||
transformToObjectFormat(value: string, schemaField: EntitySchemaField)
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:34
|
||||||||||||
|
transforms saved strings from the DB to Objects of InteractionType
Parameters :
Returns :
ConfigurableEnumValue
|
| Async importMapFunction | ||||||||||||
importMapFunction(val: unknown, schemaField: EntitySchemaField, additional: DiscreteColumnMappingAdditional)
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:28
|
||||||||||||
|
Parameters :
Returns :
unknown
|
| Async anonymize | ||||||||||||||||
anonymize(value: EntityType, schemaField: EntitySchemaField, parent: any)
|
||||||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||||||
|
Defined in
DefaultDatatype:261
|
||||||||||||||||
|
(Partially) anonymize to "retain-anonymized" for reporting purposes without personal identifiable information.
Parameters :
Returns :
Promise<any>
|
| Static detectAllFieldsInEntity | ||||||||||||
detectAllFieldsInEntity(entityOrType: Entity | EntityConstructor, dataTypes: string | string[])
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:98
|
||||||||||||
|
Detect all fields of the given datatype(s) in an entity's schema.
Parameters :
Returns :
literal type[]
Array of matching fields with their id and schema definition. |
| Static detectFieldInEntity | ||||||||||||
detectFieldInEntity(entityOrType: Entity | EntityConstructor, dataTypes: string | string[])
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:83
|
||||||||||||
|
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 |
| getExportColumns | ||||||
getExportColumns(schemaField: EntitySchemaField)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:232
|
||||||
|
Export columns for a field using this datatype. Each returned column contributes a CSV header and its own value resolver.
The returned The default implementation returns a single column with the raw field value. Readable formatting can be applied by callers during CSV transformation. Override this to provide custom or additional columns (e.g. entity references can add a human-readable name column alongside the ID column).
Parameters :
Returns :
ExportColumnMapping[]
|
| normalizeSchemaField | ||||||||
normalizeSchemaField(schemaField: EntitySchemaField)
|
||||||||
|
Inherited from
DefaultDatatype
|
||||||||
|
Defined in
DefaultDatatype:217
|
||||||||
|
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) |
| Static dataType |
Type : string
|
Default value : "configurable-enum"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:15
|
| Public Readonly editComponent |
Type : string
|
Default value : "EditConfigurableEnum"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:19
|
| Static label |
Type : string
|
Default value : $localize`:datatype-label:dropdown option`
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:16
|
| Public Readonly viewComponent |
Type : string
|
Default value : "DisplayConfigurableEnum"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:18
|
| importConfigComponent |
Type : string
|
Default value : "DiscreteImportConfig"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:14
|
| Readonly importAllowsMultiMapping |
Type : boolean
|
Default value : false
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:122
|
|
Whether this datatype allows multiple values to be mapped to the same entity field during import. |
import { EntitySchemaField } from "../../../entity/schema/entity-schema-field";
import { ConfigurableEnumService } from "../configurable-enum.service";
import { Injectable, inject } from "@angular/core";
import { DiscreteDatatype } from "../../discrete/discrete.datatype";
import { ConfigurableEnumValue } from "../configurable-enum.types";
import { Ordering } from "../configurable-enum-ordering";
@Injectable()
export class ConfigurableEnumDatatype extends DiscreteDatatype<
ConfigurableEnumValue,
string
> {
private enumService = inject(ConfigurableEnumService);
static override dataType = "configurable-enum";
static override label: string = $localize`:datatype-label:dropdown option`;
public override readonly viewComponent = "DisplayConfigurableEnum";
public override readonly editComponent = "EditConfigurableEnum";
/**
* transforms Objects of InteractionType to strings to save in DB
* @param value Object to be saved as specified in config file; e.g. `{id: 'CALL', label:'Phone Call', color:'#FFFFFF'}`
*/
public transformToDatabaseFormat(value: ConfigurableEnumValue): string {
return value?.id;
}
/**
* transforms saved strings from the DB to Objects of InteractionType
* @param value string from database as specified in config file; e.g. 'PHONE_CALL'
* @param schemaField
*/
public transformToObjectFormat(
value: string,
schemaField: EntitySchemaField,
): ConfigurableEnumValue {
if (value === undefined) {
return undefined;
}
let enumId = schemaField.additional;
let enumOption = this.enumService
.getEnumValues(enumId)
?.find((option) => String(option.id) === String(value));
if (!enumOption) {
enumOption = this.generateOptionForInvalid(value);
}
return enumOption;
}
/**
* Sort enum values by their configured ordinal position rather than
* alphabetically by their label, so the order matches the admin configuration.
* Falls back to default sorting for enums without an ordinal position.
* See `src/app/core/basic-datatypes/README.md` for details on custom sorting.
*/
override sortValue(fieldValue: ConfigurableEnumValue): number | undefined {
return Ordering.hasOrdinalValue(fieldValue)
? fieldValue._ordinal
: undefined;
}
/**
* Build a dummy option so that invalid values are not lost on the next save and users can manually correct issues.
* @param optionValue
* @private
*/
private generateOptionForInvalid(optionValue: string) {
return {
id: optionValue,
isInvalidOption: true,
label:
$localize`:enum option label prefix for invalid id dummy:[invalid option]` +
" " +
optionValue,
};
}
}