@WidgetComponent

nm-toggle-button-cell

File

src/app/shared/widgets/imarket/list-cell-toggle-button/toggle-button-widget.component.ts

Implements

CellWidget AfterViewInit

Metadata

selector nm-toggle-button-cell
styleUrls toggle-button-widget.component.scss
templateUrl ./toggle-button-widget.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(localStorageService: LocalStorageService)
Parameters :
Name Type Optional
localStorageService LocalStorageService no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig<ToggleButtonConfiguration> no
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
onClick
onClick(event: )
Parameters :
Name Optional
event no
Returns : void
selectionChange
selectionChange(event: )
Parameters :
Name Optional
event no
Returns : void

Properties

Public alignment
alignment: string
Type : string
Public cellComponent
cellComponent: IgxGridCell
Type : IgxGridCell
Public configuration
configuration: WidgetConfig<ToggleButtonConfiguration>
Type : WidgetConfig<ToggleButtonConfiguration>
Decorators : WidgetConfiguration
Public disableCondition
disableCondition: string
Type : string
Public hide
hide: boolean
Type : boolean
Default value : false
Public hideButton
hideButton:
Default value : new ReplaySubject<boolean>(1)
Decorators : WidgetInput

Hide the button

Public listCellMode
listCellMode: boolean
Type : boolean
Public row
row: any
Type : any
Private stopPropagation
stopPropagation: boolean
Type : boolean
Private toggleButtonEntry
toggleButtonEntry: LocalStorageEntry
Type : LocalStorageEntry
Public toggleChange
toggleChange:
Default value : new ReplaySubject<any>(1)
Decorators : WidgetOutput

Emits the state when the toggle changes or emits the toggle event if the listCellMode is enabled

Public toggleClass
toggleClass: string
Type : string
Public togglerLabel
togglerLabel: string
Type : string
Public togglerLabelChannel
togglerLabelChannel:
Default value : new Subject<string>()
Decorators : WidgetInput

Sets the label for the toggle button

Public togglerTooltip
togglerTooltip: string
Type : string
Public togglerTooltipChannel
togglerTooltipChannel:
Default value : new Subject<string>()
Decorators : WidgetInput

Sets the tooltip for the toggle button

Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
Public value
value: any
Type : any
import { Component, AfterViewInit } from "@angular/core";
import { Subject, ReplaySubject } from "rxjs";
import {
  WidgetComponent,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetOutput,
  WidgetInput,
} from "../../widget.metadata";
import { WidgetConfig, getOrDefault } from "../../widget.configuration";
import { CellWidget } from "../../../components/list-cell";
import { IgxGridCell } from "@infragistics/igniteui-angular";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import { takeUntil } from "rxjs/operators";
import { deepCopy } from "../../../components/util/util.service";
import {
  LocalStorageEntry,
  LocalStorageService,
} from "../../../components/local-storage/local-storage.service";
import {
  DeletionMode,
  Scope,
} from "../../../components/local-storage/local-storage-constants";

export interface ToggleButtonConfiguration {
  /** Sets mandatory field if it is not found then the button is disabled */
  disableCondition?: string;
  /** Specifies if the button is used within a list cell @default(true) */
  listCellMode?: boolean;
  /** Specifies if we should stop the event propagation when button is clicked @default(false)*/
  stopPropagation?: boolean;
  /** Specifies the alignment*/
  alignment?: string;
  /** Sets local storage entry name */
  localStorageEntry?: string;
  /** Sets tooltip for toggle button */
  togglerTooltip?: string;
  /** Sets label for toggle button */
  togglerLabel?: string;
  /** Specifies toggle button class*/
  toggleClass?: string;
}

@WidgetComponent("nm-toggle-button-cell")
@Component({
  selector: "nm-toggle-button-cell",
  templateUrl: "./toggle-button-widget.component.html",
  styleUrls: ["./toggle-button-widget.component.scss"],
})
export class ToggleButtonWidgetComponent implements CellWidget, AfterViewInit {
  private unsubscribe = NgUnsubscribe.create();

  public row: any;
  public value: any;
  public cellComponent: IgxGridCell;

  public disableCondition: string;
  public listCellMode: boolean;
  public togglerLabel: string;
  public togglerTooltip: string;
  public alignment: string;
  public hide: boolean = false;
  private stopPropagation: boolean;
  public toggleClass: string;

  private toggleButtonEntry: LocalStorageEntry;

  /**
   * Sets the label for the toggle button
   */
  @WidgetInput()
  public togglerLabelChannel = new Subject<string>();

  /**
   * Sets the tooltip for the toggle button
   */
  @WidgetInput()
  public togglerTooltipChannel = new Subject<string>();

  /**
   * Hide the button
   */
  @WidgetInput()
  public hideButton = new ReplaySubject<boolean>(1);

  /**
   * Emits the state when the toggle changes or emits the toggle event if the listCellMode is enabled
   */
  @WidgetOutput()
  public toggleChange = new ReplaySubject<any>(1);

  @WidgetConfiguration()
  public configuration: WidgetConfig<ToggleButtonConfiguration>;

  @WidgetConfigure()
  protected configureWidget(
    configuration: WidgetConfig<ToggleButtonConfiguration>
  ) {
    this.disableCondition = this.configuration.configuration.disableCondition;
    this.listCellMode = getOrDefault(
      this.configuration.configuration.listCellMode,
      true
    );
    this.stopPropagation = getOrDefault(
      this.configuration.configuration.stopPropagation,
      false
    );

    this.alignment = getOrDefault(
      this.configuration.configuration.alignment,
      "right"
    );
    this.togglerTooltip = this.configuration.configuration.togglerTooltip;
    this.togglerLabel = this.configuration.configuration.togglerLabel;
    this.toggleClass = this.configuration.configuration.toggleClass;

    if (configuration.configuration.localStorageEntry) {
      this.toggleButtonEntry = this.localStorageService.getLocalStorageEntry(
        configuration.configuration.localStorageEntry,
        Scope.GLOBAL,
        DeletionMode.NEVER
      );
    }
  }

  constructor(protected localStorageService: LocalStorageService) {}

  ngAfterViewInit() {
    if (!this.listCellMode) {
      if (
        this.toggleButtonEntry &&
        this.toggleButtonEntry.exists() &&
        this.toggleButtonEntry.value != null
      ) {
        this.value = {
          state: this.toggleButtonEntry.value === "true",
        };
      } else {
        this.value = {
          state: false,
        };
      }

      this.toggleChange.next(this.value.state);

      this.togglerLabelChannel
        .pipe(takeUntil(this.unsubscribe))
        .subscribe((togglerLabel) => (this.togglerLabel = togglerLabel));

      this.togglerTooltipChannel
        .pipe(takeUntil(this.unsubscribe))
        .subscribe((togglerTooltip) => (this.togglerTooltip = togglerTooltip));

      this.hideButton
        .pipe(takeUntil(this.unsubscribe))
        .subscribe((hide) => (this.hide = hide));
    }
  }

  selectionChange(event) {
    if (this.toggleButtonEntry) {
      this.toggleButtonEntry.value = event.checked;
    }

    if (this.listCellMode) {
      //  this.cellComponent.update(event);
      this.toggleChange.next({
        event: event,
        row: deepCopy(this.row),
      });
    } else {
      this.toggleChange.next(event.checked);
    }
  }

  onClick(event) {
    if (this.stopPropagation) {
      event.stopPropagation();
    }
  }

  ngOnDestroy(): void {
    this.unsubscribe.destroy();
  }
}
<div
  class="nm-toggle-button"
  [style.text-align]="alignment"
  *ngIf="
    !hide && (!listCellMode || row.hasOwnProperty(cellComponent.column.field))
  "
>
  <mat-slide-toggle
    [pTooltip]="
      (listCellMode ? (value ? value.name : '') : togglerTooltip) | translate
    "
    [(ngModel)]="value && value.state"
    (click)="onClick($event)"
    [disabled]="
      listCellMode
        ? (row[disableCondition] == '' && !row[disableCondition]) || !value
        : false
    "
    (change)="selectionChange($event)"
    [class]="toggleClass"
    >{{ (togglerLabel ? togglerLabel : "") | translate }}
  </mat-slide-toggle>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""