161 lines
5.3 KiB
TypeScript
161 lines
5.3 KiB
TypeScript
import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
|
|
import {ResultPreview} from "./result-preview";
|
|
import {EnvProperties} from "../properties/env-properties";
|
|
import {RouterHelper} from "../routerHelper.class";
|
|
import {AlertModal} from "../modal/alert";
|
|
import {properties} from "../../../../environments/environment";
|
|
import {Session} from "../../login/utils/helper.class";
|
|
import {Identifier} from "../string-utils.class";
|
|
|
|
@Component({
|
|
selector: 'result-preview',
|
|
templateUrl: 'result-preview.component.html'
|
|
})
|
|
export class ResultPreviewComponent implements OnInit, OnChanges {
|
|
@Input() result: ResultPreview;
|
|
@Input() properties: EnvProperties;
|
|
@Input() showSubjects: boolean = true;
|
|
@Input() showOrganizations: boolean = true;
|
|
@Input() modal: AlertModal = null;
|
|
@Input() promoteWebsiteURL: boolean = false;
|
|
@Input() hasLink: boolean = true;
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
public urlParam: string;
|
|
public url: string;
|
|
@Input() externalUrl: string;
|
|
public type: string;
|
|
public beforeTitle: string[] = [];
|
|
public dataProviderUrl = properties.searchLinkToDataProvider.split('?')[0];
|
|
@Input() showOrcid: boolean = true;
|
|
@Input() showEnermaps: boolean = false;
|
|
|
|
ngOnInit(): void {
|
|
if(this.hasLink) {
|
|
if (this.result.resultType === "publication") {
|
|
this.urlParam = "articleId";
|
|
this.url = properties.searchLinkToPublication.split('?')[0];
|
|
} else if (this.result.resultType === "dataset") {
|
|
this.urlParam = "datasetId";
|
|
this.url = properties.searchLinkToDataset.split('?')[0];
|
|
} else if (this.result.resultType === "software") {
|
|
this.urlParam = "softwareId";
|
|
this.url = properties.searchLinkToSoftwareLanding.split('?')[0];
|
|
} else if (this.result.resultType === "other") {
|
|
this.urlParam = "orpId";
|
|
this.url = properties.searchLinkToOrp.split('?')[0];
|
|
} else if (this.result.resultType == "project") {
|
|
if(this.result.id) {
|
|
this.urlParam = "projectId";
|
|
}else if(this.result.code && this.result.funderShortname){
|
|
this.result.id = this.result.code;
|
|
this.urlParam = "grantId";
|
|
}
|
|
this.url = properties.searchLinkToProject.split('?')[0];
|
|
} else if (this.result.resultType == "organization") {
|
|
this.urlParam = "organizationId";
|
|
this.url = properties.searchLinkToOrganization.split('?')[0];
|
|
} else if (this.result.resultType == "dataprovider") {
|
|
this.urlParam = "datasourceId";
|
|
this.url = properties.searchLinkToDataProvider.split('?')[0];
|
|
} else {
|
|
this.urlParam = "id";
|
|
this.url = properties.searchLinkToResult.split('?')[0];
|
|
}
|
|
this.checkPID();
|
|
}
|
|
this.initBeforeTitle();
|
|
if(this.result.languages) {
|
|
this.result.languages = this.removeUnknown(this.result.languages);
|
|
}
|
|
if(this.result.countries) {
|
|
this.result.countries = this.removeUnknown(this.result.countries);
|
|
}
|
|
}
|
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
if(changes.result && this.hasLink) {
|
|
this.checkPID();
|
|
}
|
|
}
|
|
|
|
checkPID() {
|
|
// if result has a pid use it as parameter instead of openaireId
|
|
let pid:Identifier =this.getPID();
|
|
if(pid){
|
|
this.urlParam = "pid";
|
|
this.result.id = encodeURIComponent(pid.id);
|
|
|
|
}
|
|
}
|
|
getPID() {
|
|
return Identifier.getResultPIDFromIdentifiers(this.result.identifiers);
|
|
}
|
|
get isLoggedIn(): boolean {
|
|
return Session.isLoggedIn();
|
|
}
|
|
|
|
public initBeforeTitle() {
|
|
if(this.result.resultType && this.result.resultType !== 'dataprovider') {
|
|
this.type = this.getTypeName(this.result.resultType);
|
|
}
|
|
if(this.result.types) {
|
|
this.removeUnknown(this.removeDuplicates(this.result.types)).forEach(type => {
|
|
this.beforeTitle.push(type);
|
|
});
|
|
}
|
|
if(this.result.year) {
|
|
this.beforeTitle.push(this.result.year.toString());
|
|
}
|
|
if(this.result.startYear && this.result.endYear) {
|
|
this.beforeTitle.push(this.result.startYear.toString() + ' - ' + this.result.endYear.toString());
|
|
}
|
|
if(this.result.provenanceAction) {
|
|
this.beforeTitle.push(this.result.provenanceAction);
|
|
}
|
|
}
|
|
|
|
public getTypeName(type: string): string {
|
|
if (type === "dataset") {
|
|
return "research data";
|
|
} else if (type === "other") {
|
|
return "other research product";
|
|
} else if (type === "dataprovider") {
|
|
return "content provider";
|
|
} else {
|
|
return type;
|
|
}
|
|
}
|
|
|
|
public removeUnknown(array: string[]): string[] {
|
|
return array.filter(value => value.toLowerCase() !== 'unknown');
|
|
}
|
|
|
|
public removeDuplicates(array: string[]): string[] {
|
|
return array.filter(value => value.toLowerCase() !== this.result.resultType);
|
|
}
|
|
|
|
public accessClass(accessMode: string): string {
|
|
if(accessMode.toLowerCase().indexOf('open') !== -1) {
|
|
return 'open';
|
|
} else if(accessMode.toLowerCase() === 'not available') {
|
|
return 'unknown';
|
|
} else {
|
|
return 'closed';
|
|
}
|
|
}
|
|
|
|
public onClick() {
|
|
if(this.modal) {
|
|
this.modal.cancel();
|
|
}
|
|
}
|
|
createParam(){
|
|
if(this.urlParam == "grantId" ){
|
|
return this.routerHelper.createQueryParams([this.urlParam,"funder"],[this.result.id,this.result.funderShortname])
|
|
|
|
}
|
|
return this.routerHelper.createQueryParam(this.urlParam,this.result.id)
|
|
|
|
}
|
|
}
|