File

projects/i-components/src/lib/components/basewrapper/basewrapper.component.ts

Description

Base class for components used for configuration of UI elements

This base class is not meant to be used for component controls

Index

Properties
Methods

Properties

Protected pendingResourceValues
Type : Array<>

Pending resource assignments

These assignments are performed when the model is available

Protected pendingSetValuesColumns
Type : Array<>
Default value : []

A collection of pending values to assign to the model

Methods

Protected applyPendingResourceAssignment
applyPendingResourceAssignment(model: DependencyObject)

Apply pending resource assignments

Parameters :
Name Type Optional
model DependencyObject No
Returns : void
Protected checkForStaticResourceReference
checkForStaticResourceReference(property: DependencyProperty, obj: any)

Verifies if the given value is a resource value

Parameters :
Name Type Optional Description
property DependencyProperty No

property to assign

obj any No

static resource reference candidate

Returns : boolean

{boolean} true if the value was assigned

Protected resolveResource
resolveResource(key: any)

Resolve the resource in the current context

Parameters :
Name Type Optional
key any No
Returns : any
import {
  Application,
  DependencyObject,
  DependencyProperty,
  PropertyPath,
} from '@mobilize/wms-framework';

/**
 *  Base class for components used for configuration of UI elements
 *
 *  This base class is not meant to be used for component controls
 *
 * @export
 * @class BaseWrapperComponent
 */
export class BaseWrapperComponent {
  /**
   *  Pending resource assignments
   *
   *  These assignments are performed when the model is available
   *
   * @private
   * @type {Array<[DependencyProperty, any]>}
   * @memberof BaseWrapperComponent
   */
  protected pendingResourceValues: Array<[DependencyProperty, any]>;

  /**
   * A collection of pending values to assign to the model
   *
   * @protected
   * @type {Array<[DependencyProperty, any]>}
   * @memberof BaseWrapperComponent
   */
  protected pendingSetValuesColumns: Array<[DependencyProperty, any]> = [];
  /**
   *  Verifies if the given value is a resource value
   *
   * @protected
   * @param {DependencyProperty} property property to assign
   * @param {*} obj static resource reference candidate
   * @return {*}  {boolean} true if the value was assigned
   * @memberof BaseWrapperComponent
   */
  /* istanbul ignore next */
  protected checkForStaticResourceReference(
    property: DependencyProperty,
    obj: any
  ): boolean {
    if (!this.pendingResourceValues) {
      this.pendingResourceValues = [];
    }
    if (obj && typeof obj.resourceKey === 'string') {
      this.pendingResourceValues.push([property, obj]);
      return true;
    } else {
      return false;
    }
  }

  /**
   * Apply pending resource assignments
   *
   * @protected
   * @param {DependencyObject} model
   * @memberof BaseWrapperComponent
   */
  /* istanbul ignore next */
  protected applyPendingResourceAssignment(model: DependencyObject) {
    if (this.pendingResourceValues) {
      for (const [property, value] of this.pendingResourceValues) {
        let resource = this.resolveResource(value.resourceKey);
        if (resource) {
          if (typeof value.bindingPath === 'string') {
            const bindingPath = new PropertyPath(value.bindingPath);
            resource = bindingPath.getValueFromContextObject(resource);
            if (typeof resource === 'undefined') {
              continue;
            }
          }
          model.setValue(property, resource);
        }
      }
    }
    this.pendingResourceValues = null;
  }

  /**
   * Resolve the resource in the current context
   *
   * @protected
   * @param {*} key
   * @returns
   * @memberof BaseWrapperComponent
   */
  protected resolveResource(key: any) {
    return Application.Current.getResourceByKey(key);
  }
}

result-matching ""

    No results matching ""