175 lines
6.1 KiB
TypeScript
175 lines
6.1 KiB
TypeScript
import {Component, Input, Output, EventEmitter, ViewChild, ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {Location} from '@angular/common';
|
|
import "rxjs/add/observable/zip";
|
|
import { Meta, MetaDefinition, ConfigurationService} from 'ng-openaire-library';
|
|
|
|
import {SearchPublicationsService, SearchDataprovidersService, SearchProjectsService, SearchDatasetsService, SearchOrganizationsService, SearchFields} from 'ng-openaire-library';
|
|
import { ErrorCodes, RouterHelper, NumberUtils, RefineFieldResultsService, PiwikService} from 'ng-openaire-library';
|
|
import {Properties} from '../utils/properties';
|
|
|
|
|
|
@Component({
|
|
selector: 'home',
|
|
templateUrl: 'home.component.html',
|
|
})
|
|
export class HomeComponent {
|
|
public piwiksub: any;
|
|
public subfunders: any;
|
|
|
|
public pageTitle = "OpenAIRE"
|
|
public keyword:string = "";
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
|
|
|
public publicationsSize:any = null;
|
|
public datasetsSize:any = null;
|
|
public fundersSize:any = null;
|
|
public projectsSize:any = null;
|
|
public datasourcesSize:any = null;
|
|
|
|
showPublications:boolean= false;
|
|
showDatasets:boolean= false;
|
|
showProjects:boolean= false;
|
|
showDataProviders:boolean= false;
|
|
|
|
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 _searchOrganizationsService: SearchOrganizationsService,
|
|
private _refineFieldResultsService:RefineFieldResultsService,
|
|
private location: Location, private _meta: Meta,private _piwikService:PiwikService,
|
|
private config: ConfigurationService
|
|
) {
|
|
|
|
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
|
|
|
|
var title = "OpenAIRE";
|
|
|
|
var url = Properties.getBaseLink()+this._router.url;
|
|
this._meta.setTitle(title);
|
|
this._meta.updateMeta("description", description);
|
|
this._meta.updateProperty("og:description", description);
|
|
this._meta.updateProperty("og:title", title);
|
|
this._meta.updateProperty("og:url", url);
|
|
|
|
const entityOne = this.config.isEntityEnabled("publication");
|
|
const entityTwo = this.config.isEntityEnabled("dataset");
|
|
const entityThree = this.config.isEntityEnabled("project");
|
|
const entityFour = this.config.isEntityEnabled("datasource");
|
|
const example = Observable.zip(entityOne,entityTwo,entityThree,entityFour);
|
|
|
|
// wait until all observables have emitted a value then emit all as an array
|
|
example.subscribe(data => {
|
|
this.showPublications = data[0];
|
|
this.showDatasets = data[1];
|
|
this.showProjects = data[2];
|
|
this.showDataProviders = data[3];
|
|
this.getNumbers();
|
|
});
|
|
if(Properties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
|
|
this.piwiksub = this._piwikService.trackView("OpenAIRE").subscribe();
|
|
}
|
|
|
|
}
|
|
|
|
public ngOnInit() {
|
|
}
|
|
public ngOnDestroy() {
|
|
if(this.piwiksub){
|
|
this.piwiksub.unsubscribe();
|
|
}
|
|
if(this.subfunders){
|
|
this.subfunders.unsubscribe();
|
|
}
|
|
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();
|
|
}
|
|
|
|
}
|
|
|
|
private getNumbers() {
|
|
if(this.showPublications){
|
|
this.subPub = this._searchPublicationsService.numOfSearchPublications("").subscribe(
|
|
data => {
|
|
console.log("Count results: "+data);
|
|
if(data && data != null && data > 0 ){
|
|
this.publicationsSize = NumberUtils.roundNumber(data);
|
|
console.log("After round");
|
|
|
|
}
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
}
|
|
);
|
|
}
|
|
if(this.showDatasets){
|
|
this.subData = this._searchDatasetsService.numOfSearchDatasets("").subscribe(
|
|
data => {
|
|
if(data && data != null && data > 0 ){
|
|
this.datasetsSize = NumberUtils.roundNumber(data);
|
|
}
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
}
|
|
);
|
|
}
|
|
if(this.showProjects){
|
|
this.subfunders = this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project").subscribe(
|
|
data => {
|
|
|
|
console.info("Funders: "+data[1][0].title+ " values "+data[1][0].values.length+"]");
|
|
console.info("Projects: "+data[0]);
|
|
|
|
if(data[0] && data[0] > 0 ){
|
|
this.projectsSize = NumberUtils.roundNumber(data[0]);
|
|
}
|
|
if(data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values ){
|
|
this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
|
|
}
|
|
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
});
|
|
}
|
|
if(this.showDataProviders){
|
|
this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders("").subscribe(
|
|
data => {
|
|
if(data && data != null && data > 0 ){
|
|
this.datasourcesSize = NumberUtils.roundNumber(data);
|
|
}
|
|
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|