2022-05-27 11:22:04 +02:00
|
|
|
import {
|
|
|
|
ChangeDetectorRef,
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnChanges,
|
|
|
|
OnDestroy,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
2022-11-18 14:03:08 +01:00
|
|
|
SimpleChanges, ViewChild
|
2022-05-27 11:22:04 +02:00
|
|
|
} from '@angular/core';
|
2020-02-13 15:44:51 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2022-04-19 01:09:42 +02:00
|
|
|
import {AdvancedField, Filter} from './searchHelperClasses.class';
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
import {OpenaireEntities, SearchFields} from '../../utils/properties/searchFields';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {Dates} from '../../utils/string-utils.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2020-04-03 18:00:19 +02:00
|
|
|
import {SearchCustomFilter} from "./searchUtils.class";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2020-11-18 17:06:27 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2022-05-27 11:22:04 +02:00
|
|
|
import {Option} from "../../sharedComponents/input/input.component";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
2022-04-12 16:20:51 +02:00
|
|
|
selector: 'advanced-search-form',
|
|
|
|
templateUrl: 'advancedSearchForm.component.html'
|
2017-12-19 13:53:46 +01:00
|
|
|
})
|
2022-05-27 11:22:04 +02:00
|
|
|
export class AdvancedSearchFormComponent implements OnInit, OnDestroy, OnChanges {
|
2022-11-18 14:03:08 +01:00
|
|
|
@ViewChild("container") container;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Input() entityType;
|
2022-04-12 16:20:51 +02:00
|
|
|
@Input() fieldIds: string[];
|
2017-12-19 13:53:46 +01:00
|
|
|
@Input() fieldIdsMap;
|
2022-05-27 11:22:04 +02:00
|
|
|
public fieldIdsOptions: Option[] = [];
|
2022-04-12 16:20:51 +02:00
|
|
|
@Input() selectedFields: AdvancedField[];
|
2017-12-19 13:53:46 +01:00
|
|
|
@Input() isDisabled: boolean = false;
|
2018-10-01 17:02:14 +02:00
|
|
|
@Input() simpleSearchLink;
|
2020-01-31 16:12:51 +01:00
|
|
|
@Input() advancedSearchLink;
|
|
|
|
@Input() advancedSearchLinkParameters;
|
2022-04-12 16:20:51 +02:00
|
|
|
@Input() simpleView: boolean = false;
|
2020-01-31 16:12:51 +01:00
|
|
|
@Input() formPlaceholderText = "Type Keywords...";
|
2022-04-15 10:08:12 +02:00
|
|
|
@Input() dark: boolean;
|
2022-04-12 16:20:51 +02:00
|
|
|
@Output() queryChange = new EventEmitter();
|
|
|
|
@Input() resultTypes;
|
|
|
|
@Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
|
2022-12-07 15:56:16 +01:00
|
|
|
@Input() isMobile: boolean = false;
|
2022-04-18 10:29:14 +02:00
|
|
|
public disableSelect: boolean = false;
|
2019-05-22 12:50:32 +02:00
|
|
|
validDateFrom: boolean = true;
|
|
|
|
validDateTo: boolean = true;
|
2020-04-03 18:00:19 +02:00
|
|
|
@Input() customFilter: SearchCustomFilter;
|
2022-04-12 16:20:51 +02:00
|
|
|
newFieldId: string;
|
|
|
|
newFieldName: string;
|
|
|
|
fieldList: { [id: string]: any[] } = {};
|
|
|
|
public searchFields: SearchFields = new SearchFields();
|
|
|
|
properties: EnvProperties;
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
public openaireEntities = OpenaireEntities;
|
2022-05-27 11:22:04 +02:00
|
|
|
public operators: string[] = this.searchFields.ADVANCED_SEARCH_OPERATORS;
|
2022-06-01 12:27:46 +02:00
|
|
|
public isOperators: Option[] = [{label: 'is', value: true}, {label: 'is not', value: false}];
|
|
|
|
public isWithinOperators: Option[] = [{label: 'is within', value: true}, {label: 'is not within', value: false}];
|
|
|
|
public includesOperators: Option[] = [{label: 'includes', value: true}, {label: 'not includes', value: false}];
|
2020-02-13 15:44:51 +01:00
|
|
|
selectedEntity;
|
|
|
|
selectedEntitySimpleUrl;
|
|
|
|
selectedEntityAdvancedUrl;
|
2022-04-12 16:20:51 +02:00
|
|
|
@Input() entitiesSelection: boolean;
|
|
|
|
@Input() showSwitchSearchLink: boolean = true;
|
2022-12-07 15:56:16 +01:00
|
|
|
@Output() filtersClicked: EventEmitter<boolean> = new EventEmitter<boolean>();
|
2020-11-11 15:43:13 +01:00
|
|
|
sub;
|
2022-04-12 16:20:51 +02:00
|
|
|
|
2022-04-19 01:09:42 +02:00
|
|
|
constructor(private route: ActivatedRoute, private router: Router, private cdr: ChangeDetectorRef) {}
|
2022-04-12 16:20:51 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
2020-02-13 15:44:51 +01:00
|
|
|
this.selectedEntity = this.entityType;
|
2022-04-12 16:20:51 +02:00
|
|
|
|
|
|
|
this.properties = properties;
|
|
|
|
|
|
|
|
for (var i = 0; i < this.fieldIds.length; i++) {
|
|
|
|
this.fieldList[this.fieldIds[i]] = [];
|
|
|
|
}
|
|
|
|
this.newFieldId = this.fieldIds[0];
|
|
|
|
this.newFieldName = this.fieldIdsMap[this.newFieldId].name;
|
2022-05-27 11:22:04 +02:00
|
|
|
this.buildFieldIdsOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.sub instanceof Subscriber) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
|
|
if(changes.fieldIds || changes.fieldIdsMap) {
|
|
|
|
this.buildFieldIdsOptions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-01 12:27:46 +02:00
|
|
|
getNotOperators(field: AdvancedField) {
|
|
|
|
if(this.fieldIdsMap[field.id].equalityOperator.includes('exact')) {
|
|
|
|
return this.isOperators;
|
|
|
|
} else if(this.fieldIdsMap[field.id].equalityOperator.includes('within')) {
|
|
|
|
return this.isWithinOperators;
|
|
|
|
} else {
|
|
|
|
return this.includesOperators;
|
|
|
|
}
|
2022-05-27 11:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
buildFieldIdsOptions() {
|
|
|
|
this.fieldIdsOptions = [];
|
|
|
|
this.fieldIds.forEach(id => {
|
|
|
|
this.fieldIdsOptions.push({label: this.fieldIdsMap[id].name, value: id})
|
|
|
|
});
|
2022-04-12 16:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
simpleEntityChanged($event) {
|
2020-02-13 15:44:51 +01:00
|
|
|
this.selectedEntity = $event.entity;
|
|
|
|
this.selectedEntitySimpleUrl = $event.simpleUrl;
|
|
|
|
this.selectedEntityAdvancedUrl = $event.advancedUrl;
|
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
|
|
|
|
simpleKeywordChanged() {
|
2020-02-13 15:44:51 +01:00
|
|
|
// this.selectedFields[0].value = $event.value;
|
2022-04-12 16:20:51 +02:00
|
|
|
if (this.selectedEntity == this.entityType) {
|
2020-02-13 15:44:51 +01:00
|
|
|
this.queryChanged();
|
2022-04-12 16:20:51 +02:00
|
|
|
} else {
|
|
|
|
this.router.navigate([this.selectedEntitySimpleUrl], {queryParams: {q: this.selectedFields[0].value, op: "and"}});
|
2020-02-13 15:44:51 +01:00
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
|
|
|
|
queryChanged() {
|
|
|
|
this.validDateFrom = true;
|
|
|
|
this.validDateTo = true;
|
|
|
|
|
|
|
|
this.selectedFields.forEach(selectedField => {
|
|
|
|
if (selectedField.type == 'date') {
|
|
|
|
if (selectedField.dateValue.type.indexOf("range") != -1) {
|
|
|
|
if (!Dates.isValidDate(Dates.getDateToString(selectedField.dateValue.from))) {
|
|
|
|
//console.info("INVALID: isValidDate FROM");
|
|
|
|
this.validDateFrom = false;
|
|
|
|
}
|
|
|
|
if (!Dates.isValidDate(Dates.getDateToString(selectedField.dateValue.to))) {
|
|
|
|
//console.info("INVALID: isValidDate TO");
|
|
|
|
this.validDateTo = false;
|
2019-05-22 12:50:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (this.validDateFrom && this.validDateTo) {
|
|
|
|
this.queryChange.emit({});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
}
|
|
|
|
|
2022-04-18 10:29:14 +02:00
|
|
|
disableSelectChange(value) {
|
|
|
|
this.disableSelect = value;
|
2022-04-19 01:09:42 +02:00
|
|
|
this.cdr.detectChanges();
|
2022-04-18 10:29:14 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 16:20:51 +02:00
|
|
|
addField() {
|
|
|
|
this.newFieldId = this.fieldIds[0];
|
|
|
|
var type = this.fieldIdsMap[this.newFieldId].type;
|
|
|
|
if (type == "boolean") {
|
|
|
|
this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].param, this.fieldIdsMap[this.newFieldId].name, type, "true", "and"));
|
|
|
|
} else {
|
|
|
|
this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].param, this.fieldIdsMap[this.newFieldId].name, type, "", "and"));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-11-18 14:03:08 +01:00
|
|
|
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
this.container.nativeElement.scrollTo({top: this.container.nativeElement.scrollHeight, behavior: 'smooth'});
|
2022-04-12 16:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
removeField(index: number) {
|
|
|
|
if (this.selectedFields.length == 1) {
|
|
|
|
this.selectedFields[index] = new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].param, this.fieldIdsMap[this.newFieldId].name, this.fieldIdsMap[this.newFieldId].type, "", "and");
|
|
|
|
} else {
|
|
|
|
this.selectedFields.splice(index, 1);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
//if only one filter left, set the operator to and
|
|
|
|
if (this.selectedFields.length == 1) {
|
|
|
|
this.selectedFields[0].operatorId = "and";
|
2020-07-21 14:41:08 +02:00
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fieldOperatorChanged(index: number, operatorId: string, operatorName: string) {
|
|
|
|
this.selectedFields[index].operatorId = operatorId;
|
|
|
|
this.selectedFields[index].operatorName = operatorName;
|
|
|
|
}
|
|
|
|
|
|
|
|
validateDate(index: number, value: string) {
|
|
|
|
this.selectedFields[index].valid = Dates.isValidYear(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldIdsChanged(index: number, fieldId: string) {
|
2022-05-27 11:22:04 +02:00
|
|
|
this.selectedFields[index].name = this.fieldIdsMap[fieldId].name;
|
|
|
|
this.selectedFields[index].type = this.fieldIdsMap[fieldId].type;
|
2022-04-12 16:20:51 +02:00
|
|
|
this.selectedFields[index].value = "";
|
2022-05-27 11:22:04 +02:00
|
|
|
this.selectedFields[index].param = this.fieldIdsMap[fieldId].param;
|
|
|
|
if (this.fieldIdsMap[fieldId].type == "boolean") {
|
2022-04-12 16:20:51 +02:00
|
|
|
this.selectedFields[index].value = "true";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-04-12 16:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
valueChanged($event, index: number) {
|
|
|
|
this.selectedFields[index].value = $event.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
updatedValueLabel($event, index: number) {
|
|
|
|
this.selectedFields[index].valueLabel = $event.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
listUpdated($event, fieldId: number) {
|
|
|
|
this.fieldList[fieldId] = $event.value;
|
|
|
|
}
|
|
|
|
|
2022-05-27 11:22:04 +02:00
|
|
|
onlyAndSupported(index: number) {
|
|
|
|
return (this.selectedFields[index] && !this.selectedFields[index].includes) || (this.selectedFields[index+1] && !this.selectedFields[index+1].includes)
|
|
|
|
}
|
|
|
|
|
|
|
|
onlyIncludesSupported(index: number) {
|
|
|
|
return (this.selectedFields[index] && this.selectedFields[index].operatorId === 'or') || (this.selectedFields[index+1] && this.selectedFields[index+1].operatorId === 'or')
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|