470 lines
20 KiB
TypeScript
470 lines
20 KiB
TypeScript
import {Component, Input} from '@angular/core';
|
|
import {ChangeDetectionStrategy} from '@angular/core';
|
|
import {ViewEncapsulation} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {Location} from '@angular/common';
|
|
import {Title, Meta} from '@angular/platform-browser';
|
|
|
|
import {FetchResearchResults} from '../../utils/fetchEntitiesClasses/fetchResearchResults.class';
|
|
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
|
|
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
|
|
import {FetchOrganizations} from '../../utils/fetchEntitiesClasses/fetchOrganizations.class';
|
|
|
|
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
|
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
|
|
|
import {SearchFields} from '../../utils/properties/searchFields';
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
|
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
|
import {ConfigurationService} from '../../utils/configuration/configuration.service';
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
|
import {SearchCustomFilter} from "../searchUtils/searchUtils.class";
|
|
import {Observable, Subscription} from "rxjs";
|
|
|
|
@Component({
|
|
changeDetection: ChangeDetectionStrategy.Default,
|
|
encapsulation: ViewEncapsulation.Emulated,
|
|
selector: 'search-find',
|
|
templateUrl: 'search.component.html'
|
|
})
|
|
export class SearchComponent {
|
|
subs: Subscription[] = [];
|
|
|
|
public reloadPublications: boolean;
|
|
public reloadDatasets: boolean;
|
|
public reloadSoftware: boolean;
|
|
public reloadOrps: boolean;
|
|
public reloadProjects: boolean;
|
|
public reloadDataproviders: boolean;
|
|
public reloadOrganizations: boolean;
|
|
|
|
|
|
public pageTitle = "Search in OpenAIRE"
|
|
public keyword: string = "";
|
|
public publications: string[];
|
|
public datasets: string[];
|
|
public software: string[];
|
|
public orps: string[];
|
|
public projectsTab: string[];
|
|
public dataproviders: string[];
|
|
public organizations: string[];
|
|
|
|
public activeTab = "publications";
|
|
public linkToSearchPublications = "";
|
|
public linkToSearchProjects = "";
|
|
public linkToSearchDataproviders = "";
|
|
public linkToSearchDatasets = "";
|
|
public linkToSearchSoftware = "";
|
|
public linkToSearchOrps = "";
|
|
public linkToSearchOrganizations = "";
|
|
|
|
public fetchPublications: FetchResearchResults;
|
|
public fetchDataproviders: FetchDataproviders;
|
|
public fetchProjects: FetchProjects;
|
|
public fetchDatasets: FetchResearchResults;
|
|
public fetchSoftware: FetchResearchResults;
|
|
public fetchOrps: FetchResearchResults;
|
|
public fetchOrganizations: FetchOrganizations;
|
|
|
|
public searchFields: SearchFields = new SearchFields();
|
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
public publicationsSize: any = null;
|
|
public datasetsSize: any = null;
|
|
public softwareSize: any = null;
|
|
public oprsSize: any = null;
|
|
public fundersSize: any = null;
|
|
public projectsSize: any = null;
|
|
public datasourcesSize: any = null;
|
|
showPublications: boolean = false;
|
|
showDatasets: boolean = false;
|
|
showSoftware: boolean = false;
|
|
showOrps: boolean = false;
|
|
showProjects: boolean = false;
|
|
showDataProviders: boolean = false;
|
|
showOrganizations: boolean = false;
|
|
advancedSearchLink: string = "/search/advanced/publications";
|
|
properties: EnvProperties;
|
|
@Input() logoURL;
|
|
@Input() name;
|
|
@Input() customFilter: SearchCustomFilter = null;
|
|
@Input() piwikSiteId = null;
|
|
@Input() formPlaceholderText = "Search for research outcomes, projects, content providers & organizations in OpenAIRE";
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
private _router: Router,
|
|
private _searchResearchResultsService: SearchResearchResultsService,
|
|
private _searchDataprovidersService: SearchDataprovidersService,
|
|
private _searchProjectsService: SearchProjectsService,
|
|
private _searchOrganizationsService: SearchOrganizationsService,
|
|
private _refineFieldResultsService: RefineFieldResultsService,
|
|
private location: Location,
|
|
private _meta: Meta,
|
|
private _title: Title,
|
|
private _piwikService: PiwikService,
|
|
private config: ConfigurationService,
|
|
private seoService: SEOService) {
|
|
this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
|
|
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
|
|
this.fetchProjects = new FetchProjects(this._searchProjectsService);
|
|
this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
|
|
this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
|
|
this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
|
|
this.fetchOrganizations = new FetchOrganizations(this._searchOrganizationsService);
|
|
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.subs.push(this.route.data
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
|
|
var title = "OpenAIRE | Search publications, research data, projects... | OpenAIRE";
|
|
this.properties = data.envSpecific;
|
|
var url = data.envSpecific.baseLink + this._router.url;
|
|
this._title.setTitle(title);
|
|
this._meta.updateTag({content: description}, "name='description'");
|
|
this._meta.updateTag({content: description}, "property='og:description'");
|
|
this._meta.updateTag({content: title}, "property='og:title'");
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this._router.url, false);
|
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
|
this.subs.push(this._piwikService.trackView(this.properties, "OpenAIRE |Search publications, research data, projects...", this.piwikSiteId).subscribe());
|
|
|
|
}
|
|
|
|
|
|
if ((this.customFilter && this.customFilter.queryFieldName == "communityId") || this.properties.adminToolsCommunity) {
|
|
//this.subs.push(this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
|
|
this.subs.push(this.config.communityInformationState.subscribe(data => {
|
|
if(data) {
|
|
var showEntity = {};
|
|
for (var i = 0; i < data['entities'].length; i++) {
|
|
|
|
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
|
}
|
|
this.showPublications = showEntity["publication"];
|
|
this.showDatasets = showEntity["dataset"];
|
|
this.showProjects = showEntity["project"];
|
|
this.showOrganizations = showEntity["organization"];
|
|
this.showDataProviders = showEntity["datasource"];
|
|
this.showSoftware = showEntity["software"];
|
|
this.showOrps = showEntity["orp"];
|
|
if (this.customFilter && this.customFilter.queryFieldName == "communityId") {
|
|
this.showProjects = false;
|
|
this.showOrganizations = false;
|
|
this.showDataProviders = false;
|
|
}
|
|
this.loadAll();
|
|
}
|
|
}));
|
|
} else {
|
|
if ((this.customFilter && this.customFilter.queryFieldName == "country")) {
|
|
this.showPublications =true;
|
|
this.showDatasets = true;
|
|
this.showDataProviders = true;
|
|
this.showSoftware = true;
|
|
this.showOrps = true;
|
|
this.showProjects = true;
|
|
this.showOrganizations = true;
|
|
this.showDataProviders = true;
|
|
}
|
|
}
|
|
this.loadAll();
|
|
}));
|
|
}
|
|
|
|
loadAll() {
|
|
this.subs.push(this.route.queryParams.subscribe(params => {
|
|
|
|
this.reloadTabs();
|
|
this.keyword = (params['keyword']) ? params['keyword'] : "";
|
|
if (this.keyword != null && this.keyword.length > 0) {
|
|
//if showPublications == false will setValues another entity as the first
|
|
if (this.showPublications) {
|
|
this.activeTab = "publications";
|
|
this.searchPublications();
|
|
} else if (this.showDatasets) {
|
|
this.activeTab = "research data";
|
|
this.searchDatasets();
|
|
} else if (this.showSoftware) {
|
|
this.activeTab = "software";
|
|
this.searchSoftware();
|
|
} else if (this.showOrps) {
|
|
this.activeTab = "other research products";
|
|
this.searchOrps();
|
|
} else if (this.showProjects) {
|
|
this.activeTab = "projects";
|
|
this.searchProjects();
|
|
} else if (this.showDataProviders) {
|
|
this.activeTab = "content providers";
|
|
this.searchDataProviders();
|
|
} else if (this.showOrganizations) {
|
|
this.activeTab = "organizations";
|
|
this.searchOrganizations();
|
|
}
|
|
this.count();
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
public ngOnDestroy() {
|
|
for (let sub of this.subs) {
|
|
sub.unsubscribe();
|
|
}
|
|
}
|
|
|
|
public searchPublications() {
|
|
this.activeTab = "publications";
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedPublications;//"/search/advanced/publications";
|
|
if (this.reloadPublications &&
|
|
this.fetchPublications.searchUtils.status != this.errorCodes.NONE /*&&
|
|
this.fetchPublications.searchUtils.status != this.errorCodes.ERROR*/
|
|
&& (this.keyword != null && this.keyword.length > 0)) {
|
|
this.reloadPublications = false;
|
|
this.fetchPublications.getResultsByKeyword("publication", this.keyword, 1, 10, this.properties, this.customFilter);
|
|
this.linkToSearchPublications = this.properties.searchLinkToPublications;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
|
|
public searchDatasets() {
|
|
this.activeTab = "research data";
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedDatasets;//"/search/advanced/datasets";
|
|
if (this.reloadDatasets &&
|
|
this.fetchDatasets.searchUtils.status != this.errorCodes.NONE /*&&
|
|
this.fetchDatasets.searchUtils.status != this.errorCodes.ERROR*/
|
|
&& (this.keyword != null && this.keyword.length > 0)) {
|
|
this.reloadDatasets = false;
|
|
this.fetchDatasets.getResultsByKeyword("dataset", this.keyword, 1, 10, this.properties, this.customFilter);
|
|
this.linkToSearchDatasets = this.properties.searchLinkToDatasets;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
|
|
public searchSoftware() {
|
|
|
|
this.activeTab = "software";
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedSoftware;//"/search/advanced/software";
|
|
if (this.reloadSoftware
|
|
&& this.fetchSoftware.searchUtils.status != this.errorCodes.NONE/* &&
|
|
( this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
|
|
this.fetchSoftware.searchUtils.status == this.errorCodes.DONE )*/
|
|
&& (this.keyword != null && this.keyword.length > 0)) {
|
|
this.reloadSoftware = false;
|
|
this.fetchSoftware.getResultsByKeyword("software", this.keyword, 1, 10, this.properties, this.customFilter);
|
|
this.linkToSearchSoftware = this.properties.searchLinkToSoftware;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
|
|
public searchOrps() {
|
|
this.activeTab = "other research products";
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedOrps;//"/search/advanced/other";
|
|
if (this.reloadOrps &&
|
|
this.fetchOrps.searchUtils.status != this.errorCodes.NONE /*&&
|
|
this.fetchOrps.searchUtils.status != this.errorCodes.ERROR*/
|
|
&& (this.keyword != null && this.keyword.length > 0)) {
|
|
this.reloadOrps = false;
|
|
this.fetchOrps.getResultsByKeyword("other", this.keyword, 1, 10, this.properties, this.customFilter);
|
|
this.linkToSearchOrps = this.properties.searchLinkToOrps;
|
|
}
|
|
}
|
|
|
|
public searchProjects() {
|
|
this.activeTab = "projects";
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedProjects;//"/search/advanced/projects";
|
|
if (this.reloadProjects &&
|
|
this.fetchProjects.searchUtils.status != this.errorCodes.NONE /*&&
|
|
this.fetchProjects.searchUtils.status != this.errorCodes.ERROR*/
|
|
&& (this.keyword != null && this.keyword.length > 0)) {
|
|
this.reloadProjects = false;
|
|
this.fetchProjects.getResultsByKeyword(this.keyword, 1, 10, this.properties, this.customFilter);
|
|
this.linkToSearchProjects = this.properties.searchLinkToProjects;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
|
|
public searchDataProviders() {
|
|
this.activeTab = "content providers";
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedDataProviders;//"/search/advanced/dataproviders";
|
|
if (this.reloadDataproviders &&
|
|
this.fetchDataproviders.searchUtils.status != this.errorCodes.NONE /*&&
|
|
this.fetchDataproviders.searchUtils.status != this.errorCodes.ERROR*/
|
|
&& (this.keyword != null && this.keyword.length > 0)) {
|
|
this.reloadDataproviders = false;
|
|
this.fetchDataproviders.getResultsByKeyword(this.keyword, 1, 10, this.properties, this.customFilter);
|
|
this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
|
|
public searchOrganizations() {
|
|
this.activeTab = "organizations";
|
|
this.advancedSearchLink = this.properties.searchLinkToAdvancedOrganizations;//"/search/advanced/organizations";
|
|
if (this.reloadOrganizations &&
|
|
this.fetchOrganizations.searchUtils.status != this.errorCodes.NONE /*&&
|
|
this.fetchOrganizations.searchUtils.status != this.errorCodes.ERROR*/
|
|
&& (this.keyword != null && this.keyword.length > 0)) {
|
|
this.reloadOrganizations = false;
|
|
this.fetchOrganizations.getResultsByKeyword(this.keyword, 1, 10, this.properties, this.customFilter);
|
|
this.linkToSearchOrganizations = this.properties.searchLinkToOrganizations;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
|
|
|
|
public keywordChanged($event) {
|
|
|
|
this.keyword = $event.value;
|
|
//console.info("Search Find: search with keyword \"" + this.keyword + "\"" );
|
|
this.location.go(location.pathname, "?keyword=" + this.keyword);
|
|
this.reloadTabs();
|
|
if (this.activeTab == "publications") {
|
|
this.searchPublications();
|
|
}
|
|
if (this.activeTab == "projects") {
|
|
this.searchProjects();
|
|
}
|
|
if (this.activeTab == "content providers") {
|
|
this.searchDataProviders();
|
|
}
|
|
if (this.activeTab == "research data") {
|
|
this.searchDatasets();
|
|
}
|
|
if (this.activeTab == "software") {
|
|
this.searchSoftware();
|
|
}
|
|
if (this.activeTab == "other research products") {
|
|
this.searchOrps();
|
|
}
|
|
if (this.activeTab == "organizations") {
|
|
this.searchOrganizations();
|
|
}
|
|
|
|
this.count();
|
|
}
|
|
|
|
private count() {
|
|
var refineParams = null;
|
|
if (this.customFilter) {
|
|
refineParams = (refineParams ? (refineParams + '&') : '') + "&fq=" + StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId)));
|
|
}
|
|
if (this.activeTab != "publications" && this.showPublications) {
|
|
this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchPublications.results = [];
|
|
|
|
this.subs.push(this.numOfSearchResults("publication", this.fetchPublications, refineParams));
|
|
}
|
|
if (this.activeTab != "research data" && this.showDatasets) {
|
|
this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchDatasets.results = [];
|
|
this.subs.push(this.numOfSearchResults("dataset", this.fetchDatasets, refineParams));
|
|
}
|
|
if (this.activeTab != "software" && this.showSoftware) {
|
|
this.fetchSoftware.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchSoftware.results = [];
|
|
this.subs.push(this.numOfSearchResults("software", this.fetchSoftware, refineParams));
|
|
}
|
|
if (this.activeTab != "other research products" && this.showOrps) {
|
|
this.fetchOrps.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchOrps.results = [];
|
|
this.subs.push(this.numOfSearchResults("other", this.fetchOrps, refineParams));
|
|
}
|
|
if (this.activeTab != "projects" && this.showProjects) {
|
|
this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchProjects.results = [];
|
|
this.subs.push(this._searchProjectsService.numOfSearchProjects(this.keyword, this.properties, refineParams).subscribe(
|
|
data => {
|
|
this.fetchProjects.searchUtils.totalResults = data;
|
|
this.fetchProjects.searchUtils.status = this.errorCodes.DONE;
|
|
if (this.fetchProjects.searchUtils.totalResults == 0) {
|
|
this.fetchProjects.searchUtils.status = this.errorCodes.NONE;
|
|
}
|
|
},
|
|
err => {
|
|
//console.log(err);
|
|
this.handleError("Error getting number of Projects", err);
|
|
this.fetchProjects.searchUtils.status = this.errorCodes.ERROR;
|
|
}
|
|
));
|
|
}
|
|
if (this.activeTab != "content providers" && this.showDataProviders) {
|
|
this.fetchDataproviders.results = [];
|
|
this.fetchDataproviders.getNumForSearch(this.keyword, this.properties, refineParams);
|
|
}
|
|
if (this.activeTab != "organizations" && this.showOrganizations) {
|
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchOrganizations.results = [];
|
|
this.subs.push(this._searchOrganizationsService.numOfSearchOrganizations(this.keyword, this.properties, refineParams).subscribe(
|
|
data => {
|
|
this.fetchOrganizations.searchUtils.totalResults = data;
|
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.DONE;
|
|
if (this.fetchOrganizations.searchUtils.totalResults == 0) {
|
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.NONE;
|
|
}
|
|
},
|
|
err => {
|
|
//console.log(err);
|
|
this.handleError("Error getting number of Organizations", err);
|
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
}
|
|
));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private numOfSearchResults(resultType: string, fetchClass: FetchResearchResults, refineParams) {
|
|
return this._searchResearchResultsService.numOfSearchResults(resultType, this.keyword, this.properties, refineParams).subscribe(
|
|
data => {
|
|
fetchClass.searchUtils.totalResults = data;
|
|
fetchClass.searchUtils.status = this.errorCodes.DONE;
|
|
if (fetchClass.searchUtils.totalResults == 0) {
|
|
fetchClass.searchUtils.status = this.errorCodes.NONE;
|
|
}
|
|
},
|
|
err => {
|
|
this.handleError("Error getting number of "+this.getEntityName(resultType, true, true), err);
|
|
fetchClass.searchUtils.status = this.errorCodes.ERROR;
|
|
}
|
|
);
|
|
}
|
|
|
|
private reloadTabs() {
|
|
this.reloadPublications = true;
|
|
this.reloadDatasets = true;
|
|
this.reloadSoftware = true;
|
|
this.reloadOrps = true;
|
|
this.reloadProjects = true;
|
|
this.reloadDataproviders = true;
|
|
this.reloadOrganizations = true;
|
|
this.fetchOrganizations.searchUtils.status = null;
|
|
this.fetchDataproviders.searchUtils.status = null;
|
|
this.fetchProjects.searchUtils.status = null;
|
|
this.fetchPublications.searchUtils.status = null;
|
|
this.fetchDatasets.searchUtils.status = null;
|
|
this.fetchSoftware.searchUtils.status = null;
|
|
this.fetchOrps.searchUtils.status = null;
|
|
}
|
|
|
|
private handleError(message: string, error) {
|
|
console.error("General Search Page: " + message, error);
|
|
}
|
|
|
|
private getEntityName (entityType:string, plural:boolean, full:boolean): string {
|
|
if(entityType == "publication") {
|
|
return "publication" + (plural ? "s" : "");
|
|
} else if(entityType == "dataset") {
|
|
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
|
|
} else if(entityType == "software") {
|
|
return "software";
|
|
} else if(entityType == "other") {
|
|
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
|
|
}
|
|
}
|
|
}
|