2021-02-26 15:30:10 +01:00
|
|
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
|
2020-03-12 14:49:10 +01:00
|
|
|
import {ResultPreview} from "./result-preview";
|
|
|
|
import {EnvProperties} from "../properties/env-properties";
|
|
|
|
import {RouterHelper} from "../routerHelper.class";
|
|
|
|
import {AlertModal} from "../modal/alert";
|
2020-06-29 15:15:52 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2021-01-13 19:30:25 +01:00
|
|
|
import {Session} from "../../login/utils/helper.class";
|
2022-06-03 12:01:55 +02:00
|
|
|
import {Identifier, StringUtils} from "../string-utils.class";
|
2022-05-04 12:57:13 +02:00
|
|
|
import {OpenaireEntities} from "../properties/searchFields";
|
2022-09-06 15:28:51 +02:00
|
|
|
import {HelperFunctions} from "../HelperFunctions.class";
|
2020-03-12 14:49:10 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'result-preview',
|
2022-08-02 11:43:39 +02:00
|
|
|
templateUrl: 'result-preview.component.html',
|
|
|
|
styleUrls: ['result-preview.component.less']
|
2020-03-12 14:49:10 +01:00
|
|
|
})
|
2021-02-26 15:30:10 +01:00
|
|
|
export class ResultPreviewComponent implements OnInit, OnChanges {
|
2020-03-12 14:49:10 +01:00
|
|
|
@Input() result: ResultPreview;
|
|
|
|
@Input() properties: EnvProperties;
|
2022-05-04 12:57:13 +02:00
|
|
|
public openaireEntities = OpenaireEntities;
|
2020-03-12 14:49:10 +01:00
|
|
|
@Input() showSubjects: boolean = true;
|
|
|
|
@Input() showOrganizations: boolean = true;
|
|
|
|
@Input() modal: AlertModal = null;
|
2020-03-13 16:06:22 +01:00
|
|
|
@Input() promoteWebsiteURL: boolean = false;
|
2021-02-26 15:30:10 +01:00
|
|
|
@Input() hasLink: boolean = true;
|
2022-03-15 12:13:28 +01:00
|
|
|
@Input() isCard: boolean = false;
|
2020-03-12 14:49:10 +01:00
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
public urlParam: string;
|
2020-06-29 15:15:52 +02:00
|
|
|
public url: string;
|
2021-03-22 17:16:08 +01:00
|
|
|
@Input() externalUrl: string;
|
2020-07-22 15:39:35 +02:00
|
|
|
public type: string;
|
2020-05-21 16:18:52 +02:00
|
|
|
public beforeTitle: string[] = [];
|
2020-07-13 16:42:34 +02:00
|
|
|
public dataProviderUrl = properties.searchLinkToDataProvider.split('?')[0];
|
2021-02-10 10:05:37 +01:00
|
|
|
@Input() showOrcid: boolean = true;
|
2021-04-02 11:17:00 +02:00
|
|
|
@Input() showEnermaps: boolean = false;
|
2022-08-03 17:21:14 +02:00
|
|
|
@Input() deposit: boolean = false;
|
2022-09-06 15:28:51 +02:00
|
|
|
@Input() provenanceActionVocabulary = null;
|
|
|
|
@Input() relationsVocabulary = null;
|
2021-01-13 19:30:25 +01:00
|
|
|
|
2020-03-12 14:49:10 +01:00
|
|
|
ngOnInit(): void {
|
2021-02-26 15:30:10 +01:00
|
|
|
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") {
|
2021-03-08 16:32:33 +01:00
|
|
|
if(this.result.id) {
|
|
|
|
this.urlParam = "projectId";
|
|
|
|
}else if(this.result.code && this.result.funderShortname){
|
|
|
|
this.result.id = this.result.code;
|
|
|
|
this.urlParam = "grantId";
|
|
|
|
}
|
2021-02-26 15:30:10 +01:00
|
|
|
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") {
|
2022-05-20 14:20:50 +02:00
|
|
|
if(this.result.compatibilityUNKNOWN && properties.adminToolsPortalType == "eosc") {
|
|
|
|
this.urlParam = "serviceId";
|
|
|
|
this.url = properties.searchLinkToService.split('?')[0];
|
|
|
|
} else {
|
|
|
|
this.urlParam = "datasourceId";
|
|
|
|
this.url = properties.searchLinkToDataProvider.split('?')[0];
|
|
|
|
}
|
2022-05-13 14:57:31 +02:00
|
|
|
} else if (this.result.resultType == "service") {
|
|
|
|
this.urlParam = "serviceId";
|
|
|
|
this.url = properties.searchLinkToService.split('?')[0];
|
2021-02-26 15:30:10 +01:00
|
|
|
} else {
|
|
|
|
this.urlParam = "id";
|
|
|
|
this.url = properties.searchLinkToResult.split('?')[0];
|
|
|
|
}
|
|
|
|
this.checkPID();
|
2021-02-11 11:20:10 +01:00
|
|
|
}
|
2020-05-21 16:18:52 +02:00
|
|
|
this.initBeforeTitle();
|
2020-07-14 11:57:11 +02:00
|
|
|
if(this.result.languages) {
|
|
|
|
this.result.languages = this.removeUnknown(this.result.languages);
|
|
|
|
}
|
|
|
|
if(this.result.countries) {
|
|
|
|
this.result.countries = this.removeUnknown(this.result.countries);
|
|
|
|
}
|
2020-05-21 16:18:52 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 15:30:10 +01:00
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
|
|
if(changes.result && this.hasLink) {
|
|
|
|
this.checkPID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkPID() {
|
|
|
|
// if result has a pid use it as parameter instead of openaireId
|
2021-03-10 11:41:38 +01:00
|
|
|
let pid:Identifier =this.getPID();
|
2021-02-26 15:30:10 +01:00
|
|
|
if(pid){
|
|
|
|
this.urlParam = "pid";
|
2021-04-09 17:39:42 +02:00
|
|
|
this.result.id = pid.id;
|
2021-02-26 15:30:10 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2021-03-10 11:41:38 +01:00
|
|
|
getPID() {
|
2022-05-30 09:39:10 +02:00
|
|
|
return Identifier.getPIDFromIdentifiers(this.result.identifiers);
|
2021-03-10 11:41:38 +01:00
|
|
|
}
|
2022-04-13 12:50:55 +02:00
|
|
|
|
2020-05-21 16:18:52 +02:00
|
|
|
public initBeforeTitle() {
|
2020-07-17 11:29:57 +02:00
|
|
|
if(this.result.resultType && this.result.resultType !== 'dataprovider') {
|
2020-07-22 15:39:35 +02:00
|
|
|
this.type = this.getTypeName(this.result.resultType);
|
2020-05-21 16:18:52 +02:00
|
|
|
}
|
|
|
|
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());
|
|
|
|
}
|
2022-09-06 15:28:51 +02:00
|
|
|
if(this.result.provenanceAction) {
|
2022-09-08 23:35:11 +02:00
|
|
|
let value = HelperFunctions.getVocabularyLabel(this.result.provenanceAction, this.provenanceActionVocabulary, false);
|
|
|
|
if(value) {
|
|
|
|
this.beforeTitle.push(value);
|
|
|
|
}
|
2022-09-06 15:28:51 +02:00
|
|
|
}
|
2022-01-07 11:16:23 +01:00
|
|
|
if(this.result.relationName) {
|
2022-09-06 15:28:51 +02:00
|
|
|
this.beforeTitle.push(HelperFunctions.getVocabularyLabel(this.result.relationName, this.relationsVocabulary));
|
2022-01-07 11:16:23 +01:00
|
|
|
}
|
|
|
|
// if(this.result.percentage) {
|
|
|
|
// this.beforeTitle.push((this.result.relation ? this.result.relation+": " : "") + this.result.percentage.toString() + "%");
|
|
|
|
// }
|
2020-03-12 14:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public getTypeName(type: string): string {
|
2022-06-03 12:01:55 +02:00
|
|
|
return StringUtils.getEntityName(type, false);
|
2020-03-12 14:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-03-15 12:13:28 +01:00
|
|
|
return 'success';
|
2020-03-12 14:49:10 +01:00
|
|
|
} else if(accessMode.toLowerCase() === 'not available') {
|
2022-03-15 12:13:28 +01:00
|
|
|
return 'disabled'; // unknown
|
2020-03-12 14:49:10 +01:00
|
|
|
} else {
|
2022-03-15 12:13:28 +01:00
|
|
|
return 'disabled'; // closed
|
2020-03-12 14:49:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
public onClick() {
|
2020-03-12 14:49:10 +01:00
|
|
|
if(this.modal) {
|
|
|
|
this.modal.cancel();
|
|
|
|
}
|
|
|
|
}
|
2021-03-08 16:32:33 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
2022-05-19 18:08:04 +02:00
|
|
|
|
|
|
|
public get isResultType() {
|
|
|
|
return this.result.resultType == "publication" || this.result.resultType == "dataset" ||
|
|
|
|
this.result.resultType == "software" || this.result.resultType == "other" || this.result.resultType == "result";
|
|
|
|
}
|
2020-03-13 16:06:22 +01:00
|
|
|
}
|