File

src/app/core/basic-datatypes/discrete/discrete.datatype.ts

Description

Abstract base for datatypes that hold a discrete set of values.

This provides import config and mapping definitions that work across all such types.

Extends

DefaultDatatype

Index

Properties
Methods

Properties

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 @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
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

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

Methods

importIncompleteAdditionalConfigBadge
importIncompleteAdditionalConfigBadge(col: ColumnMapping)
Inherited from DefaultDatatype
Defined in DefaultDatatype:51
Parameters :
Name Type Optional
col ColumnMapping No
Returns : string
Async importMapFunction
importMapFunction(val: unknown, schemaField: EntitySchemaField, additional: DiscreteColumnMappingAdditional)
Inherited from DefaultDatatype
Defined in DefaultDatatype:29
Parameters :
Name Type Optional
val unknown No
schemaField EntitySchemaField No
additional DiscreteColumnMappingAdditional No
Returns : unknown
Abstract transformToDatabaseFormat
transformToDatabaseFormat(value: unknown, schemaField?: EntitySchemaField, parent?: Entity)
Inherited from DefaultDatatype
Defined in DefaultDatatype:17
Parameters :
Name Type Optional
value unknown No
schemaField EntitySchemaField Yes
parent Entity Yes
Returns : any
Abstract transformToObjectFormat
transformToObjectFormat(value: unknown, schemaField?: EntitySchemaField, parent?: any)
Inherited from DefaultDatatype
Defined in DefaultDatatype:23
Parameters :
Name Type Optional
value unknown No
schemaField EntitySchemaField Yes
parent any Yes
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>
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 dataType matches one of the provided strings and returns its property name.

Subclasses typically override this without the extra dataTypes parameter, forwarding their own relevant datatype identifiers.

Parameters :
Name Type Optional Description
entityOrType Entity | EntityConstructor No

An entity instance or entity constructor to inspect.

dataTypes string | string[] No

One or more datatype identifiers to match against.

Returns : string | undefined

The field name of the first matching field, or undefined if none is found.

normalizeSchemaField
normalizeSchemaField(schemaField: EntitySchemaField)
Inherited from DefaultDatatype

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 isArray: true).

Parameters :
Name Type Optional Description
schemaField EntitySchemaField No

The current schema field definition

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

results matching ""

    No results matching ""