File

src/app/features/file/file.datatype.ts

Description

Datatype for saving a file on an entity property.

The name of the file is saved on the property while the file itself is stored in another database.

Usage in code:

Example :
@DatabaseProperty({ dataType: "file", label: "My label"}) myFileProperty: string;

Usage in config:

Example :
{
  "name": "myFileProperty",
  "schema": {
    "dataType": "file",
    "label": "My label"
  }
}

Extends

StringDatatype

Index

Properties
Methods

Methods

Async anonymize
anonymize(value: string, schemaField: EntitySchemaField, parent: any)
Inherited from DefaultDatatype
Defined in DefaultDatatype:33
Parameters :
Name Type Optional
value string No
schemaField EntitySchemaField No
parent any No
Returns : Promise<any>
transformToDatabaseFormat
transformToDatabaseFormat(value)
Inherited from DefaultDatatype
Defined in DefaultDatatype:38
Parameters :
Name Optional
value No
Returns : any
transformToObjectFormat
transformToObjectFormat(value)
Inherited from DefaultDatatype
Defined in DefaultDatatype:42
Parameters :
Name Optional
value No
Returns : 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
Type : string
Default value : "file"
Inherited from DefaultDatatype
Defined in DefaultDatatype:27
editComponent
Type : string
Default value : "EditFile"
Inherited from DefaultDatatype
Defined in DefaultDatatype:31
Static label
Type : string
Default value : $localize`:datatype-label:file attachment`
Inherited from DefaultDatatype
Defined in DefaultDatatype:28
viewComponent
Type : string
Default value : "ViewFile"
Inherited from DefaultDatatype
Defined in DefaultDatatype:30
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)

import { StringDatatype } from "../../core/basic-datatypes/string/string.datatype";
import { Injectable } from "@angular/core";
import { EntitySchemaField } from "../../core/entity/schema/entity-schema-field";

/**
 * Datatype for saving a file on an entity property.
 *
 * The name of the file is saved on the property while the file itself is stored in another database.
 *
 * Usage in code:
 * ```javascript
 * @DatabaseProperty({ dataType: "file", label: "My label"}) myFileProperty: string;
 * ```
 * Usage in config:
 * ```json
 * {
 *   "name": "myFileProperty",
 *   "schema": {
 *     "dataType": "file",
 *     "label": "My label"
 *   }
 * }
 * ```
 */
@Injectable()
export class FileDatatype extends StringDatatype {
  static override dataType = "file";
  static override label: string = $localize`:datatype-label:file attachment`;

  override viewComponent = "ViewFile";
  override editComponent = "EditFile";

  override async anonymize(
    value: string,
    schemaField: EntitySchemaField,
    parent: any,
  ): Promise<any> {
    // accessing the id of the entity property seems difficult here
    // file anonymization requires the FileService to actively delete - not supporting partial anonymization for now
    // --> see EntityRemoveService for full anonymization, removing files
    throw new Error(
      "'retain-anonymized' is not implemented for 'file' datatype",
    );
  }
}

/**
 * (Optional) "additional" object to configure details of a "file" datatype / form field.
 */
export interface FileFieldConfig {
  /**
   * The accepted file types for file selection dialog.
   * If not defined, allows any file.
   */
  acceptedFileTypes?: string;

  /**
   * The maxSize to which the image will be automatically resized before upload.
   */
  imageCompression?: number;
}

results matching ""

    No results matching ""