monitor/src/app/home/home.component.ts

266 lines
9.4 KiB
TypeScript
Raw Normal View History

import {Component} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Meta, Title} from '@angular/platform-browser';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {StakeholderService} from "../services/stakeholder.service";
import {RefineFieldResultsService} from "../openaireLibrary/services/refineFieldResults.service";
import {NumberUtils} from "../openaireLibrary/utils/number-utils.class";
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
@Component({
selector: 'home',
templateUrl: 'home.component.html',
})
export class HomeComponent {
public piwiksub: any;
public pageTitle = "OpenAIRE | Monitor";
public funders = [];
public gifs: { "gif": string, "header": string, "text" }[] = [];
public pageContents = null;
public divContents = null;
// Message variables
public status: number;
public loading: boolean = true;
public subscriberErrorMessage: string = "";
public errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
properties: EnvProperties;
public keyword: string = "";
public type: string = "all";
public publicationsSize:any = null;
public datasetsSize:any = null;
public softwareSize: any = null;
public otherSize: any = null;
public fundersSize:any = null;
numberSubs=[];
constructor(
private route: ActivatedRoute,
private _router: Router,
private _meta: Meta,
private _title: Title,
private _piwikService: PiwikService,
private _stakeholderService: StakeholderService,
private helper: HelperService,
private seoService: SEOService,
private _refineFieldResultsService:RefineFieldResultsService, private _searchResearchResultsService: SearchResearchResultsService) {
var description = "OpenAIRE - Monitor, Statistics, Search, Funder, EC, European Commision";
var title = "OpenAIRE - Monitor";
this._meta.updateTag({content: description}, "name='description'");
this._meta.updateTag({content: description}, "property='og:description'");
this._meta.updateTag({content: title}, "property='og:title'");
this._title.setTitle(title);
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.status = this.errorCodes.LOADING;
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
var url = data.envSpecific.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.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Monitor", this.properties.piwikSiteId).subscribe();
}
this.getNumbers();
this.getFunders();
// this.createGifs();
//this.getDivContents();
this.getPageContents();
});
}
private getPageContents() {
this.helper.getPageHelpContents(this.properties, 'monitor', this._router.url).subscribe(contents => {
this.pageContents = contents;
})
}
private getDivContents() {
this.helper.getDivHelpContents(this.properties, 'monitor', this._router.url).subscribe(contents => {
this.divContents = contents;
})
}
getNumbers(){
this.numberSubs.push(this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project", this.properties).subscribe(
data => {
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);
this.handleError("Error getting 'funder' field results of projects", err);
}));
this.numberSubs.push(this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
data => {
if(data && data != null && data > 0 ){
this.publicationsSize = NumberUtils.roundNumber(data);
}
},
err => {
//console.log(err);
this.handleError("Error getting number of publications", err);
}
));
this.numberSubs.push(this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties).subscribe(
data => {
if(data && data != null && data > 0 ){
this.datasetsSize = NumberUtils.roundNumber(data);
}
},
err => {
//console.log(err);
this.handleError("Error getting number of research data", err);
}
));
this.numberSubs.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.numberSubs.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);
}
));
}
public getFunders() {
this.loading = true;
this.status = this.errorCodes.LOADING;
this.subscriberErrorMessage = "";
this.funders = [];
this._stakeholderService.mockgetFunders().subscribe(
funders => {
console.log(funders)
if(!funders){
return;
}
if(funders.length == 0) {
this.status = this.errorCodes.DONE;
return;
}
// this.sort(funders);
this.funders = funders;
this.loading = false;
},
error => {
this.status = this.handleError("Error getting funders", error);
this.loading = false;
}
);
}
private createGifs() {
this.gifs.push({
gif: "assets/connect-assets/home/gifs/deposit.gif",
header: "Find a repository to deposit your research outcome",
text: "This is OpenAIREs key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
});
this.gifs.push({
gif: "assets/connect-assets/home/gifs/link.gif",
header: "Link your research output with your community, funding, and other research products",
text: "This is OpenAIREs key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
});
this.gifs.push({
gif: "assets/connect-assets/home/gifs/overview.gif",
header: "View community's overview at a glance",
text: "This is OpenAIREs key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
});
this.gifs.push({
gif: "assets/connect-assets/home/gifs/results.gif",
header: "Search & browse your community's research products. ",
text: "This is OpenAIREs key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
});
this.gifs.push({
gif: "assets/connect-assets/home/gifs/graph-analysis.gif",
header: "View statistics for your community's research products.",
text: "This is OpenAIREs key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
});
}
private sort(results: CommunityInfo[]) {
results.sort((left, right): number => {
if (!right.date || left.date > right.date) {
return -1;
} else if (!left.date || left.date < right.date) {
return 1;
} else {
if (left.title > right.title) {
return 1;
} else if (left.title < right.title) {
return -1;
} else {
return 0;
}
}
})
}
public quote(param: string): string {
return StringUtils.quote(param);
}
public ngOnDestroy() {
if (this.piwiksub) {
this.piwiksub.unsubscribe();
}
}
private handleError(message: string, error): number {
var code = "";
if (!error.status) {
var error = error.json();
code = error.code;
} else {
code = error.status;
}
console.error("Communities (component): " + message, error);
return this.errorMessages.getErrorCode(code);
}
}