2020-04-22 15:00:13 +02:00
|
|
|
import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
|
2020-02-13 15:44:51 +01:00
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
|
|
import {SearchCustomFilter} from "./searchUtils.class";
|
|
|
|
import {ConfigurationService} from "../../utils/configuration/configuration.service";
|
|
|
|
import {Router} from "@angular/router";
|
2020-07-13 00:19:30 +02:00
|
|
|
import {Subscription} from "rxjs";
|
2021-04-15 20:26:38 +02:00
|
|
|
import {properties} from '../../../../environments/environment';
|
2022-04-15 23:49:35 +02:00
|
|
|
import {InputComponent, Option} from "../../sharedComponents/input/input.component";
|
|
|
|
import {OpenaireEntities} from "../../utils/properties/searchFields";
|
2020-02-13 15:44:51 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'entities-selection',
|
|
|
|
template: `
|
2022-04-18 10:29:14 +02:00
|
|
|
<ng-container *ngIf="simpleView && entities.length > 0">
|
2022-04-15 23:49:35 +02:00
|
|
|
<div #input input placeholder="Type" hint="What type of content?" inputClass="advanced-search"
|
|
|
|
[options]="entities" [(value)]="selectedEntity" (valueChange)="entityChanged()" type="select"></div>
|
|
|
|
</ng-container>
|
2022-04-18 10:29:14 +02:00
|
|
|
<ng-container *ngIf="!simpleView && entities.length > 0">
|
|
|
|
<div #input input inputClass="inner small"
|
|
|
|
[options]="entities" [(value)]="selectedEntity" (valueChange)="entityChanged()" type="select"></div>
|
|
|
|
</ng-container>
|
2020-02-13 15:44:51 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class EntitiesSelectionComponent {
|
2022-04-15 23:49:35 +02:00
|
|
|
@Input() onlyresults: boolean = false;
|
2020-02-13 15:44:51 +01:00
|
|
|
@Input() customFilter: SearchCustomFilter = null;
|
2022-04-15 23:49:35 +02:00
|
|
|
@Input() selectedEntity = "result";
|
|
|
|
@Input() currentEntity = "result";
|
2020-03-03 15:32:43 +01:00
|
|
|
@Input() simpleView: boolean = true;
|
|
|
|
@Input() onChangeNavigate: boolean = true;
|
2022-04-15 23:49:35 +02:00
|
|
|
@Output() selectionChange = new EventEmitter();
|
|
|
|
@ViewChild('input') input: InputComponent;
|
2022-04-18 10:29:14 +02:00
|
|
|
@Output() disableSelectEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
2022-04-15 23:49:35 +02:00
|
|
|
public entities: Option[] = [];
|
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
private subscriptions: Subscription[] = [];
|
|
|
|
|
|
|
|
constructor(private config: ConfigurationService, private router: Router) {
|
|
|
|
}
|
2020-06-29 15:15:52 +02:00
|
|
|
|
2020-02-13 15:44:51 +01:00
|
|
|
ngOnInit() {
|
2022-04-15 23:49:35 +02:00
|
|
|
if ((this.customFilter && this.customFilter.queryFieldName == "communityId") || (this.properties.adminToolsCommunity !== "monitor")) {
|
|
|
|
//this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
|
|
|
|
this.subscriptions.push(this.config.communityInformationState.subscribe(data => {
|
|
|
|
if (data) {
|
|
|
|
let showEntity = {};
|
|
|
|
let showPage = {};
|
|
|
|
if (data['entities']) {
|
|
|
|
for (let i = 0; i < data['entities'].length; i++) {
|
|
|
|
|
|
|
|
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
}
|
|
|
|
if (data['pages']) {
|
|
|
|
for (let i = 0; i < data['pages'].length; i++) {
|
|
|
|
showPage["" + data['pages'][i]["route"] + ""] = data['pages'][i]["isEnabled"];
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
}
|
|
|
|
if(this.onlyresults) {
|
2022-04-18 10:29:14 +02:00
|
|
|
if(this.simpleView) {
|
|
|
|
this.entities.push({label: 'All ' + OpenaireEntities.RESULTS.toLowerCase(), value: 'all'});
|
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults] && showEntity["publication"]) {
|
|
|
|
this.entities.push({label: OpenaireEntities.PUBLICATIONS, value: 'publications'});
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults] && showEntity["dataset"]) {
|
|
|
|
this.entities.push({label: OpenaireEntities.DATASETS, value: 'datasets'});
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults] && showEntity["software"]) {
|
|
|
|
this.entities.push({label: OpenaireEntities.SOFTWARE, value: 'software'});
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults] && showEntity["orp"]) {
|
|
|
|
this.entities.push({label: OpenaireEntities.OTHER, value: 'other'});
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
} else {
|
2022-04-18 10:29:14 +02:00
|
|
|
if(this.simpleView) {
|
|
|
|
this.entities.push({label: 'All Content', value: 'all'});
|
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults]
|
|
|
|
&& (showEntity["publication"] || showEntity["dataset"] || showEntity["software"] || showEntity["orp"])) {
|
|
|
|
this.entities.push({label: OpenaireEntities.RESULTS, value: 'result'});
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects] && showEntity["project"]) {
|
|
|
|
this.entities.push({label: OpenaireEntities.PROJECTS, value: 'project'});
|
|
|
|
}
|
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations] && showEntity["organization"]) {
|
|
|
|
this.entities.push({label: OpenaireEntities.ORGANIZATIONS, value: 'organization'});
|
|
|
|
}
|
|
|
|
if(showPage[this.simpleView ? this.properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders] && showEntity["datasource"]) {
|
|
|
|
this.entities.push({label: OpenaireEntities.DATASOURCES, value: 'dataprovider'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.customFilter && this.customFilter.queryFieldName == "communityId" || this.properties.adminToolsCommunity === "connect") {
|
|
|
|
//for community pages: no organization in simple search, only results in advanced
|
|
|
|
this.entities = this.entities.filter(option => option.value !== 'organization' && option.value !== 'all');
|
|
|
|
if (!this.simpleView) {
|
|
|
|
this.entities = this.entities.filter(option => option.value !== 'project' && option.value !== 'dataprovider');
|
2020-06-29 15:15:52 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-18 10:29:14 +02:00
|
|
|
console.log(this.entities);
|
|
|
|
this.disableSelectEmitter.emit(this.entities.length == 1);
|
2022-04-15 23:49:35 +02:00
|
|
|
}
|
|
|
|
}));
|
2022-04-18 10:29:14 +02:00
|
|
|
} else if (((this.customFilter && this.customFilter.queryFieldName == "community") && this.properties.adminToolsCommunity === "monitor") ||
|
|
|
|
(this.customFilter && (this.customFilter.queryFieldName == "relfunder" || this.customFilter.queryFieldName == "funder")) ||
|
|
|
|
(this.customFilter && this.customFilter.queryFieldName == "relorganizationid")) {
|
|
|
|
this.entities.push({label: OpenaireEntities.RESULTS, value: 'result'});
|
|
|
|
this.entities.push({label: OpenaireEntities.PROJECTS, value: 'project'});
|
|
|
|
this.entities.push({label: OpenaireEntities.ORGANIZATIONS, value: 'organization'});
|
|
|
|
this.entities.push({label: OpenaireEntities.DATASOURCES, value: 'dataprovider'});
|
|
|
|
this.disableSelectEmitter.emit(true);
|
2022-04-15 23:49:35 +02:00
|
|
|
} else {
|
|
|
|
if(this.onlyresults) {
|
2022-04-18 10:29:14 +02:00
|
|
|
if(this.simpleView) {
|
|
|
|
this.entities.push({label: 'All ' + OpenaireEntities.RESULTS.toLowerCase(), value: 'all'});
|
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
this.entities.push({label: OpenaireEntities.PUBLICATIONS, value: 'publications'});
|
|
|
|
this.entities.push({label: OpenaireEntities.DATASETS, value: 'datasets'});
|
|
|
|
this.entities.push({label: OpenaireEntities.SOFTWARE, value: 'software'});
|
|
|
|
this.entities.push({label: OpenaireEntities.OTHER, value: 'other'});
|
2020-06-29 15:15:52 +02:00
|
|
|
} else {
|
2022-04-18 10:29:14 +02:00
|
|
|
if(this.simpleView) {
|
|
|
|
this.entities.push({label: 'All Content', value: 'all'});
|
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
this.entities.push({label: OpenaireEntities.RESULTS, value: 'result'});
|
|
|
|
this.entities.push({label: OpenaireEntities.PROJECTS, value: 'project'});
|
|
|
|
this.entities.push({label: OpenaireEntities.ORGANIZATIONS, value: 'organization'});
|
|
|
|
this.entities.push({label: OpenaireEntities.DATASOURCES, value: 'dataprovider'});
|
2022-04-18 10:29:14 +02:00
|
|
|
this.disableSelectEmitter.emit(false);
|
2020-06-29 15:15:52 +02:00
|
|
|
}
|
2020-02-13 15:44:51 +01:00
|
|
|
}
|
|
|
|
this.selectedEntity = this.currentEntity;
|
2020-03-03 15:32:43 +01:00
|
|
|
this.selectionChange.emit({
|
|
|
|
entity: this.selectedEntity,
|
|
|
|
simpleUrl: this.getUrl(true),
|
|
|
|
advancedUrl: this.getUrl(false)
|
|
|
|
});
|
2020-02-13 15:44:51 +01:00
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
|
2020-07-13 00:19:30 +02:00
|
|
|
public ngOnDestroy() {
|
2022-04-15 23:49:35 +02:00
|
|
|
for (let subscription of this.subscriptions) {
|
|
|
|
subscription.unsubscribe();
|
2020-07-13 00:19:30 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-29 15:15:52 +02:00
|
|
|
|
2022-04-18 10:29:14 +02:00
|
|
|
getLabel(value: string) {
|
|
|
|
return this.entities.find(entity => entity.value === value)?.label;
|
|
|
|
}
|
|
|
|
|
2020-03-03 15:32:43 +01:00
|
|
|
entityChanged() {
|
2020-03-05 14:21:01 +01:00
|
|
|
if (!this.simpleView || this.onChangeNavigate) {
|
2022-04-15 23:49:35 +02:00
|
|
|
this.router.navigate([this.getUrl(this.simpleView)], {queryParams: this.customFilter ? this.customFilter.getParameters() : {}});
|
2020-03-03 15:32:43 +01:00
|
|
|
} else {
|
|
|
|
this.selectionChange.emit({
|
|
|
|
entity: this.selectedEntity,
|
|
|
|
simpleUrl: this.getUrl(true),
|
|
|
|
advancedUrl: this.getUrl(false)
|
|
|
|
});
|
2020-02-13 15:44:51 +01:00
|
|
|
}
|
2020-06-29 15:15:52 +02:00
|
|
|
|
2020-02-13 15:44:51 +01:00
|
|
|
}
|
2020-06-29 15:15:52 +02:00
|
|
|
|
2022-04-15 23:49:35 +02:00
|
|
|
getUrl(simpleView: boolean): string {
|
2020-06-29 15:15:52 +02:00
|
|
|
if (!this.onlyresults) {
|
2020-04-22 15:00:13 +02:00
|
|
|
if (this.selectedEntity == "all") {
|
2022-04-15 23:49:35 +02:00
|
|
|
return (simpleView ? "/search/find/" : null);
|
2020-04-22 15:00:13 +02:00
|
|
|
} else if (this.selectedEntity == "result") {
|
2022-04-15 23:49:35 +02:00
|
|
|
return (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
|
2020-04-22 15:00:13 +02:00
|
|
|
} else if (this.selectedEntity == "project") {
|
2022-04-15 23:49:35 +02:00
|
|
|
return (simpleView ? this.properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects);
|
2020-04-22 15:00:13 +02:00
|
|
|
} else if (this.selectedEntity == "dataprovider") {
|
2022-04-15 23:49:35 +02:00
|
|
|
return (simpleView ? this.properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders);
|
2020-04-22 15:00:13 +02:00
|
|
|
} else if (this.selectedEntity == "organization") {
|
2022-04-15 23:49:35 +02:00
|
|
|
return (simpleView ? this.properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations);
|
2020-04-22 15:00:13 +02:00
|
|
|
}
|
2020-06-29 15:15:52 +02:00
|
|
|
} else {
|
2022-04-15 23:49:35 +02:00
|
|
|
return (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
|
2020-04-22 15:00:13 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 15:44:51 +01:00
|
|
|
}
|