src/app/core/basic-datatypes/date-with-age/date-with-age.datatype.ts
Similar to the 'date-only' datatype but it uses the DateWithAge class which provides the age function.
Properties |
|
Methods |
| getExportColumns | ||||||
getExportColumns(schemaField: EntitySchemaField)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:36
|
||||||
|
Export the raw date column plus an additional, derived "age" column. The age is a virtual property computed from the date and is not stored on the entity itself, so without this dedicated column the value would be missing from exports (see #4057).
Parameters :
Returns :
ExportColumnMapping[]
|
| transformToObjectFormat | ||||||||||||
transformToObjectFormat(value: unknown, schemaField: EntitySchemaField, parent: any)
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:17
|
||||||||||||
|
Parameters :
Returns :
DateWithAge
|
| transformToDatabaseFormat | ||||||
transformToDatabaseFormat(value: Date)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:37
|
||||||
|
Parameters :
Returns :
any
|
| Async anonymize | ||||||
anonymize(value: Date)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:101
|
||||||
|
Parameters :
Returns :
Promise<Date>
|
| Static detectAllFieldsInEntity | ||||||
detectAllFieldsInEntity(entityOrType: Entity | EntityConstructor)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:55
|
||||||
|
Detect all
Parameters :
Returns :
literal type[]
|
| Static detectFieldInEntity | ||||||
detectFieldInEntity(entityOrType: Entity | EntityConstructor)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:45
|
||||||
|
Parameters :
Returns :
string | undefined
|
| Async importMapFunction | ||||||||||||
importMapFunction(val: any, schemaField?: EntitySchemaField | undefined, additional?: any)
|
||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||
|
Defined in
DefaultDatatype:88
|
||||||||||||
|
Parameters :
Returns :
unknown
|
| Async importMatchField | ||||||||||||||||
importMatchField(schemaField: EntitySchemaField, columns: ColumnImportInput[], importProcessingContext?: ImportProcessingContext)
|
||||||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||||||
|
Defined in
DefaultDatatype:223
|
||||||||||||||||
|
Map all columns mapped to one target field to the value(s) stored there. ImportService calls this once per target field per row with every column mapped to that field. The default handles trimming and array splitting and delegates each individual value to importMapFunction. Datatypes that need to consider several columns together (e.g. matching an entity by more than one property) override this. (isArray=true), or undefined if nothing was mapped
Parameters :
Returns :
Promise<unknown>
the value to store: a single value (isArray=false) or array (isArray=true), or undefined if nothing was mapped |
| normalizeSchemaField | ||||||||
normalizeSchemaField(schemaField: EntitySchemaField)
|
||||||||
|
Inherited from
DefaultDatatype
|
||||||||
|
Defined in
DefaultDatatype:316
|
||||||||
|
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
Parameters :
Returns :
EntitySchemaField
The schema field to use (default: unchanged) |
| sortValue | ||||||
sortValue(_fieldValue: EntityType)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:352
|
||||||
|
Return a comparable primitive for sorting this field's value in a list column.
Return
Parameters :
Returns :
number | string | undefined
|
| Static dataType |
Type : string
|
Default value : "date-with-age"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:12
|
| editComponent |
Type : string
|
Default value : "EditAge"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:15
|
| Static label |
Type : string
|
Default value : $localize`:datatype-label:date of birth (date + age)`
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:13
|
| importConfigComponent |
Type : string
|
Default value : "DateImportConfig"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:86
|
| viewComponent |
Type : string
|
Default value : "DisplayDate"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:64
|
| Readonly importAllowsMultiMapping |
Type : boolean
|
Default value : false
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:134
|
|
Whether this datatype allows multiple values to be mapped to the same entity field during import. |
import { DateOnlyDatatype } from "../date-only/date-only.datatype";
import { Injectable } from "@angular/core";
import { DateWithAge } from "./dateWithAge";
import { EntitySchemaField } from "../../entity/schema/entity-schema-field";
import { ExportColumnMapping } from "../../entity/default-datatype/default.datatype";
/**
* Similar to the 'date-only' datatype but it uses the `DateWithAge` class which provides the `age` function.
*/
@Injectable()
export class DateWithAgeDatatype extends DateOnlyDatatype {
static override dataType = "date-with-age";
static override label: string = $localize`:datatype-label:date of birth (date + age)`;
override editComponent = "EditAge";
override transformToObjectFormat(
value,
schemaField: EntitySchemaField,
parent: any,
): DateWithAge {
const dateValue = super.transformToObjectFormat(value, schemaField, parent);
if (!dateValue) {
return undefined;
}
return new DateWithAge(dateValue);
}
/**
* Export the raw date column plus an additional, derived "age" column.
*
* The age is a virtual property computed from the date and is not stored on the
* entity itself, so without this dedicated column the value would be missing
* from exports (see #4057).
*/
override getExportColumns(
schemaField: EntitySchemaField,
): ExportColumnMapping[] {
const columns = super.getExportColumns(schemaField);
if (columns.length === 0) {
return columns;
}
return [
...columns,
{
keySuffix: "_age",
label: schemaField.label + $localize`:export age column suffix: (age)`,
resolveValue: (value: DateWithAge) => value?.age,
},
];
}
}