File

src/app/child-dev-project/attendance/model/event-attendance.datatype.ts

Description

Holds a full register of EventAttendance entries. (previously this was "MapDatatype")

Extends

DefaultDatatype

Index

Properties
Methods

Constructor

constructor()

Methods

transformToDatabaseFormat
transformToDatabaseFormat(value: Map)
Inherited from DefaultDatatype
Defined in DefaultDatatype:25
Parameters :
Name Type Optional
value Map<string | any> No
Returns : any
transformToObjectFormat
transformToObjectFormat(value: any[])
Inherited from DefaultDatatype
Defined in DefaultDatatype:41
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

Static dataType
Default value : EventAttendanceMap.DATA_TYPE
Inherited from DefaultDatatype
Defined in DefaultDatatype:16
embeddedType
Type : EventAttendanceDatatype
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 { Injectable } from "@angular/core";
import { SchemaEmbedDatatype } from "../../../core/basic-datatypes/schema-embed/schema-embed.datatype";
import { EntityConstructor } from "../../../core/entity/model/entity";
import { EventAttendance, EventAttendanceMap } from "./event-attendance";
import { DefaultDatatype } from "../../../core/entity/default-datatype/default.datatype";

/**
 * Holds a full register of EventAttendance entries.
 * (previously this was "MapDatatype")
 */
@Injectable()
export class EventAttendanceMapDatatype extends DefaultDatatype<
  Map<string, any>,
  [string, any][]
> {
  static override dataType = EventAttendanceMap.DATA_TYPE;

  embeddedType: EventAttendanceDatatype;

  constructor() {
    super();
    this.embeddedType = new EventAttendanceDatatype();
  }

  override transformToDatabaseFormat(value: Map<string, any>) {
    if (!(value instanceof Map)) {
      console.warn(
        'property to be saved with "map" EntitySchema is not of expected type',
        value,
      );
      return value as any;
    }

    const result: [string, any][] = [];
    value.forEach((item, key) => {
      result.push([key, this.embeddedType.transformToDatabaseFormat(item)]);
    });
    return result;
  }

  override transformToObjectFormat(value: any[]) {
    if (value instanceof Map) {
      // usually this shouldn't already be a map but in MockDatabase somehow this can happen
      return value;
    }
    if (!Array.isArray(value) || value === null) {
      console.warn(
        'property to be loaded with "map" EntitySchema is not valid',
        value,
      );
      return value as any;
    }

    const result = new EventAttendanceMap();
    for (const keyValue of value) {
      const transformedElement = this.embeddedType.transformToObjectFormat(
        keyValue[1],
      ) as unknown as EventAttendance;
      result.set(keyValue[0], transformedElement);
    }
    return result;
  }
}

/** @deprecated do not use externally, use EventAttendanceMap instead **/
@Injectable()
export class EventAttendanceDatatype extends SchemaEmbedDatatype {
  static override dataType = EventAttendance.DATA_TYPE;

  override embeddedType = EventAttendance as unknown as EntityConstructor;
}

results matching ""

    No results matching ""