@WidgetComponent

nm-conditional-link

File

src/app/shared/widgets/imarket/list-cell-conditional-link/conditional-link-widget.component.ts

Implements

CellWidget OnDestroy OnInit OnChanges

Metadata

selector nm-conditional-link
styleUrls conditional-link-widget.component.scss
templateUrl ./conditional-link-widget.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(translateService: TranslateService, linkService: ConditionalLinkUtilService, _responseService: IMarketResponseService)
Parameters :
Name Type Optional
translateService TranslateService no
linkService ConditionalLinkUtilService no
_responseService IMarketResponseService no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig<ConditionalLinkConfiguration> no
Returns : void
getCssClasses
getCssClasses(link: any)
Parameters :
Name Type Optional
link any no
Returns : any
ngOnChanges
ngOnChanges()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onClick
onClick(link: , event: )
Parameters :
Name Optional
link no
event no
Returns : any
Public overrideLinkClick
overrideLinkClick(link: )
Parameters :
Name Optional
link no
Returns : void

Properties

Public baseRedirectionPage
baseRedirectionPage: string
Type : string
Public click
click:
Default value : new Subject<any>()
Decorators : WidgetOutput

Emits the selected link/row

Public configuration
configuration: WidgetConfig<ConditionalLinkConfiguration>
Type : WidgetConfig<ConditionalLinkConfiguration>
Decorators : WidgetConfiguration
Public customCssClasses
customCssClasses: string[]
Type : string[]
Public inputLink
inputLink:
Default value : new Subject<string>()
Decorators : WidgetInput

Sets the links values

Public links
links: any
Type : any
Public linkService
linkService: ConditionalLinkUtilService
Type : ConditionalLinkUtilService
Public row
row: any
Type : any
Public selectedIcon
selectedIcon:
Default value : new Subject<any>()
Decorators : WidgetOutput

Emits the selected icon

Public toggleLinkState
toggleLinkState:
Default value : new Subject<any>()
Decorators : WidgetInput

Sets the disabled property for each link value

Public translateService
translateService: TranslateService
Type : TranslateService
Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
Public value
value: any
Type : any
import { Component, OnDestroy, OnChanges, OnInit } from "@angular/core";
import { Subject } from "rxjs";
import {
  WidgetComponent,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetOutput,
  WidgetInput,
} from "../../widget.metadata";
import { WidgetConfig } from "../../widget.configuration";
import { CellWidget } from "../../../components/list-cell";
import { takeUntil } from "rxjs/operators";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import { TranslateService } from "@ngx-translate/core";
import { ConditionalLinkUtilService } from "./conditional-link-widget.component.service";
import { UtilService } from "../../../components/util/util.service";
import { IMarketResponseService } from "../../../components/imarket/services/iMarketresponse.service";

export interface LinkConfiguration {
  /*
   * Link value for each cell value
   */
  value: string;
  /*
   * Tooltip for each cell value
   */
  tooltip: string;
  /*
   * Override link click for each cell value
   */
  overrideClick: boolean;
  /*
   * Defines whether link is disabled or not
   */
  disabled: boolean;
}
export interface ConditionalLinkConfiguration {
  /**
   * Defines the Links provided for each cell value
   */
  links: LinkConfiguration[];
  /**
   * Defines base redirection for navigation
   */
  baseRedirectionPage: string;
  /**
   * Defines list of custom css classes
   */
  customCssClasses: string[];
}

@WidgetComponent("nm-conditional-link")
@Component({
  selector: "nm-conditional-link",
  templateUrl: "./conditional-link-widget.component.html",
  styleUrls: ["./conditional-link-widget.component.scss"],
})
export class ConditionalLinkWidgetComponent
  implements CellWidget, OnDestroy, OnInit, OnChanges {
  public row: any;
  public value: any;
  public links: any;

  public baseRedirectionPage: string;
  public customCssClasses: string[];

  private unsubscribe = NgUnsubscribe.create();

  /**
   * Sets the links values
   */
  @WidgetInput()
  public inputLink = new Subject<string>();

  /**
   * Sets the disabled property for each link value
   */
  @WidgetInput()
  public toggleLinkState = new Subject<any>();

  /**
   * Emits the selected link/row
   */
  @WidgetOutput()
  public click = new Subject<any>();

  /**
   * Emits the selected icon
   */
  @WidgetOutput() 
  public selectedIcon = new Subject<any>();

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

  constructor(
    public translateService: TranslateService,
    public linkService: ConditionalLinkUtilService,
    private _responseService: IMarketResponseService
  ) {}

  @WidgetConfigure()
  protected configureWidget(
    configuration: WidgetConfig<ConditionalLinkConfiguration>
  ) {
    this.links = this.configuration.configuration.links;
    this.baseRedirectionPage = this.configuration.configuration.baseRedirectionPage;
    this.customCssClasses = configuration.configuration.customCssClasses;

    this.inputLink
      .asObservable()
      .pipe(takeUntil(this.unsubscribe))
      .subscribe((inputLink) => {
        this.links = inputLink;
      });

    this.toggleLinkState
      .asObservable()
      .pipe(takeUntil(this.unsubscribe))
      .subscribe((event) => {
        this.links.forEach((link) => {
          link.disabled = !link.disabled;
        });
      });
  }

  onClick(link, event) {
    const overrideClick = this.linkService.onLinkClick(
      link,
      this.baseRedirectionPage,
      event
    );

    if (overrideClick) {
      this.overrideLinkClick(link);
      return false;
    }

    return overrideClick;
  }

  public overrideLinkClick(link) {
    if (!this.row && !link.disabled) {
      this.click.next(link);
    } else if (!link.disabled) {
      this.click.next({
        identifier: link.value,
        row: this.row,
      });
    }
  }

  getCssClasses(link: any) {
    let cssClasses = link.disabled ? ["--disabled"] : [];

    if (this.customCssClasses) {
      cssClasses = cssClasses.concat(this.customCssClasses);
    }
    return cssClasses.toString().replace(/,/g, " ");
  }

  ngOnInit() {
    if (this.row) {
      this.links = this.value;
    }
  }

  ngOnChanges() {
    if (this.row) {
      this.links = this.value;
    }
  }

  ngOnDestroy() {
    this.unsubscribe.destroy();
  }
}
<div *ngIf="links">
  <div
    class="nm-conditional-link__item--display"
    *ngFor="let link of links; let i = index"
    matTooltip="{{ link.tooltip | translate }}"
    [class.--fullWidth]="link.copyToClipboardValue || link.icons?.length > 0"
  >
    <div>
      <a
        class="nm-conditional-link__item--display"
        href="{{ linkService.getLink(link, baseRedirectionPage) }}"
        (click)="onClick(link, $event)"
        class="{{ getCssClasses(link) }}"
      >
        <nm-ellipsis
          [disableTooltip]="link.tooltip"
          [content]="link.value | translate"
        ></nm-ellipsis>
      </a>
    </div>
    <div
      class="nm-conditional-link__item--separator-display"
      *ngIf="i != links.length - 1"
    >
      ,
    </div>
    <div class="nm-conditional-link__iconList" >
      <nm-icon 
        [data]="link" 
        (selectedIcon)="selectedIcon.next({event: $event, payload: row})">
      </nm-icon>
    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""