File

src/app/core/basic-datatypes/schema-embed/schema-embed.datatype.ts

Description

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.

Extends

DefaultDatatype

Index

Properties
Methods

Methods

transformToDatabaseFormat
transformToDatabaseFormat(value: any)
Inherited from DefaultDatatype
Defined in DefaultDatatype:42
Parameters :
Name Type Optional
value any No
Returns : any
transformToObjectFormat
transformToObjectFormat(value: any)
Inherited from DefaultDatatype
Defined in DefaultDatatype:49
Parameters :
Name Type Optional
value any No
Returns : any
Async anonymize
anonymize(value: EntityType, schemaField: EntitySchemaField, parent: any)
Inherited from DefaultDatatype

(Partially) anonymize to "retain-anonymized" for reporting purposes without personal identifiable information.

Parameters :
Name Type Optional Description
value EntityType No

The original value to be anonymized

schemaField EntitySchemaField No
parent any No
Returns : Promise<any>
importIncompleteAdditionalConfigBadge
importIncompleteAdditionalConfigBadge(col: ColumnMapping)
Inherited from DefaultDatatype

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 :
Name Type Optional
col ColumnMapping No
Returns : string
Async importMapFunction
importMapFunction(val: any, schemaField: EntitySchemaField, additional?: any, importProcessingContext?: any)
Inherited from DefaultDatatype

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 :
Name Type Optional Description
val any No

The value from an imported cell to be mapped

schemaField EntitySchemaField No

The schema field definition for the target property into which the value is mapped

additional any Yes

config as returned by the configComponent

importProcessingContext any Yes

an object that the datatype can use to store any relevant context across multiple calls to share information across processing of multiple columns and rows.

Properties

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 @DatabaseField({dataType: 'foo'}) myField will trigger the datatype implementation with name "foo".

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. @DatabaseField() myField: string is triggering the EntitySchemaDatatype with name "string".

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

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 DynamicComponent decorator

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;
  }
}

results matching ""

    No results matching ""