418 lines
18 KiB
TypeScript
418 lines
18 KiB
TypeScript
import {Component, Input, Output} from '@angular/core';
|
|
import {EventEmitter, ViewChild} 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 {Observable} from 'rxjs/Observable';
|
|
|
|
import {FetchPublications} from '../../utils/fetchEntitiesClasses/fetchPublications.class';
|
|
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
|
|
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
|
|
import {FetchDatasets} from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
|
|
import {FetchSoftware} from '../../utils/fetchEntitiesClasses/fetchSoftware.class';
|
|
import {FetchOrganizations} from '../../utils/fetchEntitiesClasses/fetchOrganizations.class';
|
|
|
|
import {SearchPublicationsService} from '../../services/searchPublications.service';
|
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
|
import {SearchDatasetsService} from '../../services/searchDatasets.service';
|
|
import {SearchSoftwareService} from '../../services/searchSoftware.service';
|
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
|
|
|
import {SearchFields, FieldDetails} 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';
|
|
|
|
@Component({
|
|
changeDetection: ChangeDetectionStrategy.Default,
|
|
encapsulation: ViewEncapsulation.Emulated,
|
|
selector: 'search-find',
|
|
templateUrl: 'search.component.html'
|
|
})
|
|
export class SearchComponent {
|
|
public sub: any; piwiksub: any;
|
|
public reloadPublications: boolean;
|
|
public reloadDatasets: boolean;
|
|
public reloadSoftware: 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 projectsTab:string[];
|
|
public dataproviders:string[];
|
|
public organizations:string[];
|
|
|
|
public activeTab = "publications";
|
|
public linkToSearchPublications = "";
|
|
public linkToSearchProjects = "";
|
|
public linkToSearchDataproviders = "";
|
|
public linkToSearchDatasets = "";
|
|
public linkToSearchSoftware = "";
|
|
public linkToSearchOrganizations = "";
|
|
|
|
public fetchPublications : FetchPublications;
|
|
public fetchDataproviders : FetchDataproviders;
|
|
public fetchProjects : FetchProjects;
|
|
public fetchDatasets: FetchDatasets;
|
|
public fetchSoftware: FetchSoftware;
|
|
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 fundersSize:any = null;
|
|
public projectsSize:any = null;
|
|
public datasourcesSize:any = null;
|
|
showPublications:boolean= false;
|
|
showDatasets:boolean= false;
|
|
showSoftware:boolean=false;
|
|
showProjects:boolean= false;
|
|
showDataProviders:boolean= false;
|
|
showOrganizations:boolean= false;
|
|
advancedSearchLink:string ="/search/advanced/publications";
|
|
properties: EnvProperties;
|
|
|
|
public subPub;public subData;public subProjects;public subOrg; public subDataPr;
|
|
constructor ( private route: ActivatedRoute,
|
|
private _router: Router,
|
|
private _searchPublicationsService: SearchPublicationsService,
|
|
private _searchDataprovidersService: SearchDataprovidersService,
|
|
private _searchProjectsService: SearchProjectsService,
|
|
private _searchDatasetsService: SearchDatasetsService,
|
|
private _searchSoftwareService: SearchSoftwareService,
|
|
private _searchOrganizationsService: SearchOrganizationsService,
|
|
private _refineFieldResultsService:RefineFieldResultsService,
|
|
private location: Location,
|
|
private _meta: Meta,
|
|
private _title: Title,
|
|
private _piwikService:PiwikService,
|
|
private config: ConfigurationService ) {
|
|
this.fetchPublications = new FetchPublications(this._searchPublicationsService);
|
|
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
|
|
this.fetchProjects = new FetchProjects(this._searchProjectsService);
|
|
this.fetchDatasets = new FetchDatasets( this._searchDatasetsService);
|
|
this.fetchSoftware = new FetchSoftware(this._searchSoftwareService);
|
|
this.fetchOrganizations = new FetchOrganizations( this._searchOrganizationsService);
|
|
|
|
}
|
|
|
|
public ngOnInit() {
|
|
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'");
|
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
|
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE |Search publications, research data, projects...").subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.config.getCommunityInformation(this.properties.adminToolsAPIURL, this.properties.adminToolsCommunity ).subscribe(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.sub = this.route.queryParams.subscribe(params => {
|
|
|
|
this.keyword = (params['keyword'])?params['keyword']:"";
|
|
if(this.keyword !=null && this.keyword.length > 0){
|
|
this.reloadTabs();
|
|
//if showPublications == false will set 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.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() {
|
|
this.sub.unsubscribe();
|
|
if(this.piwiksub){
|
|
this.piwiksub.unsubscribe();
|
|
}
|
|
if(this.keyword !=null && this.keyword.length > 0){
|
|
if(this.subPub){
|
|
this.subPub.unsubscribe();
|
|
}
|
|
if(this.subData){
|
|
this.subData.unsubscribe();
|
|
}
|
|
if(this.subProjects){
|
|
this.subProjects.unsubscribe();
|
|
}
|
|
if(this.subOrg){
|
|
this.subOrg.unsubscribe();
|
|
}
|
|
if(this.subDataPr){
|
|
this.subDataPr.unsubscribe();
|
|
}
|
|
|
|
}
|
|
}
|
|
public searchPublications() {
|
|
this.activeTab = "publications";
|
|
this.advancedSearchLink ="/search/advanced/publications";
|
|
if( this.reloadPublications &&
|
|
this.fetchPublications.searchUtils.status != this.errorCodes.NONE &&
|
|
this.fetchPublications.searchUtils.status != this.errorCodes.ERROR) {
|
|
this.reloadPublications = false;
|
|
this.fetchPublications.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
|
this.linkToSearchPublications = this.properties.searchLinkToPublications;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
public searchDatasets() {
|
|
this.activeTab = "research data";
|
|
this.advancedSearchLink ="/search/advanced/datasets";
|
|
if(this.reloadDatasets &&
|
|
this.fetchDatasets.searchUtils.status != this.errorCodes.NONE &&
|
|
this.fetchDatasets.searchUtils.status != this.errorCodes.ERROR) {
|
|
this.reloadDatasets = false;
|
|
this.fetchDatasets.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
|
this.linkToSearchDatasets =this.properties.searchLinkToDatasets;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
public searchSoftware() {
|
|
this.activeTab = "software";
|
|
this.advancedSearchLink ="/search/advanced/software";
|
|
if(this.reloadSoftware &&
|
|
( this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
|
|
this.fetchSoftware.searchUtils.status == this.errorCodes.DONE )) {
|
|
this.reloadSoftware = false;
|
|
this.fetchSoftware.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
|
this.linkToSearchSoftware = this.properties.searchLinkToSoftware;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
public searchProjects() {
|
|
this.activeTab = "projects";
|
|
this.advancedSearchLink ="/search/advanced/projects";
|
|
if(this.reloadProjects &&
|
|
this.fetchProjects.searchUtils.status != this.errorCodes.NONE &&
|
|
this.fetchProjects.searchUtils.status != this.errorCodes.ERROR) {
|
|
this.reloadProjects = false;
|
|
this.fetchProjects.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
|
this.linkToSearchProjects = this.properties.searchLinkToProjects;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
public searchDataProviders() {
|
|
this.activeTab = "content providers";
|
|
this.advancedSearchLink ="/search/advanced/dataproviders";
|
|
if( this.reloadDataproviders &&
|
|
this.fetchDataproviders.searchUtils.status != this.errorCodes.NONE &&
|
|
this.fetchDataproviders.searchUtils.status != this.errorCodes.ERROR) {
|
|
this.reloadDataproviders = false;
|
|
this.fetchDataproviders.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
|
this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders;// + "?keyword=" + this.keyword;
|
|
}
|
|
}
|
|
public searchOrganizations() {
|
|
this.activeTab = "organizations";
|
|
this.advancedSearchLink ="/search/advanced/organizations";
|
|
if( this.reloadOrganizations &&
|
|
this.fetchOrganizations.searchUtils.status != this.errorCodes.NONE &&
|
|
this.fetchOrganizations.searchUtils.status != this.errorCodes.ERROR) {
|
|
this.reloadOrganizations = false;
|
|
this.fetchOrganizations.getResultsByKeyword(this.keyword, 1, 10,this.properties);
|
|
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 == "organizations") {
|
|
this.searchOrganizations();
|
|
}
|
|
|
|
this.count();
|
|
}
|
|
|
|
private count() {
|
|
if(this.activeTab != "publications" && this.showPublications){
|
|
this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchPublications.results = [];
|
|
this.subPub = this._searchPublicationsService.numOfSearchPublications(this.keyword,this.properties).subscribe(
|
|
data => {
|
|
console.log("Count results: "+data);
|
|
this.fetchPublications.searchUtils.totalResults = data;
|
|
this.fetchPublications.searchUtils.status = this.errorCodes.DONE;
|
|
if(this.fetchPublications.searchUtils.totalResults == 0) {
|
|
this.fetchPublications.searchUtils.status = this.errorCodes.NONE;
|
|
}
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
this.fetchPublications.searchUtils.status = this.errorCodes.ERROR;
|
|
}
|
|
);
|
|
}
|
|
if(this.activeTab != "research data" && this.showDatasets){
|
|
this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchDatasets.results = [];
|
|
this.subData = this._searchDatasetsService.numOfSearchDatasets(this.keyword,this.properties).subscribe(
|
|
data => {
|
|
this.fetchDatasets.searchUtils.totalResults = data;
|
|
this.fetchDatasets.searchUtils.status = this.errorCodes.DONE;
|
|
if(this.fetchDatasets.searchUtils.totalResults == 0) {
|
|
this.fetchDatasets.searchUtils.status = this.errorCodes.NONE;
|
|
}
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
this.fetchDatasets.searchUtils.status = this.errorCodes.ERROR;
|
|
}
|
|
);
|
|
}
|
|
if(this.activeTab != "software" && this.showSoftware){
|
|
this.fetchSoftware.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchSoftware.results = [];
|
|
this.subData = this._searchSoftwareService.numOfSearchSoftware(this.keyword,this.properties).subscribe(
|
|
data => {
|
|
this.fetchSoftware.searchUtils.totalResults = data;
|
|
this.fetchSoftware.searchUtils.status = this.errorCodes.DONE;
|
|
if(this.fetchSoftware.searchUtils.totalResults == 0) {
|
|
this.fetchSoftware.searchUtils.status = this.errorCodes.NONE;
|
|
}
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
if(err.status == '404') {
|
|
this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
} else if(err.status == '500') {
|
|
this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
|
|
} else {
|
|
this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
}
|
|
//this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
|
|
}
|
|
);
|
|
}
|
|
if(this.activeTab != "projects" && this.showProjects){
|
|
this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchProjects.results = [];
|
|
this.subProjects = this._searchProjectsService.numOfSearchProjects(this.keyword,this.properties).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.fetchProjects.searchUtils.status = this.errorCodes.ERROR;
|
|
}
|
|
);
|
|
}
|
|
if(this.activeTab != "content providers" && this.showDataProviders){
|
|
this.fetchDataproviders.results = [];
|
|
this.fetchDataproviders.getNumForSearch(this.keyword,this.properties);
|
|
}
|
|
if(this.activeTab != "organizations" && this.showOrganizations){
|
|
this.fetchOrganizations.searchUtils.status = this.errorCodes.LOADING;
|
|
this.fetchOrganizations.results = [];
|
|
this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations(this.keyword,this.properties).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.fetchOrganizations.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private reloadTabs() {
|
|
this.reloadPublications = true;
|
|
this.reloadDatasets = true;
|
|
this.reloadSoftware = true;
|
|
this.reloadProjects = true;
|
|
this.reloadDataproviders = true;
|
|
this.reloadOrganizations = true;
|
|
}
|
|
|
|
|
|
|
|
}
|