src/app/features/location/location.datatype.ts
Properties |
|
Methods |
| Async importMapFunction | ||||||
importMapFunction(val: any)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:48
|
||||||
|
Parameters :
Returns :
Promise<GeoLocation>
|
| transformToObjectFormat | ||||||
transformToObjectFormat(value: GeoLocation)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:20
|
||||||
|
Parameters :
Returns :
GeoLocation
|
| Async anonymize | ||||||||||||||||
anonymize(value: EntityType, schemaField: EntitySchemaField, parent: any)
|
||||||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||||||
|
Defined in
DefaultDatatype:148
|
||||||||||||||||
|
(Partially) anonymize to "retain-anonymized" for reporting purposes without personal identifiable information.
Parameters :
Returns :
Promise<any>
|
| importIncompleteAdditionalConfigBadge | ||||||
importIncompleteAdditionalConfigBadge(col: ColumnMapping)
|
||||||
|
Inherited from
DefaultDatatype
|
||||||
|
Defined in
DefaultDatatype:140
|
||||||
|
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 :
Returns :
string
|
| transformToDatabaseFormat | ||||||||||||||||
transformToDatabaseFormat(value: EntityType, schemaField?: EntitySchemaField, parent?: Entity)
|
||||||||||||||||
|
Inherited from
DefaultDatatype
|
||||||||||||||||
|
Defined in
DefaultDatatype:80
|
||||||||||||||||
|
Transformation function taking a value in the format that is used in entity instances and returning the value in the format used in database objects. Example :
Parameters :
Returns :
DBType
|
| Static dataType |
Type : string
|
Default value : "location"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:14
|
| editComponent |
Type : string
|
Default value : "EditLocation"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:17
|
| Static label |
Type : string
|
Default value : $localize`:datatype-label:location (address + map)`
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:15
|
| viewComponent |
Type : string
|
Default value : "ViewLocation"
|
|
Inherited from
DefaultDatatype
|
|
Defined in
DefaultDatatype:18
|
| 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
|
|
Defined in
DefaultDatatype:132
|
|
A component to be display as a dialog to configure the transformation function (e.g. defining a format or mapping) |
import { Injectable, inject } from "@angular/core";
import { lastValueFrom } from "rxjs";
import { DefaultDatatype } from "../../core/entity/default-datatype/default.datatype";
import { GeoLocation } from "./geo-location";
import { GeoResult, GeoService } from "./geo.service";
@Injectable()
export class LocationDatatype extends DefaultDatatype<
GeoLocation,
GeoLocation
> {
private geoService = inject(GeoService);
static override dataType = "location";
static override label: string = $localize`:datatype-label:location (address + map)`;
override editComponent = "EditLocation";
override viewComponent = "ViewLocation";
override transformToObjectFormat(value: GeoLocation): GeoLocation {
if (typeof value !== "object") {
// until we have an extended location datatype that includes a custom address addition field, discard invalid values (e.g. in case datatype was changed)
return undefined;
}
// migrate from legacy format
if (
!value.hasOwnProperty("locationString") &&
!value.hasOwnProperty("geoLookup")
) {
value = {
geoLookup: value as unknown as GeoResult,
};
}
// fix errors from broken migrations
while (value?.geoLookup && "geoLookup" in value.geoLookup) {
value.geoLookup = (value.geoLookup as { geoLookup: GeoResult }).geoLookup;
}
if (!value.locationString) {
value.locationString = value.geoLookup?.display_name ?? "";
}
return value;
}
override async importMapFunction(val: any): Promise<GeoLocation> {
if (!val) {
return undefined;
}
const geoResults = await lastValueFrom(this.geoService.lookup(val));
return { locationString: val, geoLookup: geoResults[0] };
}
}