graph/src/app/home/home.component.ts

212 lines
7.6 KiB
TypeScript

import {Component} from '@angular/core';
import {Subscription} from 'rxjs';
import {ActivatedRoute, Router} from '@angular/router';
import {Location} from '@angular/common';
import "rxjs/add/observable/zip";
import {Title, Meta} from '@angular/platform-browser';
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
import {SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
import {SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
import {SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
import {RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
import {NumberUtils} from '../openaireLibrary/utils/number-utils.class';
import {RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
import {properties} from "../../environments/environment";
import {portals} from "./portals";
@Component({
selector: 'home',
templateUrl: 'home.component.html',
styleUrls: ['home.component.css']
})
export class HomeComponent {
public pageTitle = "OpenAIRE - Research Graph";
public errorCodes: ErrorCodes = new ErrorCodes();
public routerHelper: RouterHelper = new RouterHelper();
public publicationsSize: any = null;
public datasetsSize: any = null;
public datasetsLinkedSize: any = null;
public softwareLinkedSize: any = null;
public softwareSize: any = null;
public otherSize: any = null;
public fundersSize: any = null;
public projectsSize: any = null;
public datasourcesSize: any = null;
public portals: any[] = portals;
public state: number = 0;
private timeouts: any[] = [];
properties: EnvProperties = properties;
subs: Subscription[] = [];
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 _piwikService: PiwikService,
private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService
) {
let description = "OpenAIRE Research Graph is an open resource that aggregates a collection of research data properties (metadata, links) available within the OpenAIRE Open Science infrastructure for funders, organizations, researchers, research communities and publishers to interlink information by using a semantic graph database approach.";
this._title.setTitle(this.pageTitle);
this._meta.updateTag({content: description}, "name='description'");
this._meta.updateTag({content: description}, "property='og:description'");
this._meta.updateTag({content: this.pageTitle}, "property='og:title'");
}
public ngOnInit() {
if (this.properties) {
let url = this.properties.domain + this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(url, false);
this._meta.updateTag({content: url}, "property='og:url'");
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subs.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
}
this.getNumbers();
this.animation();
}
}
public ngOnDestroy() {
for (let sub of this.subs) {
sub.unsubscribe();
}
this.clearTimeouts();
}
private animation() {
this.timeouts.push(setTimeout(() => {
this.animation();
if (this.state === (this.portals.length -1)) {
this.state = 0
} else {
this.state++;
}
}, 4000));
}
private changeSlide(slide: number) {
this.clearTimeouts();
this.state = slide;
this.animation();
}
private clearTimeouts() {
this.timeouts.forEach(timeout => {
clearTimeout(timeout);
});
this.state = 0;
}
private getNumbers() {
this.subs.push(this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
data => {
if (data && data > 0) {
this.publicationsSize = NumberUtils.roundNumber(data);
}
},
err => {
this.handleError("Error getting number of publications", err);
}
));
this.subs.push(this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties).subscribe(
data => {
if (data && data > 0) {
this.datasetsSize = NumberUtils.roundNumber(data);
}
},
err => {
//console.log(err);
this.handleError("Error getting number of research data", err);
}
));
this.subs.push(this._searchResearchResultsService.numOfSearchResultsLinkedToPub("dataset", this.properties).subscribe(
data => {
if (data && data > 0) {
this.datasetsLinkedSize = NumberUtils.roundNumber(data);
}
},
err => {
this.handleError("Error getting number of linkedresearch data", err);
}
));
this.subs.push(this._searchResearchResultsService.numOfSearchResults("software", "", this.properties).subscribe(
data => {
if (data && data > 0) {
this.softwareSize = NumberUtils.roundNumber(data);
}
},
err => {
this.handleError("Error getting number of software data", err);
}
));
this.subs.push(this._searchResearchResultsService.numOfSearchResultsLinkedToPub("software", this.properties).subscribe(
data => {
if (data && data > 0) {
this.softwareLinkedSize = NumberUtils.roundNumber(data);
}
},
err => {
this.handleError("Error getting number of linked software", err);
}
));
this.subs.push(this._searchResearchResultsService.numOfSearchResults("other", "", this.properties).subscribe(
data => {
if (data && data > 0) {
this.otherSize = NumberUtils.roundNumber(data);
}
},
err => {
this.handleError("Error getting number of software data", err);
}
));
this.subs.push(this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"], "project", this.properties).subscribe(
data => {
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 => {
this.handleError("Error getting 'funder' field results of projects", err);
})
);
this.subs.push(this._searchDataprovidersService.numOfSearchDataproviders("", this.properties).subscribe(
data => {
if (data && data > 0) {
this.datasourcesSize = NumberUtils.roundNumber(data);
}
},
err => {
this.handleError("Error getting number of content providers", err);
}
));
}
private handleError(message: string, error) {
console.error("Home Page: " + message, error);
}
}