File

projects/i-components/src/lib/components/xam-grid-settings/xam-grid-paging.component.ts

Description

Placeholder for the pagination settings template object

Metadata

selector wm-xam-grid-pager-settings
template
<ng-content></ng-content>
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import {
  PagerSettings,
  BindingInfo,
  PagingLocation,
} from '@mobilize/wms-framework';
import { Utils } from '../../utils';
import { BaseComponent } from '../base/base.component';

/**
 * Placeholder for the pagination settings template object
 *
 * @export
 * @class XamGridPagerSettingsComponent
 */
@Component({
  selector: 'wm-xam-grid-pager-settings',
  template: `<ng-content></ng-content>`,
})
export class XamGridPagerSettingsComponent {}

/**
 * Xam grid pagination settings as template
 *
 * @export
 * @class PagerSettingsComponent
 */
@Component({
  selector: 'wm-pager-settings',
  template: ``,
})
export class PagerSettingsComponent extends BaseComponent implements OnInit {
  /**
   * Gets the value of the AllowPaging from the model.
   *
   * @memberof PagerSettingsComponent
   */
  public get allowPagingValue(): PagingLocation {
    return this.model.AllowPaging;
  }

  /**
   * Gets the value of the AllowPaging property as a string.
   *
   * @memberof PagerSettingsComponent
   */
  public get allowPaging(): BindingInfo | string {
    let allowPagingString = '';
    switch (this.model.AllowPaging) {
      case PagingLocation.Both:
        allowPagingString = 'Both';
        break;
      case PagingLocation.Bottom:
        allowPagingString = 'Bottom';
        break;
      case PagingLocation.Hidden:
        allowPagingString = 'Hidden';
        break;
      case PagingLocation.Top:
        allowPagingString = 'Top';
        break;
      default:
        allowPagingString = 'None';
        break;
    }
    return allowPagingString;
  }

  /**
   * Sets the value of the AllowPaging property.
   *
   * @memberof PagerSettingsComponent
   */
  @Input()
  public set allowPaging(value: BindingInfo | string) {
    /* istanbul ignore else */
    if (
      !this.checkAndRegisterCompatibilityBinding(
        PagerSettings.AllowPagingProperty,
        value
      )
    ) {
      /* istanbul ignore else */
      if (PagingLocation[value as string] !== undefined) {
        this.model.AllowPaging = PagingLocation[value as string];
      }
    }
  }

  /**
   * Event emitter for two-way binding.
   *
   * @type {EventEmitter<PagingLocation>}
   * @memberof PagerSettingsComponent
   */
  @Output()
  allowPagingChange: EventEmitter<PagingLocation> = new EventEmitter<PagingLocation>();

  /**
   * Allows to configure the number of items that will be displayed per page.
   *
   * @memberof PagerSettingsComponent
   */
  @Input()
  public get pageSize(): number | BindingInfo {
    return this.model.PageSize;
  }

  public set pageSize(value: number | BindingInfo) {
    /* istanbul ignore else */
    if (
      !this.checkAndRegisterCompatibilityBinding(
        PagerSettings.PageSizeProperty,
        value
      )
    ) {
      this.model.PageSize = value as number;
    }
  }

  /**
   * Event emitter for two-way binding.
   *
   * @type {EventEmitter<number>}
   * @memberof PagerSettingsComponent
   */
  @Output()
  pageSizeChange: EventEmitter<number> = new EventEmitter<number>();

  /**
   * Gets/sets what page of data will be displayed.
   *
   * @memberof PagerSettingsComponent
   */
  @Input()
  public get currentPageIndex(): number | BindingInfo {
    return this.model.CurrentPageIndex;
  }

  public set currentPageIndex(value: number | BindingInfo) {
    /* istanbul ignore else */
    if (
      !this.checkAndRegisterCompatibilityBinding(
        PagerSettings.CurrentPageIndexProperty,
        value
      )
    ) {
      this.model.CurrentPageIndex = value as number;
    }
  }

  /**
   * Event emitter for two way binding
   *
   * @type {EventEmitter<number>}
   * @memberof PagerSettingsComponent
   */
  @Output()
  currentPageIndexChange: EventEmitter<number> = new EventEmitter<number>();

  /**
   * Pager settings model
   *
   * @memberof PagerSettingsComponent
   */
  public model = new PagerSettings();

  /**
   * Update the current model with the new value from the xam grid parent instance.
   * If the parent instance is already set, then update the model with the new values.
   * @param {PagerSettings} parentModel - The parent model instance for the paging.
   * @memberof PagerSettingsComponent
   */
  setupModelFromParent(parentModel: PagerSettings) {
    const mergeModel = Utils.mergeObjects(this.model, parentModel);
    this.setupModel(mergeModel);
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""