2021-05-19 13:40:29 +02:00
|
|
|
import {Option} from "../../openaireLibrary/sharedComponents/input/input.component";
|
2023-03-10 16:15:26 +01:00
|
|
|
import {Criteria} from "../../openaireLibrary/utils/entities/contentProvider";
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
export class CriteriaUtils {
|
2023-03-10 16:15:26 +01:00
|
|
|
public readonly fields: Option[] = [
|
2021-05-19 13:40:29 +02:00
|
|
|
{value: 'author', label: 'Author\'s name'},
|
2023-03-08 23:26:06 +01:00
|
|
|
{value: 'title', label: 'Title'},
|
2022-11-28 12:06:40 +01:00
|
|
|
{value: 'orcid', label: 'Author\'s ORCID'},
|
2021-05-19 13:40:29 +02:00
|
|
|
{value: 'contributor', label: 'Contributor'},
|
2023-03-08 23:26:06 +01:00
|
|
|
{value: 'description', label: 'Description'},
|
|
|
|
{value: 'subject', label: 'Subject'},
|
2023-03-10 16:15:26 +01:00
|
|
|
{value: 'fos', label: 'Field of Science'},
|
2023-11-08 08:40:25 +01:00
|
|
|
{value: 'sdg', label: 'SDG'},
|
|
|
|
{value: 'publisher', label: 'Publisher'},
|
|
|
|
{value: 'publicationyear', label: 'Publication Year'}
|
2021-05-19 13:40:29 +02:00
|
|
|
]
|
|
|
|
|
2023-03-10 16:15:26 +01:00
|
|
|
public readonly verbs: Option[] = [
|
2021-05-19 13:40:29 +02:00
|
|
|
{value: 'contains', label: 'contains'},
|
|
|
|
{value: 'equals', label: 'equals'},
|
|
|
|
{value: 'not_contains', label: 'not contains'},
|
2023-03-10 16:15:26 +01:00
|
|
|
{value: 'not_equals', label: 'not equals'},
|
|
|
|
{value: 'starts_with', label: 'starts with'}
|
2021-05-19 13:40:29 +02:00
|
|
|
]
|
2023-03-10 16:15:26 +01:00
|
|
|
|
|
|
|
public getFiltersAsText(criteria: Criteria[]): string {
|
|
|
|
let text = criteria.slice(0, 3).map((criterion, index) => (index + 1) + ". " + criterion.constraint.map(constraint => {
|
|
|
|
let field = this.fields.find(field => field.value === constraint.field)?.label;
|
|
|
|
let matchCase = false;
|
|
|
|
if (!constraint.verb.includes('_caseinsensitive')) {
|
|
|
|
matchCase = true;
|
|
|
|
}
|
|
|
|
let verb = this.verbs.find(verb => verb.value === constraint.verb.replace("_caseinsensitive", "")).label;
|
|
|
|
let value = '"' + constraint.value + '"' + (matchCase ? " (Match case)" : "");
|
|
|
|
return field + " " + verb + " " + value;
|
|
|
|
}).join(" <b>and</b> "));
|
|
|
|
return text.join("<br>");
|
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|