File

src/utility/configurables/dataConfigurable.abstract.ts

Description

This is the base class of all configurable items; items that represents the configuration that is applied to a search result (Distribution) in order to retrieve data.

Implements

DataConfigurableI

Index

Properties
Methods

Constructor

constructor(distributionDetails: DistributionDetails, paramValues: Array, spatialOverrides?: BoundingBox, temporalOverrides?: TemporalRange)

Initialises the object, spatially and temporally linking if possible. configuration is applied to.

Parameters :
Name Type Optional Description
distributionDetails DistributionDetails No

The detailed search result (distribution) object that a configuration is applied to.

paramValues Array<ParameterValue> No

An array of initial parameter values.

spatialOverrides BoundingBox Yes

Overriding spatial parameter values.

temporalOverrides TemporalRange Yes

Overriding temporal parameter values.

Properties

Public Readonly actions
Type : null | Array<DataConfigurableAction>

An array of DataConfigurableActions that can be applied to this configurable.

Public changed
Default value : false

Whether any of the #newParamValues have changed or not.

Public Readonly context
Type : string
Public Readonly currentParamValues
Type : Array<ParameterValue>

An array of ParameterValue objects representing values that have been applied to any visualizations etc.

Public Readonly distributionDetails
Type : DistributionDetails
The detailed search result (distribution) object that a configuration is applied to.
Public Readonly id
Type : string

the object's identifier.

Public Readonly isDownloadable
Type : boolean

Copied from DistributionDetails

Public Readonly isGraphable
Type : boolean

Copied from DistributionDetails

Public Readonly isMappable
Type : boolean

Copied from DistributionDetails

Public Readonly isTabularable
Type : boolean

Copied from DistributionDetails

Public loading
Default value : false

Whether the #newParamValues are in the process of being applied or not.

Public Readonly name
Type : string

the object's name.

Private newParamValues
Type : Array<ParameterValue>

An array of ParameterValue objects that have been changed and have not yet been applied to any visualizations etc.

Private Readonly parameterDefinitions
Type : ParameterDefinitions

The ParameterDefinitions retrieved from a DistributionDetails item.

Public sameAsDefaults
Default value : true

Whether all of the #newParamValues are the same as the defaults or not.

Private Readonly showSpatialCoverageSrc
Default value : new BehaviorSubject<boolean>(false)

Whether a user has selected to show the spatial coverage for this item or not.

Public showSpatialObs
Default value : this.showSpatialCoverageSrc.asObservable()
Private spatialLinked
Default value : false

Whether any spatial parameter values in this configuration are linked to page-wide values.

Public Readonly styleObs
Default value : this.styleSource.asObservable()
Private Readonly styleSource
Default value : new BehaviorSubject<null | Style>(null)

An rxjs/BehaviorSubject holding the Style object for this configurable.

Private temporalLinked
Default value : false

Whether any temporal parameter values in this configuration are linked to page-wide values.

Protected triggerReloadFunc
Type : function

A function that will trigger a reload of visual representations of this object.

Public valid
Default value : true

Whether all #newParamValues are valid or not.

Methods

Protected evaluateActionVisibility
evaluateActionVisibility()

Calls the DataConfigurableAction function on all #actions.

Returns : void
Public getCurrentSpatialBounds
getCurrentSpatialBounds()
Returns : BoundingBox
Public getCurrentTemporalRange
getCurrentTemporalRange()
Returns : TemporalRange
Public getDistributionDetails
getDistributionDetails()

Retrieves the DistributionDetails that this object was created with.

Public getDownloadableFormats
getDownloadableFormats()

Returns an Array of DistributionFormats available on this configurable, that are classified as downloadable.

Public getGraphableFormats
getGraphableFormats()

Returns an Array of DistributionFormats available on this configurable, that are classified as graphable.

Public getMappableableFormats
getMappableableFormats()

Returns an Array of DistributionFormats available on this configurable, that are classified as mappable.

Public getNewParameterValues
getNewParameterValues()

Retrieves the #newParamValues variable.

Returns : Array<ParameterValue>
Public getNewSpatialBounds
getNewSpatialBounds()
Returns : BoundingBox
Public getNewTemporalRange
getNewTemporalRange()
Returns : TemporalRange
Public getParameterDefinitions
getParameterDefinitions()

Retrieves the ParameterDefinitions from the DistributionDetails that this object was created with.

Public getShowSpatialCoverage
getShowSpatialCoverage()
Returns : boolean
Public getSpatialCoverage
getSpatialCoverage()
Public getStyle
getStyle()

Returns the style in #styleSource.

Returns : null | Style
Public isOnlyDownloadable
isOnlyDownloadable()
Returns : boolean
Public isSpatialLinked
isSpatialLinked()

returns the value of the the #spatialLinked variable.

Returns : boolean
Public isTemporalLinked
isTemporalLinked()
Returns : boolean
Protected paramsSameAsDefaults
paramsSameAsDefaults()
Returns : boolean
Protected paramValuesSame
paramValuesSame(params1: Array, params2: Array)

This function compares two Arrays of ParameterValues. As default value on param definitions are now set to "" on init if not set, ths number of param values should be constant.

Parameters :
Name Type Optional Description
params1 Array<ParameterValue> No

First set of ParameterValues.

params2 Array<ParameterValue> No

Second set of ParameterValues.

Returns : boolean

true if all values in params1 are equivalent to the item with the same key in params2. As default value on param definitions are now set to "" on init if not set, ths number of param values should be constant.

Public reload
reload(newConfigurable?: DataConfigurable)

The reload function in TypeScript triggers a reload with optional new configuration after a delay. method is an optional parameter of type DataConfigurable. It is used to provide a new configuration for reloading data. If a newConfigurable object is provided, it will be used for reloading data; otherwise, the method will which the method is being called.

Parameters :
Name Type Optional Description
newConfigurable DataConfigurable Yes
  • The newConfigurable parameter in the reload method is an optional parameter of type DataConfigurable. It is used to provide a new configuration for reloading data. If a newConfigurable object is provided, it will be used for reloading data; otherwise, the method will
Protected resetParameterValues
resetParameterValues()

Sets the #newParamValues variable to a copy of the #currentParamValues variable, as it was after initialisation.

Returns : void
Public setLoading
setLoading(loading: boolean)

Sets the internal #loading variable before calling #updateActionsEnabledStatus.

Parameters :
Name Type Optional
loading boolean No
Public setNewParams
setNewParams(newParamValues: Array)

The function setNewParams updates parameter values and related properties, and returns the instance for chaining. parameter values. the class.

Parameters :
Name Type Optional Description
newParamValues Array<ParameterValue> No
  • An array of new parameter values that will be used to update the current parameter values.
Protected setParameterValuesToDefaults
setParameterValuesToDefaults()

Sets the #newParamValues variable to the default values obtained from the #distributionDetails object.

Returns : void
Public setShowSpatialCoverage
setShowSpatialCoverage(show: boolean)
Parameters :
Name Type Optional
show boolean No
Public setSpatialLinked
setSpatialLinked(linked: boolean)

Sets the value of the the #spatialLinked variable and calls reload.

Parameters :
Name Type Optional Description
linked boolean No

Whether spatially linked or not.

Public setStyle
setStyle(style: null | Style, force)

The function setStyle updates the style of an element if it is different from the current style or if forced to do so. or an object of type Style. a default value of false. It is used to determine whether the style should be set even if it is the same as the current style. If force is set to true, the style will be

Parameters :
Name Type Optional Default value Description
style null | Style No
  • The style parameter in the setStyle method can be either null or an object of type Style.
force No false
  • The force parameter in the setStyle method is a boolean parameter with a default value of false. It is used to determine whether the style should be set even if it is the same as the current style. If force is set to true, the style will be
Public setTemporalLinked
setTemporalLinked(linked: boolean)
Parameters :
Name Type Optional
linked boolean No
Public setTriggerReloadFunc
setTriggerReloadFunc(func: (configurable: DataConfigurable) => void)
Parameters :
Name Type Optional
func function No
Public setValid
setValid(valid: boolean)

Sets the internal #valid variable before calling #updateActionsEnabledStatus.

Parameters :
Name Type Optional Description
valid boolean No

Whether this object is valid or not.

Protected updateActionsEnabledStatus
updateActionsEnabledStatus()

Calls the DataConfigurableAction function on all #actions using the #valid, #changed and #loading values.

Returns : void
Public watchStyle
use styleobs instead
watchStyle()

Returns an rxjs/Observable object from #styleSource, containing the current style.

import { ParameterValue } from 'api/webApi/data/parameterValue.interface';
import { DataConfigurableAction } from './dataConfigurableAction';
import { DistributionDetails } from 'api/webApi/data/distributionDetails.interface';
import { Style } from 'utility/styler/style';
import { Observable, BehaviorSubject } from 'rxjs';
import { SpatialRange } from 'api/webApi/data/spatialRange.interface';
import { BoundingBox } from 'api/webApi/data/boundingBox.interface';
import { TemporalRange } from 'api/webApi/data/temporalRange.interface';
import { ParameterDefinitions } from 'api/webApi/data/parameterDefinitions.interface';
import { DistributionFormat } from 'api/webApi/data/distributionFormat.interface';
import { DataConfigurableI } from './dataConfigurableI.interface';
import { DistributionType } from 'api/webApi/data/distributionType.enum';

/**
 * This is the base class of all configurable items; items that represents the
 * configuration that is applied to a search result (Distribution) in order to retrieve data.
 *
 */
export abstract class DataConfigurable implements DataConfigurableI {
  /** Copied from {@link DistributionDetails#isMappable} */
  public readonly isMappable: boolean;
  /** Copied from {@link DistributionDetails#isDownloadable} */
  public readonly isDownloadable: boolean;
  /** Copied from {@link DistributionDetails#isGraphable} */
  public readonly isGraphable: boolean;
  /** Copied from {@link DistributionDetails#isTabularable} */
  public readonly isTabularable: boolean;

  public readonly context: string;

  /** Whether all {@link #newParamValues} are valid or not. */
  public valid = true;
  /** Whether any of the {@link #newParamValues} have changed or not. */
  public changed = false;
  /** Whether all of the {@link #newParamValues} are the same as the defaults or not. */
  public sameAsDefaults = true;
  /** Whether the {@link #newParamValues} are in the process of being applied or not. */
  public loading = false;

  /** An array of {@link DataConfigurableAction}s that can be applied to this configurable. */
  public readonly actions: null | Array<DataConfigurableAction>;
  /**
   * An array of {@link ParameterValue} objects representing values that have been applied to
   * any visualizations etc.
   */
  public readonly currentParamValues: Array<ParameterValue>;

  /** the object's identifier. */
  public readonly id: string;
  /** the object's name. */
  public readonly name: string;

  /** The {@link ParameterDefinitions} retrieved from a {@link DistributionDetails} item. */
  private readonly parameterDefinitions: ParameterDefinitions;

  /** Whether a user has selected to show the spatial coverage for this item or not. */
  private readonly showSpatialCoverageSrc = new BehaviorSubject<boolean>(false);
  // eslint-disable-next-line @typescript-eslint/member-ordering
  public showSpatialObs = this.showSpatialCoverageSrc.asObservable();

  /** An rxjs/BehaviorSubject holding the {@link Style} object for this configurable. */
  private readonly styleSource = new BehaviorSubject<null | Style>(null);
  // eslint-disable-next-line @typescript-eslint/member-ordering
  public readonly styleObs = this.styleSource.asObservable();

  /** A function that will trigger a reload of visual representations of this object. */
  // eslint-disable-next-line @typescript-eslint/member-ordering
  protected triggerReloadFunc: (configurable: DataConfigurable) => void;

  /**
   * An array of {@link ParameterValue} objects that have been changed and have not yet been
   * applied to any visualizations etc.
   */
  private newParamValues: Array<ParameterValue>;

  /** Whether any spatial parameter values in this configuration are linked to page-wide values. */
  private spatialLinked = false;
  /** Whether any temporal parameter values in this configuration are linked to page-wide values. */
  private temporalLinked = false;


  /**
   * Initialises the object, spatially and temporally linking if possible.
   * @param distributionDetails The detailed search result (distribution) object that a
   * configuration is applied to.
   * @param paramValues An array of initial parameter values.
   * @param spatialOverrides Overriding spatial parameter values.
   * @param temporalOverrides Overriding temporal parameter values.
   */
  constructor(
    /** The detailed search result (distribution) object that a configuration is applied to. */
    public readonly distributionDetails: DistributionDetails,
    paramValues: Array<ParameterValue>,
    spatialOverrides?: BoundingBox,
    temporalOverrides?: TemporalRange,
  ) {
    this.id = distributionDetails.getIdentifier();
    this.name = distributionDetails.getName();
    this.isMappable = distributionDetails.isMappable;
    this.isGraphable = distributionDetails.isGraphable;
    this.isDownloadable = distributionDetails.isDownloadable;
    this.isTabularable = distributionDetails.isTabularable;

    this.parameterDefinitions = distributionDetails.getParameters();

    // we set to linked by default, if it's possible to link them

    this.spatialLinked = this.parameterDefinitions.hasSpatialParameters();
    if (this.spatialLinked && (null != spatialOverrides)) {
      paramValues = this.parameterDefinitions.updateSpatialParamsUsingBounds(spatialOverrides, paramValues);
    }

    this.temporalLinked = this.parameterDefinitions.hasTemporalParameters();
    if (this.temporalLinked && (null != temporalOverrides)) {
      paramValues = this.parameterDefinitions.updateTemporalParamsUsingRange(temporalOverrides, paramValues);
    }

    this.currentParamValues = paramValues.slice();
    this.setNewParams(paramValues.slice());

  }

  /**
   * Retrieves the {@link DistributionDetails} that this object was created with.
   */
  public getDistributionDetails(): DistributionDetails {
    return this.distributionDetails;
  }

  /**
   * Sets the internal {@link #valid} variable before calling {@link #updateActionsEnabledStatus}.
   * @param valid Whether this object is valid or not.
   */
  public setValid(valid: boolean): this {
    this.valid = valid;
    this.updateActionsEnabledStatus();
    return this;
  }

  /**
   * Sets the internal {@link #loading} variable before calling {@link #updateActionsEnabledStatus}.
   * @param valid Whether this object is loading or not.
   */
  public setLoading(loading: boolean): this {
    this.loading = loading;
    this.updateActionsEnabledStatus();
    return this;
  }

  /**
   * Returns an Array of {@link DistributionFormat}s available on this configurable, that are
   * classified as mappable.
   */
  public getMappableableFormats(): Array<DistributionFormat> {
    return this.distributionDetails.getMappableFormats();
  }
  /**
   * Returns an Array of {@link DistributionFormat}s available on this configurable, that are
   * classified as downloadable.
   */
  public getDownloadableFormats(): Array<DistributionFormat> {
    return this.distributionDetails.getDownloadableFormats();
  }

  /**
   * Returns an Array of {@link DistributionFormat}s available on this configurable, that are
   * classified as graphable.
   */
  public getGraphableFormats(): Array<DistributionFormat> {
    return this.distributionDetails.getGraphableFormats();
  }

  /**
   * The function `setStyle` updates the style of an element if it is different from the current style
   * or if forced to do so.
   * @param {null | Style} style - The `style` parameter in the `setStyle` method can be either `null`
   * or an object of type `Style`.
   * @param [force=false] - The `force` parameter in the `setStyle` method is a boolean parameter with
   * a default value of `false`. It is used to determine whether the style should be set even if it is
   * the same as the current style. If `force` is set to `true`, the style will be
   * @returns The method `setStyle` is returning `this`, which allows for method chaining.
   */
  public setStyle(style: null | Style, force = false): this {
    if (style !== this.getStyle() || force) {
      this.styleSource.next(style);
    }
    return this;
  }
  /**
   * Returns the style in {@link #styleSource}.
   */
  public getStyle(): null | Style {
    return this.styleSource.getValue();
  }
  /**
   * Returns an rxjs/Observable object from {@link #styleSource}, containing the current
   * {@link style}.
   * @deprecated use styleobs instead
   */
  public watchStyle(): Observable<null | Style> {
    return this.styleSource.asObservable();
  }

  /**
   * The function `setNewParams` updates parameter values and related properties, and returns the
   * instance for chaining.
   * @param newParamValues - An array of new parameter values that will be used to update the current
   * parameter values.
   * @returns The `setNewParams` method is returning `this`, which refers to the current instance of
   * the class.
   */
  public setNewParams(newParamValues: Array<ParameterValue>): this {
    this.newParamValues = newParamValues.slice();
    this.changed = !this.paramValuesSame(this.currentParamValues, this.newParamValues);
    this.sameAsDefaults = this.paramsSameAsDefaults();
    this.updateActionsEnabledStatus();

    return this;
  }

  /** returns the value of the the {@link #spatialLinked} variable. */
  public isSpatialLinked(): boolean {
    return this.spatialLinked;
  }
  /**
   * Sets the value of the the {@link #spatialLinked} variable and calls {@link reload}.
   * @param linked Whether spatially linked or not.
   */
  public setSpatialLinked(linked: boolean): this {
    this.spatialLinked = linked;
    this.reload();
    return this;
  }
  public getCurrentSpatialBounds(): BoundingBox {
    return this.parameterDefinitions.getSpatialBounds(Array.from(this.currentParamValues.values()));
  }
  public getNewSpatialBounds(): BoundingBox {
    return this.parameterDefinitions.getSpatialBounds(this.newParamValues);
  }

  public isTemporalLinked(): boolean {
    return this.temporalLinked;
  }
  public setTemporalLinked(linked: boolean): this {
    this.temporalLinked = linked;
    this.reload();
    return this;
  }
  public getCurrentTemporalRange(): TemporalRange {
    return this.parameterDefinitions.getTemporalRange(Array.from(this.currentParamValues.values()));
  }
  public getNewTemporalRange(): TemporalRange {
    return this.parameterDefinitions.getTemporalRange(this.newParamValues);
  }

  public setTriggerReloadFunc(func: (configurable: DataConfigurable) => void): this {
    this.triggerReloadFunc = func;
    return this;
  }

  /**
   * The `reload` function in TypeScript triggers a reload with optional new configuration after a
   * delay.
   * @param {DataConfigurable} [newConfigurable] - The `newConfigurable` parameter in the `reload`
   * method is an optional parameter of type `DataConfigurable`. It is used to provide a new
   * configuration for reloading data. If a `newConfigurable` object is provided, it will be used for
   * reloading data; otherwise, the method will
   * @returns The `reload` method is returning `this`, which refers to the instance of the class on
   * which the method is being called.
   */
  public reload(newConfigurable?: DataConfigurable): this {
    if (null == this.triggerReloadFunc) {
    } else {
      setTimeout(() => {
        this.triggerReloadFunc((newConfigurable == null) ? this : newConfigurable);
      }, 0);
    }
    return this;
  }

  public setShowSpatialCoverage(show: boolean): this {
    this.showSpatialCoverageSrc.next(show);
    this.reload();
    return this;
  }

  public getShowSpatialCoverage(): boolean {
    return this.showSpatialCoverageSrc.value;
  }

  public getSpatialCoverage(): null | SpatialRange {
    return this.distributionDetails.getSpatialRange();
  }

  /**
   * Retrieves the {@link ParameterDefinitions} from the {@link DistributionDetails} that this
   * object was created with.
   */
  public getParameterDefinitions(): ParameterDefinitions {
    return this.parameterDefinitions;
  }
  /**
   * Retrieves the {@link #newParamValues} variable.
   */
  public getNewParameterValues(): Array<ParameterValue> {
    return this.newParamValues;
  }

  public isOnlyDownloadable(): boolean {
    return this.getDistributionDetails().getType() === DistributionType.DOWNLOADABLE_FILE;
  }

  /**
   * Sets the {@link #newParamValues} variable to a copy of the {@link #currentParamValues}
   * variable, as it was after initialisation.
   */
  protected resetParameterValues(): void {
    this.setNewParams(this.currentParamValues.slice());
  }
  /**
   * Sets the {@link #newParamValues} variable to the default values obtained from the
   * {@link #distributionDetails} object.
   */
  protected setParameterValuesToDefaults(): void {
    let updatedParamValues = this.distributionDetails.getParameters().getDefaultParameterValues();

    if (this.isSpatialLinked()) {
      updatedParamValues = this.parameterDefinitions.updateSpatialParamsUsingBounds(this.getCurrentSpatialBounds(), updatedParamValues);
    }
    if (this.isTemporalLinked()) {
      updatedParamValues = this.parameterDefinitions.updateTemporalParamsUsingRange(this.getCurrentTemporalRange(), updatedParamValues);
    }
    this.setNewParams(updatedParamValues);
  }

  /**
   * Calls the {@link DataConfigurableAction#updateEnabledStatus} function on all {@link #actions}
   * using the {@link #valid}, {@link #changed} and {@link #loading} values.
   */
  protected updateActionsEnabledStatus(): void {
    if (null != this.actions) {
      this.actions.forEach((action: DataConfigurableAction) => {
        action.updateEnabledStatus(this.valid, this.changed, this.loading);
      });
    }
  }
  /**
   * Calls the {@link DataConfigurableAction#updateVisibleStatus} function on all {@link #actions}.
   */
  protected evaluateActionVisibility(): void {
    if (null != this.actions) {
      this.actions.forEach((action: DataConfigurableAction) => {
        action.updateVisibleStatus();
      });
    }
  }
  /**
   * This function compares two Arrays of {@link ParameterValue}s.
   * @param params1 First set of ParameterValues.
   * @param params2 Second set of ParameterValues.
   * @return true if all values in params1 are equivalent to the item with the same key in params2.
   * As default value on param definitions are now set to "" on init if not set,
   * ths number of param values should be constant.
   */
  protected paramValuesSame(params1: Array<ParameterValue>, params2: Array<ParameterValue>): boolean {
    const allSame = params1.every((param1: ParameterValue) => {
      const paramDef = this.parameterDefinitions.getParameter(param1.name);
      const param2 = params2.find((thisParam: ParameterValue) => (param1.name === thisParam.name));
      const param2Value = (param2 != null) ? param2.value : '';
      let same = true;
      if (paramDef !== undefined) {
        same = paramDef.areValuesSame(param1.value, param2Value);
      }
      return same;
    });
    return allSame;
  }
  protected paramsSameAsDefaults(): boolean {
    let returnVal = true;
    const paramDefs = this.getParameterDefinitions();
    if (null != paramDefs) {
      let paramValues = paramDefs.getDefaultParameterValues();
      if (this.isSpatialLinked()) {
        // filter out spatial values
        paramValues = paramDefs.filterOutSpatialParamValues(paramValues);
      }
      if (this.isTemporalLinked()) {
        // filter out spatial values
        paramValues = paramDefs.filterOutTemporalParamValues(paramValues);
      }

      returnVal = this.paramValuesSame(paramValues, this.getNewParameterValues());
    }
    return returnVal;
  }

}

results matching ""

    No results matching ""