src/app/shared/widgets/imarket/list-cell-conditional-link/conditional-link-widget.component.service.ts
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
constructor(router: Router)
|
||||||
Parameters :
|
Public getBaseUrl | ||||||
getBaseUrl(baseRedirectionPage: string)
|
||||||
Parameters :
Returns :
any
|
Public getFullLink |
getFullLink(baseRedirectionPage: string, link: string)
|
Returns :
string
|
Public getLink |
getLink(link: any, baseRedirectionPage: string)
|
Returns :
string
|
Public onLinkClick | ||||||||
onLinkClick(link: , baseRedirectionPage: , event: )
|
||||||||
Parameters :
Returns :
boolean
|
Public openLinkInNewTab | ||||||
openLinkInNewTab(link: string)
|
||||||
Parameters :
Returns :
boolean
|
Public 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;
}
}