File

src/app/features/attendance/model/attendance.datatype.ts

Description

Datatype for attendance tracking on any entity.

Use this as dataType: "attendance" with isArray: true on an entity field to store an array of AttendanceItem objects, each referencing a participant entity.

The allowed entity types for the participant field can be overridden via the field's additional config, e.g.:

Example :
{
  "dataType": "attendance",
  "isArray": true,
  "additional": {
    "participant": { "dataType": "entity", "additional": ["Child", "School"] }
  }
}

Extends

SchemaEmbedDatatype

Index

Properties
Methods

Methods

Static detectFieldInEntity
detectFieldInEntity(entityOrType: Entity | EntityConstructor)
Inherited from DefaultDatatype
Defined in DefaultDatatype:45
Parameters :
Name Type Optional
entityOrType Entity | EntityConstructor No
Returns : string | undefined
normalizeSchemaField
normalizeSchemaField(schemaField: EntitySchemaField)
Inherited from DefaultDatatype
Defined in DefaultDatatype:37
Parameters :
Name Type Optional
schemaField EntitySchemaField No
Returns : EntitySchemaField
transformToDatabaseFormat
transformToDatabaseFormat(value: EntityType, schemaField?: EntitySchemaField)
Inherited from DefaultDatatype
Defined in DefaultDatatype:92
Parameters :
Name Type Optional
value EntityType No
schemaField EntitySchemaField Yes
Returns : DBType
transformToObjectFormat
transformToObjectFormat(value: DBType, schemaField?: EntitySchemaField)
Inherited from DefaultDatatype
Parameters :
Name Type Optional
value DBType No
schemaField EntitySchemaField Yes
Returns : EntityType
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 Readonly dataType
Type : string
Default value : "attendance"
Inherited from DefaultDatatype
Defined in DefaultDatatype:29
editComponent
Type : string
Default value : "EditAttendance"
Inherited from DefaultDatatype
Defined in DefaultDatatype:34
embeddedType
Type : unknown
Default value : AttendanceItem
Inherited from SchemaEmbedDatatype
Static label
Type : string
Default value : $localize`:datatype-label:attendance (participants with status)`
Inherited from DefaultDatatype
Defined in DefaultDatatype:30
viewComponent
Type : string
Default value : "DisplayAttendance"
Inherited from DefaultDatatype
Defined in DefaultDatatype:35
Protected Readonly schemaService
Type : unknown
Default value : inject(EntitySchemaService)
Inherited from SchemaEmbedDatatype
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)

import { Injectable } from "@angular/core";
import { SchemaEmbedDatatype } from "#src/app/core/basic-datatypes/schema-embed/schema-embed.datatype";
import { AttendanceItem } from "./attendance-item";
import { EntitySchemaField } from "#src/app/core/entity/schema/entity-schema-field";
import { Entity, EntityConstructor } from "#src/app/core/entity/model/entity";
import { EventAttendanceMapDatatype } from "../deprecated/event-attendance-map.datatype";
import { DefaultDatatype } from "#src/app/core/entity/default-datatype/default.datatype";

/**
 * Datatype for attendance tracking on any entity.
 *
 * Use this as `dataType: "attendance"` with `isArray: true` on an entity field
 * to store an array of {@link AttendanceItem} objects, each referencing a participant entity.
 *
 * The allowed entity types for the `participant` field can be overridden via
 * the field's `additional` config, e.g.:
 * ```json
 * {
 *   "dataType": "attendance",
 *   "isArray": true,
 *   "additional": {
 *     "participant": { "dataType": "entity", "additional": ["Child", "School"] }
 *   }
 * }
 * ```
 */
@Injectable()
export class AttendanceDatatype extends SchemaEmbedDatatype {
  static override readonly dataType = "attendance";
  static override label: string = $localize`:datatype-label:attendance (participants with status)`;

  override embeddedType = AttendanceItem;

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

  override normalizeSchemaField(
    schemaField: EntitySchemaField,
  ): EntitySchemaField {
    // attendance always requires isArray
    return { ...schemaField, isArray: true };
  }

  /** @override Detects the first `attendance` or legacy `event-attendance-map` field in the entity schema. */
  static override detectFieldInEntity(
    entityOrType: Entity | EntityConstructor,
  ): string | undefined {
    return DefaultDatatype.detectFieldInEntity(entityOrType, [
      AttendanceDatatype.dataType,
      EventAttendanceMapDatatype.dataType,
    ]);
  }
}

results matching ""

    No results matching ""