File

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

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(router: Router)
Parameters :
Name Type Optional
router Router no

Methods

Public getBaseUrl
getBaseUrl(baseRedirectionPage: string)
Parameters :
Name Type Optional
baseRedirectionPage string no
Returns : any
Public getFullLink
getFullLink(baseRedirectionPage: string, link: string)
Parameters :
Name Type Optional
baseRedirectionPage string no
link string no
Returns : string
Public getLink
getLink(link: any, baseRedirectionPage: string)
Parameters :
Name Type Optional
link any no
baseRedirectionPage string no
Returns : string
Public onLinkClick
onLinkClick(link: , baseRedirectionPage: , event: )
Parameters :
Name Optional
link no
baseRedirectionPage no
event no
Returns : boolean
Public openLinkInNewTab
openLinkInNewTab(link: string)
Parameters :
Name Type Optional
link string no
Returns : boolean

Properties

Public router
router: Router
Type : Router
import { Injectable } from "@angular/core";
import { Router } from "@angular/router";

declare var contextPath: string;

@Injectable()
export class ConditionalLinkUtilService {
  constructor(public router: Router) {}

  public onLinkClick(link, baseRedirectionPage, event) {
    if (!link) {
      return false;
    }

    if (link.overrideClick) {
      return true;
    }

    if (link.link) {
      if (event.ctrlKey) {
        // We want to use the default browser logic to handle this
        return;
      }

      event.preventDefault();

      if (link.externalLink) {
        return this.openLinkInNewTab(link.link);
      }

      if (link.openInNewTab) {
        return this.openLinkInNewTab(this.getLink(link, baseRedirectionPage));
      }

      event.stopPropagation();
      this.router.navigateByUrl(link.link);
    }

    return false;
  }

  public getLink(link: any, baseRedirectionPage: string): string {
    if (link.overrideClickEvent) {
      return "";
    } else if (link.externalLink) {
      return link.link;
    } else {
      return this.getFullLink(baseRedirectionPage, link.link);
    }
  }

  public getFullLink(baseRedirectionPage: string, link: string) {
    const baseUrl = this.getBaseUrl(baseRedirectionPage);

    return baseUrl ? baseUrl + link : link;
  }

  public getBaseUrl(baseRedirectionPage: string) {
    return baseRedirectionPage
      ? window.location.href.split(baseRedirectionPage, 1)
      : window.location.origin + contextPath;
  }

  public openLinkInNewTab(link: string) {
    window.open(link);
    return false;
  }
}

results matching ""

    No results matching ""