openaire-library/landingPages/landing-utils/fundedBy.component.ts

131 lines
6.1 KiB
TypeScript

import {Component, Input, ElementRef} from '@angular/core';
@Component({
selector: 'fundedBy',
template: `
<dl class="uk-description-list-line">
<dt class="title">Funded By</dt>
<dd class="line"
*ngFor="let item of fundedByProjects let i=index">
<div *ngIf="i<5 || showAll">
<span uk-tooltip="pos:right; delay:10"
title="{{buildFundingTooltip(item)}}">
<a *ngIf="!item['inline'] && item.id"
[queryParams]="{projectId: item.id}" routerLinkActive="router-link-active" routerLink="/search/project">
<span *ngIf="item['funderShortname'] || item['funderName']">{{item['funderShortname']?item['funderShortname']:item['funderName']}}</span>
<span *ngIf="!item['funderShortname'] && !item['funderName']">[no funder available]</span>
<span *ngIf="item['acronym'] || item['title']">| {{ item['acronym']?item['acronym']:item['title']}}</span>
</a>
<a *ngIf="item['inline'] && item.id"
[queryParams]="{projectId: item.id}" routerLinkActive="router-link-active" routerLink="/search/project">
<mark>
<span *ngIf="item['funderShortname'] || item['funderName']">{{item['funderShortname']?item['funderShortname']:item['funderName']}}</span>
<span *ngIf="!item['funderShortname'] && !item['funderName']">[no funder available]</span>
<span *ngIf="item['acronym'] || item['title']">| {{ item['acronym']?item['acronym']:item['title']}}</span>
</mark>
</a>
<span class="clickable" *ngIf="!item['inline'] && !item.id">
<span *ngIf="item['funderShortname'] || item['funderName']">{{item['funderShortname']?item['funderShortname']:item['funderName']}}</span>
<span *ngIf="!item['funderShortname'] && !item['funderName']">[no funder available]</span>
<span *ngIf="item['acronym'] || item['title']">| {{ item['acronym']?item['acronym']:item['title']}}</span>
</span>
<span class="clickable" *ngIf="item['inline'] && !item.id">
<mark>
<span *ngIf="item['funderShortname'] || item['funderName']">{{item['funderShortname']?item['funderShortname']:item['funderName']}}</span>
<span *ngIf="!item['funderShortname'] && !item['funderName']">[no funder available]</span>
<span *ngIf="item['acronym'] || item['title']">| {{ item['acronym']?item['acronym']:item['title']}}</span>
</mark>
</span>
<span class="uk-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg>
</span>
</span>
</div>
</dd>
<dd *ngIf="showAll" class="uk-text-right">
<a (click)="showAll = !showAll; scroll()">
View less
</a>
</dd>
<dd *ngIf="!showAll && fundedByProjects && fundedByProjects.length > 5">...</dd>
<dd *ngIf="!showAll && fundedByProjects && fundedByProjects.length > 5" class="uk-text-right">
<a (click)="showAll = !showAll;">
View more
</a>
</dd>
</dl>
`
})
export class FundedByComponent {
@Input() fundedByProjects: { "id": string, "acronym": string, "title": string,
"funderShortname": string, "funderName": string,
"funding": string, "code": string, "provenanceAction": string,
"inline": boolean }[];
public showAll: boolean = false;
constructor (private element: ElementRef) {}
ngOnInit() {}
public buildFundingTooltip(item: { "id": string, "acronym": string, "title": string,
"funderShortname": string, "funderName": string,
"funding": string, "code": string, "provenanceAction": string, inline: boolean}) {
let tooltipContent: string = "<div class='tooltip-custom-font-size uk-light uk-padding-small'>";
if(item.title) {
tooltipContent += "<h5>"+item.title+"</h5>";
}
if(item.code || item.funderName || item.funderShortname || item.funding) {
tooltipContent += "<p>";
}
if(item.code) {
tooltipContent += "<div>Project Code: "+item.code+"</div>";
}
if(item.funderName || item.funderShortname) {
tooltipContent += "<div>Funder: ";
if(item.funderName && item.funderShortname) {
tooltipContent += item.funderName + " ("+ item.funderShortname +")";
} else if(item.funderName) {
tooltipContent += item.funderName;
} else {
tooltipContent += item.funderShortname;
}
tooltipContent += "</div>";
}
if(item.funding) {
tooltipContent += "<div>Funding: "+ item.funding + "</div>";
}
if(item.code || item.funderName || item.funderShortname || item.funding) {
tooltipContent += "</p>";
}
if(item.provenanceAction == 'Repository') {
tooltipContent += "Provided by Repository";
} else if(item.provenanceAction == 'OpenAIRE') {
tooltipContent += "Inferred by OpenAIRE";
} else if(item.provenanceAction == 'USer') {
tooltipContent += "Claimed by User";
}
tooltipContent+="</div>"
return tooltipContent;
}
public scroll() {
console.info("scroll into view");
if (typeof document !== 'undefined') {
this.element.nativeElement.scrollIntoView();
}
}
}