2020-03-12 14:49:10 +01:00
|
|
|
import {Component, Input, OnInit} from "@angular/core";
|
|
|
|
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";
|
2020-03-12 14:49:10 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'result-preview',
|
|
|
|
templateUrl: 'result-preview.component.html'
|
|
|
|
})
|
|
|
|
export class ResultPreviewComponent implements OnInit{
|
|
|
|
@Input() result: ResultPreview;
|
|
|
|
@Input() properties: EnvProperties;
|
|
|
|
@Input() showSubjects: boolean = true;
|
|
|
|
@Input() showOrganizations: boolean = true;
|
|
|
|
@Input() modal: AlertModal = null;
|
2020-03-13 16:06:22 +01:00
|
|
|
@Input() promoteWebsiteURL: 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;
|
2020-05-21 16:18:52 +02:00
|
|
|
public beforeTitle: string[] = [];
|
2020-03-12 14:49:10 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
if (this.result.resultType === "publication") {
|
|
|
|
this.urlParam = "articleId";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToPublication.split('?')[0];
|
2020-03-12 14:49:10 +01:00
|
|
|
} else if (this.result.resultType === "dataset") {
|
|
|
|
this.urlParam = "datasetId";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToDataset.split('?')[0];
|
2020-03-12 14:49:10 +01:00
|
|
|
} else if (this.result.resultType === "software") {
|
|
|
|
this.urlParam = "softwareId";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToSoftwareLanding.split('?')[0];
|
2020-03-12 14:49:10 +01:00
|
|
|
} else if (this.result.resultType === "other") {
|
|
|
|
this.urlParam = "orpId";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToOrp.split('?')[0];
|
2020-03-12 14:49:10 +01:00
|
|
|
} else if (this.result.resultType == "project") {
|
|
|
|
this.urlParam = "projectId";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToProject.split('?')[0];
|
2020-03-12 14:49:10 +01:00
|
|
|
} else if (this.result.resultType == "organization") {
|
|
|
|
this.urlParam = "organizationId";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToOrganization.split('?')[0];
|
2020-03-12 14:49:10 +01:00
|
|
|
} else if (this.result.resultType == "dataprovider") {
|
|
|
|
this.urlParam = "datasourceId";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToDataProvider.split('?')[0];
|
2020-05-22 16:51:28 +02:00
|
|
|
} else {
|
|
|
|
this.urlParam = "id";
|
2020-06-29 15:15:52 +02:00
|
|
|
this.url = properties.searchLinkToResult.split('?')[0];
|
2020-03-12 14:49:10 +01:00
|
|
|
}
|
2020-05-21 16:18:52 +02:00
|
|
|
this.initBeforeTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
public initBeforeTitle() {
|
|
|
|
if(this.result.resultType) {
|
|
|
|
this.beforeTitle.push(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());
|
|
|
|
}
|
2020-05-22 16:51:28 +02:00
|
|
|
if(this.result.provenanceAction) {
|
|
|
|
this.beforeTitle.push(this.result.provenanceAction);
|
|
|
|
}
|
2020-03-12 14:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
public onClick() {
|
2020-03-12 14:49:10 +01:00
|
|
|
if(this.modal) {
|
|
|
|
this.modal.cancel();
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 16:06:22 +01:00
|
|
|
}
|