import {ChangeDetectorRef, Component} from '@angular/core'; import {PluginBaseComponent, PluginBaseInfo, PluginInfoCards, PluginURL} from "../../utils/base-plugin.component"; import {OpenaireEntities} from "../../../../utils/properties/searchFields"; import {properties} from "../../../../../../environments/environment"; import {CustomizationService} from "../../../../services/customization.service"; import {CommunityService} from "../../../../connect/community/community.service"; import {Filter} from "../../../../searchPages/searchUtils/searchHelperClasses.class"; import {Router} from "@angular/router"; import {RouterHelper} from "../../../../utils/routerHelper.class"; export class PluginSearchBar extends PluginBaseInfo{ alternativeTitle:string =""; showTitle:boolean = true; showShortTitle:boolean = false; compare(oldObject): any { let newObj= super.compare(oldObject); return newObj; } } @Component({ selector: 'plugin-search-bar', template: `
No community info available

{{community.shortTitle}}

{{pluginObject.alternativeTitle}}

{{community.title}}
` }) export class PluginSearchBarComponent extends PluginBaseComponent{ disableSelect: boolean = true; openaireEntities= OpenaireEntities; selectedEntity = 'result'; selectedEntitySimpleUrl; selectedEntityAdvancedUrl; keyword: string = ""; // customFilter; placeholderText = "Search by title, author, abstract, DOI, orcid... "; resultTypes: Filter = { values: [], filterId: "type", countSelectedValues: 0, filterType: 'checkbox', originalFilterId: "", valueIsExact: true, title: "Type", filterOperator: "or" }; community = null; public routerHelper: RouterHelper = new RouterHelper(); constructor(private communityService: CommunityService, protected layoutService: CustomizationService, private cdr: ChangeDetectorRef, private _router: Router,) { super() this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe( community => { this.community = community; this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe( community => { this.getLayout(community.communityId); })); } )); } ngOnInit() { this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe( community => { this.getLayout(community.communityId); })); } goTo(simple: boolean) { let url = (simple) ? this.selectedEntitySimpleUrl : this.selectedEntityAdvancedUrl; let parameterNames = []; let parameterValues = []; if (this.keyword.length > 0) { parameterNames.push("fv0"); parameterValues.push(this.keyword); parameterNames.push("f0"); parameterValues.push("q"); } this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)}); } disableSelectChange(event: boolean) { this.disableSelect = event; this.cdr.detectChanges(); } entityChanged($event) { this.selectedEntity = $event.entity; this.selectedEntitySimpleUrl = $event.simpleUrl; this.selectedEntityAdvancedUrl = $event.advancedUrl; if (this.selectedEntity == 'result') { this.placeholderText = "Search by title, author, abstract, DOI, orcid... "; } else if (this.selectedEntity == 'project') { this.placeholderText = "Search by project title, grant id, funder..."; } else if (this.selectedEntity == 'dataprovider') { this.placeholderText = "Search by name..."; } else { this.placeholderText = "Search community content"; } } }