2020-02-07 14:05:07 +01:00
|
|
|
import {Component, Input, OnInit} from '@angular/core';
|
|
|
|
import {SearchResult} from '../../utils/entities/searchResult';
|
2018-02-15 11:36:12 +01:00
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
2020-02-07 14:05:07 +01:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
import {Keyword} from "./highlight/highlight.component";
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
@Component({
|
2020-02-07 14:05:07 +01:00
|
|
|
selector: 'search-result',
|
|
|
|
templateUrl: 'searchResult.component.html'
|
2017-12-19 13:53:46 +01:00
|
|
|
})
|
2020-02-07 14:05:07 +01:00
|
|
|
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";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-02-07 14:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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';
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-02-07 14:05:07 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|