app/core/services/component-link-service/component-link.service.ts
Methods |
|
constructor(util: UtilService)
|
||||||
Parameters :
|
Public getDescription | ||||
getDescription(linkObject)
|
||||
Parameters :
Returns :
string
|
Private getExtract | ||||
getExtract(linkObject)
|
||||
Parameters :
Returns :
any
|
Public getFileSizeInBytes | ||||
getFileSizeInBytes(linkObject)
|
||||
Parameters :
Returns :
number
|
Public getTitle | ||||
getTitle(linkObject)
|
||||
Parameters :
Returns :
string
|
Public getUrl | ||||
getUrl(linkObject)
|
||||
Parameters :
Returns :
string
|
Public getUseDescription | ||||
getUseDescription(linkObject)
|
||||
Parameters :
Returns :
boolean
|
Private isInternalLink | ||||
isInternalLink(linkObject)
|
||||
Parameters :
Returns :
boolean
|
Public openInNewWindow | ||||
openInNewWindow(linkObject)
|
||||
Parameters :
Returns :
boolean
|
Public parseLink | ||||||
parseLink(link: any)
|
||||||
Parameters :
Returns :
ComponentLink
|
import { Injectable } from '@angular/core';
import { UtilService } from '../util-service/util.service';
import { ComponentLink } from 'src/app/core/interfaces/interfaces.component';
@Injectable()
export class ComponentLinkService {
constructor(private util: UtilService) {}
public getTitle(linkObject): string {
const extract = this.getExtract(linkObject);
return this.util.extract(linkObject, 'LinkButtonTitleText') ||
this.util.extract(linkObject, 'LinkOrButtonTitle') ||
extract('LinkModelTarget', 'LinkData', 'LinkTitle') ||
extract('LinkModelTarget', 'Assetmetadata', 'Titlemm') ||
extract('LinkModelTarget', 'AlternateText') || ''; // only invoked for non-published/broken binaries
}
public getDescription(linkObject): string {
const extract = this.getExtract(linkObject);
return extract('LinkModelTarget', 'MetaDataDesc') ||
extract('LinkModelTarget', 'LinkData', 'LinkDesc') ||
extract('LinkModelTarget', 'Assetmetadata', 'Description') || '';
}
public getUseDescription(linkObject): boolean {
const extract = this.getExtract(linkObject);
return extract('LinkWithWithoutDescription') !== 'Without description';
}
public openInNewWindow(linkObject): boolean {
const extract = this.getExtract(linkObject);
return extract('WindowTarget') === 'New window';
}
public getUrl(linkObject): string {
const extract = this.getExtract(linkObject);
return extract('LinkTarget') || extract( 'LinkModelTarget', 'Url') || extract('LinkModelTarget', 'ExternalLink') || extract('ExternalLink') || extract('Url') || '';
}
public getFileSizeInBytes(linkObject): number {
const extract = this.getExtract(linkObject);
return extract('LinkModelTarget', 'FileSize');
}
/*
Depending on what schema the linked to component is using (Embedded Link Target (with or without image) or Embedded Item Link )
we will need to index the json with or without "LinkTarget".
*/
private getExtract(linkObject) {
let extract;
if (this.util.extract(linkObject, 'LinkOrButtonTitle') || this.util.extract(linkObject, 'ImageVideo')) {
extract = this.util.partiallyApplyExtract(linkObject, 'LinkTarget');
} else {
extract = this.util.partiallyApplyExtract(linkObject);
}
return extract;
}
private isInternalLink(linkObject) {
const extract = this.getExtract(linkObject);
return !!extract('LinkTarget');
}
public parseLink(link: any): ComponentLink {
const linkObject: ComponentLink = {
linkObject: link,
title: this.getTitle(link),
url: this.getUrl(link),
newWindow: this.openInNewWindow(link),
isInternal: this.isInternalLink(link),
description: this.getDescription(link),
useDescription: this.getUseDescription(link),
linkID: this.util.getComponentId(this.util.extract(link, 'LinkModelTarget')),
fileSize: this.util.formatFilesize(this.getFileSizeInBytes(link))
};
return linkObject;
}
}