File

src/app/features/attendance/deprecated/event-attendance-map.datatype.ts

Deprecated

[object Object],[object Object],[object Object]

Description

Holds a full register of EventAttendance entries. Each value in the map is an AttendanceItem, transformed using its schema annotations (via EntitySchemaService).

Extends

DefaultDatatype

Index

Properties
Methods

Methods

transformToDatabaseFormat
transformToDatabaseFormat(value: AttendanceItem[])
Inherited from DefaultDatatype
Defined in DefaultDatatype:25
Parameters :
Name Type Optional
value AttendanceItem[] 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>
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.

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.

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)

Properties

Static dataType
Type : string
Default value : "event-attendance-map"
Inherited from DefaultDatatype
Defined in DefaultDatatype:18
editComponent
Type : string
Default value : "EditAttendance"
Inherited from DefaultDatatype
Defined in DefaultDatatype:20
viewComponent
Type : string
Default value : "DisplayAttendance"
Inherited from DefaultDatatype
Defined in DefaultDatatype:21
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.

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:89

The human-readable name for this dataType, used in config UIs.

import { inject, Injectable } from "@angular/core";
import { AttendanceItem } from "../model/attendance-item";
import { DefaultDatatype } from "#src/app/core/entity/default-datatype/default.datatype";
import { EntitySchemaService } from "#src/app/core/entity/schema/entity-schema.service";

/**
 * Holds a full register of EventAttendance entries.
 * Each value in the map is an {@link AttendanceItem}, transformed
 * using its schema annotations (via {@link EntitySchemaService}).
 *
 * @deprecated Use the new `attendance` datatype ({@link AttendanceDatatype}) with `isArray: true` instead.
 */
@Injectable()
export class EventAttendanceMapDatatype extends DefaultDatatype<
  AttendanceItem[],
  [string, any][]
> {
  static override dataType = "event-attendance-map";

  override editComponent = "EditAttendance";
  override viewComponent = "DisplayAttendance";

  private readonly schemaService = inject(EntitySchemaService);

  override transformToDatabaseFormat(value: AttendanceItem[]) {
    if (!Array.isArray(value)) {
      console.warn(
        'property to be saved with "event-attendance-map" datatype is not of expected type',
        value,
      );
      return value as any;
    }

    const result: [string, any][] = [];
    for (const item of value) {
      const attItem = this.schemaService.transformEntityToDatabaseFormat(
        item as any,
        AttendanceItem.schema,
      );

      result.push([
        item.participant ?? "",
        { status: attItem.status, remarks: attItem.remarks },
      ]);
    }
    return result;
  }

  override transformToObjectFormat(value: any[]) {
    if (!Array.isArray(value) || value === null) {
      console.warn(
        'property to be loaded with "event-attendance-map" datatype is not valid',
        value,
      );
      return value as any;
    }

    const result: AttendanceItem[] = [];
    for (const keyValue of value) {
      const transformedValue =
        this.schemaService.transformDatabaseToEntityFormat<AttendanceItem>(
          keyValue[1],
          AttendanceItem.schema,
        );
      const instance = new AttendanceItem();
      Object.assign(instance, transformedValue);
      instance.participant = keyValue[0];
      result.push(instance);
    }
    return result;
  }
}

results matching ""

    No results matching ""