openaire-library/utils/result-preview/result-preview.component.ts

75 lines
2.3 KiB
TypeScript

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";
@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;
@Input() promoteWebsiteURL: boolean = false;
public routerHelper: RouterHelper = new RouterHelper();
public urlParam: string;
ngOnInit(): void {
if (this.result.resultType === "publication") {
this.urlParam = "articleId";
} else if (this.result.resultType === "dataset") {
this.urlParam = "datasetId";
} else if (this.result.resultType === "software") {
this.urlParam = "softwareId";
} else if (this.result.resultType === "other") {
this.urlParam = "orpId";
} else if (this.result.resultType == "project") {
this.urlParam = "projectId";
} else if (this.result.resultType == "organization") {
this.urlParam = "organizationId";
} else if (this.result.resultType == "dataprovider") {
this.urlParam = "datasourceId";
}
}
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 onTitleClick() {
if(this.modal) {
this.modal.cancel();
}
}
}