File

app/core/services/component-link-service/component-link.service.ts

Index

Methods

Constructor

constructor(util: UtilService)
Parameters :
Name Type Optional
util UtilService No

Methods

Public getDescription
getDescription(linkObject)
Parameters :
Name Optional
linkObject No
Returns : string
Private getExtract
getExtract(linkObject)
Parameters :
Name Optional
linkObject No
Returns : any
Public getFileSizeInBytes
getFileSizeInBytes(linkObject)
Parameters :
Name Optional
linkObject No
Returns : number
Public getTitle
getTitle(linkObject)
Parameters :
Name Optional
linkObject No
Returns : string
Public getUrl
getUrl(linkObject)
Parameters :
Name Optional
linkObject No
Returns : string
Public getUseDescription
getUseDescription(linkObject)
Parameters :
Name Optional
linkObject No
Returns : boolean
Private isInternalLink
isInternalLink(linkObject)
Parameters :
Name Optional
linkObject No
Returns : boolean
Public openInNewWindow
openInNewWindow(linkObject)
Parameters :
Name Optional
linkObject No
Returns : boolean
Public parseLink
parseLink(link: any)
Parameters :
Name Type Optional
link any No
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;
	}
}

result-matching ""

    No results matching ""