File

src/app/core/default-values/default-value-strategy.interface.ts

Description

A special strategy to define and set default values, which can be used by the DefaultValueService, e.g. dynamic placeholders or inherited values.

Index

Properties
Methods

Properties

Abstract mode
Type : string

The mode identifying this strategy in the config and admin UI.

Methods

Abstract getAdminUI
getAdminUI()

The Admin UI component and details.

getDefaultValueUiHint
getDefaultValueUiHint(form: EntityForm<T>, field: FormFieldConfig)
Type parameters :
  • T

Get details about the status and context of a default value field to display to the user.

Parameters :
Name Type Optional
form EntityForm<T> No
field FormFieldConfig No
Async initEntityForm
initEntityForm(form: EntityForm<T>)
Type parameters :
  • T
Parameters :
Name Type Optional
form EntityForm<T> No
Returns : Promise<void>
Async onFormValueChanges
onFormValueChanges(form: EntityForm<T>)
Type parameters :
  • T
Parameters :
Name Type Optional
form EntityForm<T> No
Returns : Promise<void>
Abstract setDefaultValue
setDefaultValue(targetFormControl: AbstractControl, fieldConfig: EntitySchemaField, form: EntityForm<any>)

Calculate and set the default value for a form control, according to the custom strategy. This is the central function to set a default value to the given targetFormControl while a form is initialized.

Parameters :
Name Type Optional Description
targetFormControl AbstractControl<any | any> No

The form control to set the default value for.

fieldConfig EntitySchemaField No

The field configuration of this entity field.

form EntityForm<any> No

The overall entity form, including all related fields to support complex, interrelated value calculations.

Returns : void
import { AbstractControl } from "@angular/forms";
import { EntitySchemaField } from "../entity/schema/entity-schema-field";
import { EntityForm } from "../common-components/entity-form/entity-form.service";
import { Entity } from "../entity/model/entity";
import { Type } from "@angular/core";
import { DefaultValueHint } from "./default-value-service/default-value.service";
import { FormFieldConfig } from "../common-components/entity-form/FormConfig";

/**
 * A special strategy to define and set default values, which can be used by the DefaultValueService,
 * e.g. dynamic placeholders or inherited values.
 */
export abstract class DefaultValueStrategy {
  /**
   * The mode identifying this strategy in the config and admin UI.
   */
  abstract mode: string;

  /**
   * The Admin UI component and details.
   */
  abstract getAdminUI(): Promise<AdminDefaultValueContext>;

  /**
   * Calculate and set the default value for a form control, according to the custom strategy.
   * This is the central function to set a default value to the given targetFormControl while a form is initialized.
   * @param targetFormControl The form control to set the default value for.
   * @param fieldConfig The field configuration of this entity field.
   * @param form The overall entity form, including all related fields to support complex, interrelated value calculations.
   */
  abstract setDefaultValue(
    targetFormControl: AbstractControl<any, any>,
    fieldConfig: EntitySchemaField,
    form: EntityForm<any>,
  ): void;

  async onFormValueChanges<T extends Entity>(
    form: EntityForm<T>,
  ): Promise<void> {}

  async initEntityForm<T extends Entity>(form: EntityForm<T>): Promise<void> {}

  /**
   * Get details about the status and context of a default value field to display to the user.
   * @param form
   * @param field
   */
  getDefaultValueUiHint<T extends Entity>(
    form: EntityForm<T>,
    field: FormFieldConfig,
  ): DefaultValueHint | undefined {
    return undefined;
  }
}

/**
 * Details required to display the admin UI for a default value strategy.
 */
export interface AdminDefaultValueContext {
  mode: string;
  component: Type<any>;
  icon: string;
  description: string;
}

results matching ""

    No results matching ""