connect-admin/src/app/pages/content-providers/criteria-utils.ts

40 lines
1.6 KiB
TypeScript
Raw Normal View History

import {Option} from "../../openaireLibrary/sharedComponents/input/input.component";
import {Criteria} from "../../openaireLibrary/utils/entities/contentProvider";
export class CriteriaUtils {
public readonly fields: Option[] = [
{value: 'author', label: 'Author\'s name'},
{value: 'title', label: 'Title'},
{value: 'orcid', label: 'Author\'s ORCID'},
{value: 'contributor', label: 'Contributor'},
{value: 'description', label: 'Description'},
{value: 'subject', label: 'Subject'},
{value: 'fos', label: 'Field of Science'},
{value: 'sdg', label: 'SDG'},
{value: 'publisher', label: 'Publisher'},
{value: 'publicationyear', label: 'Publication Year'}
]
public readonly verbs: Option[] = [
{value: 'contains', label: 'contains'},
{value: 'equals', label: 'equals'},
{value: 'not_contains', label: 'not contains'},
{value: 'not_equals', label: 'not equals'},
{value: 'starts_with', label: 'starts with'}
]
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>");
}
}