src/app/core/basic-datatypes/schema-embed/schema-embed.datatype.ts
Datatype for the EntitySchemaService transforming values of complex objects recursively.
(De)serialize instances of any class recognizing the normal @DatabaseField() annotations within that referenced class. This is useful if your Entity type is complex and has properties that are instances of other classes rather just basic value types like string or number. You can then annotate some properties of that referenced class so they will be saved to the database while ignoring other properties. The referenced class instance will be saved embedded into the entity's object and not as an own "stand-alone" entity.
see the unit tests in entity-schema.service.spec.ts for an example
implement this as its own datatype for a specific class functioning as "embedded" schema.
Properties |
|
Methods |
transformToDatabaseFormat | ||||||
transformToDatabaseFormat(value: any)
|
||||||
Inherited from
DefaultDatatype
|
||||||
Defined in
DefaultDatatype:42
|
||||||
Parameters :
Returns :
any
|
transformToObjectFormat | ||||||
transformToObjectFormat(value: any)
|
||||||
Inherited from
DefaultDatatype
|
||||||
Defined in
DefaultDatatype:49
|
||||||
Parameters :
Returns :
any
|
Async anonymize | ||||||||||||||||
anonymize(value: EntityType, schemaField: EntitySchemaField, parent: any)
|
||||||||||||||||
Inherited from
DefaultDatatype
|
||||||||||||||||
Defined in
DefaultDatatype:148
|
||||||||||||||||
(Partially) anonymize to "retain-anonymized" for reporting purposes without personal identifiable information.
Parameters :
Returns :
Promise<any>
|
importIncompleteAdditionalConfigBadge | ||||||
importIncompleteAdditionalConfigBadge(col: ColumnMapping)
|
||||||
Inherited from
DefaultDatatype
|
||||||
Defined in
DefaultDatatype:140
|
||||||
Output a label indicating whether the given column mapping needs user configuration for the "additional" config or has a valid, complete "additional" config. returns "undefined" if no user action is required.
Parameters :
Returns :
string
|
Async importMapFunction | ||||||||||||||||||||
importMapFunction(val: any, schemaField: EntitySchemaField, additional?: any, importProcessingContext?: any)
|
||||||||||||||||||||
Inherited from
DefaultDatatype
|
||||||||||||||||||||
Defined in
DefaultDatatype:113
|
||||||||||||||||||||
The function used to map values from the import data to values in the entities to be created. to share information across processing of multiple columns and rows.
Parameters :
Returns :
Promise<EntityType | []>
|
Abstract embeddedType |
Type : EntityConstructor
|
Protected Readonly schemaService |
Default value : inject(EntitySchemaService)
|
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:69
|
Readonly importAllowsMultiMapping |
Type : boolean
|
Default value : false
|
Inherited from
DefaultDatatype
|
Defined in
DefaultDatatype:48
|
Whether this datatype allows multiple values to be mapped to the same entity field during import. |
Optional importConfigComponent |
Type : string
|
Inherited from
DefaultDatatype
|
Defined in
DefaultDatatype:132
|
A component to be display as a dialog to configure the transformation function (e.g. defining a format or mapping) |
Static label |
Type : string
|
Default value : $localize`:datatype-label:any`
|
Inherited from
DefaultDatatype
|
Defined in
DefaultDatatype:57
|
The human-readable name for this dataType, used in config UIs. |
viewComponent |
Type : string
|
Default value : "DisplayText"
|
Inherited from
DefaultDatatype
|
Defined in
DefaultDatatype:68
|
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 |
import { DefaultDatatype } from "../../entity/default-datatype/default.datatype";
import { EntitySchemaService } from "../../entity/schema/entity-schema.service";
import { EntityConstructor } from "../../entity/model/entity";
import { inject, Injectable } from "@angular/core";
/**
* Datatype for the EntitySchemaService transforming values of complex objects recursively.
*
* (De)serialize instances of any class recognizing the normal @DatabaseField() annotations within that referenced class.
* This is useful if your Entity type is complex and has properties that are instances of other classes
* rather just basic value types like string or number.
* You can then annotate some properties of that referenced class so they will be saved to the database while ignoring other properties.
* The referenced class instance will be saved embedded into the entity's object and not as an own "stand-alone" entity.
*
* see the unit tests in entity-schema.service.spec.ts for an example
*
* implement this as its own datatype for a specific class functioning as "embedded" schema.
*/
@Injectable()
export abstract class SchemaEmbedDatatype extends DefaultDatatype {
abstract embeddedType: EntityConstructor;
protected readonly schemaService = inject(EntitySchemaService);
override transformToDatabaseFormat(value: any) {
return this.schemaService.transformEntityToDatabaseFormat(
value,
this.embeddedType.schema,
);
}
override transformToObjectFormat(value: any) {
const instance = new this.embeddedType();
this.schemaService.loadDataIntoEntity(instance, value);
return instance;
}
}