Class CustomSectionMeta

A custom section meta containing any number of custom fields meta.

Hierarchy

Constructors

  • Object initialization, setting all the default values.

    Parameters

    • Optional newData: any

      the data to load, optional

    • Optional options: any

      custom options to apply; they will depend on the child resource

      Usually, there is no need to implement the constructor; implicitly, it will call the load of the child resource and therefore loading all the resources with default values. If needed, this is the suggested implementation:

      super();
      this.load(x);
      // ...

    Returns CustomSectionMeta

Properties

description?: Label

The description of the section. Support to multilanguage. Optional.

displayTemplate?: string[][]

Matrix that sets the way the section is shown in the template; when null, a section won't be shown in the template. Optional.

Example, with f1, f2, etc. as fields names,

[ ['f1'], ['f2','f3','f7'], ['f5','f8'] ]

becomes:

[      f1      ]
[ f2 | f3 | f7 ]
[ f5 | f8 ]

Object containg attributes of type CustomFieldMeta; e.g.

fields.name: CustomFieldMeta;
fields.surname: CustomFieldMeta;
...
fieldsLegend: string[]

Ordered list of the fields (names) to expect in the section. Example: ['name', 'surname', ...].

name?: Label

The name of the section. Support to multilanguage. Optional.

Methods

  • Return an attribute in a cleaned standard that force-cast the element.

    Parameters

    • origin: any

      the origin attribute, to cast

    • castFunction: ((x) => any)

      the cast function, e.g. Boolean, Number, String, x => new CustomClass(x), etc.

        • (x): any
        • Parameters

          • x: any

          Returns any

    • Optional defaultVal: any

      if set, the fallback value instead of null

    Returns any

    cleaned attribute

  • Return an array in a cleaned standard that force-cast each element, keeping only the valid ones.

    Parameters

    • origin: any[]

      the origin array, to cast and check

    • castFunction: ((x) => any)

      the cast function, e.g. x => String(x) or x => new CustomClass(x)

        • (x): any
        • Parameters

          • x: any

          Returns any

    • Optional defaultVal: any

      if set, the fallback value instead of null

    Returns any[]

    cleaned array

  • Load the attributes from an already existing resource.

    Parameters

    • x: any

      the data to load

    • languages: Languages

      custom options to apply; they will depend on the child resource

      Typical implementation:

      super.load(newData);
      this.attr = this.clean(newData.attr, String);
      this.attr2 = this.clean(newData.attr2, Number, 0);
      this.attr3 = this.clean(newData.attr3, a => new Date(a), Date.now());
      this.arr = this.cleanArray(arr, String);
      // ...

    Returns void

  • Load the values of the specified fields.

    Parameters

    • newFields: any

      the values to set in the fields

    Returns any

  • Load the attributes from an already existing resource and then force some attributes to assume safeData values. The function is usually used in the back-end to mix together db data with new data, without the risk of changing ids and other attributes which are managed in appositely curated scenario.

    Parameters

    • newData: any

      the data to load

    • safeData: any

      the attributes to force to specific values

    • Optional options: any

      custom options to apply; they will depend on the child resource

      Typical implementation:

      super.safeLoad(newData, safeData);
      this.keyAttr = safeData.keyAttr;
      this.importantAttr = safeData.importantAttr;
      this.isDraft = safeData.isDraft;
      // ...

      Note well: there is no need to call this.load(), since it's implicitly called from super.safeLoad(), which will anyway use the child version of the method.

    Returns void

  • Valide the object's attributes, performing all the checkings.

    Parameters

    • languages: Languages

      custom options to apply; they will depend on the implementations

    Returns string[]

    errors if empty, the checkings are successfully passed.

    Typical implementation:

    const e = super.validate();
    if(this.iE(this.attr)) e.push(`attr`);
    // ...
    return e;
  • Validate the fields and return an array with errors, if any.

    Parameters

    • fields: any

    Returns string[]

Generated using TypeDoc