openaire-library/searchPages/searchUtils/searchResult.component.ts

96 lines
2.8 KiB
TypeScript

import {Component, Input, OnInit} from '@angular/core';
import {SearchResult} from '../../utils/entities/searchResult';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {RouterHelper} from '../../utils/routerHelper.class';
import {EnvProperties} from '../../utils/properties/env-properties';
import {Keyword} from "./highlight/highlight.component";
@Component({
selector: 'search-result',
templateUrl: 'searchResult.component.html'
})
export class SearchResultComponent implements OnInit {
@Input() keywords: Keyword[];
@Input() results: SearchResult[];
@Input() status: number;
@Input() type: string;
@Input() showLoading: boolean = false;
@Input() showSubjects: boolean = false;
@Input() showOrganizations: boolean = true;
@Input() custom_class: string = "search-results";
@Input() properties: EnvProperties;
public urlParam: string;
public errorCodes: ErrorCodes = new ErrorCodes();
public routerHelper: RouterHelper = new RouterHelper();
public errorMessage: string = "No results found";
constructor() {
}
ngOnInit() {
if (this.type == "project") {
this.urlParam = "projectId";
} else if (this.type == "organization") {
this.urlParam = "organizationId";
} else if (this.type == "dataprovider") {
this.urlParam = "datasourceId";
}
}
/**
* Returns query param name base on result's entity type
*
* @param type
*/
public queryParamName(type: string): string {
if (type === "publication") {
return "articleId";
} else if (type === "dataset") {
return "datasetId";
} else if (type === "software") {
return "softwareId";
} else if (type === "other") {
return "orpId";
}
}
public getTypeName(type: string): string {
if (type === "dataset") {
return "research data";
} else if (type === "other") {
return "other research outcome";
} else if (type === "dataprovider") {
return "content provider";
} else {
return type;
}
}
public removeUnknown(array: string[], type: string = null): string[] {
if (type) {
return this.removeDuplicates(array, type).filter(value => value.toLowerCase() !== 'unknown');
} else {
return array.filter(value => value.toLowerCase() !== 'unknown');
}
}
public removeDuplicates(array: string[], type: string): string[] {
type = this.getTypeName(type);
return array.filter(value => value.toLowerCase() !== type);
}
public quote(params: string): string {
return '"' + params + '"';
}
public accessClass(accessMode: string): string {
if(accessMode.toLowerCase().indexOf('open') !== -1) {
return 'open';
} else if(accessMode.toLowerCase() === 'not available') {
return 'unknown';
} else {
return 'closed';
}
}
}