2020-06-10 23:51:10 +02:00
|
|
|
import {Component, ElementRef, ViewChild, ViewEncapsulation} from '@angular/core';
|
2019-09-30 14:51:38 +02:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {Meta, Title} from '@angular/platform-browser';
|
|
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
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";
|
2019-12-03 12:10:05 +01:00
|
|
|
import {RefineFieldResultsService} from "../openaireLibrary/services/refineFieldResults.service";
|
|
|
|
import {NumberUtils} from "../openaireLibrary/utils/number-utils.class";
|
|
|
|
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
|
2020-06-03 23:55:32 +02:00
|
|
|
import {animate, state, style, transition, trigger} from "@angular/animations";
|
|
|
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
2020-06-09 11:19:25 +02:00
|
|
|
import {LocalStorageService} from "../openaireLibrary/services/localStorage.service";
|
2020-06-10 11:12:17 +02:00
|
|
|
import {Stakeholder} from "../openaireLibrary/monitor/entities/stakeholder";
|
2020-06-10 23:51:10 +02:00
|
|
|
import {Session, User} from "../openaireLibrary/login/utils/helper.class";
|
|
|
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
2019-09-30 14:51:38 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'home',
|
|
|
|
templateUrl: 'home.component.html',
|
2020-06-03 23:55:32 +02:00
|
|
|
styleUrls: ['home.component.css'],
|
2020-06-10 23:51:10 +02:00
|
|
|
encapsulation: ViewEncapsulation.None,
|
2020-06-03 23:55:32 +02:00
|
|
|
animations: [
|
|
|
|
trigger('captain-left', [
|
|
|
|
state('before', style({
|
|
|
|
transform: 'translateX(-300px)'
|
|
|
|
})),
|
|
|
|
state('after', style({
|
|
|
|
transform: 'translateX(0)'
|
|
|
|
})),
|
|
|
|
transition('before => after', [
|
|
|
|
animate('0.7s')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
trigger('captain-right', [
|
|
|
|
state('before', style({
|
|
|
|
transform: 'translateX(300px)'
|
|
|
|
})),
|
|
|
|
state('after', style({
|
|
|
|
transform: 'translateX(0)'
|
|
|
|
})),
|
|
|
|
transition('before => after', [
|
|
|
|
animate('0.7s')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
trigger('1', [
|
|
|
|
state('1', style({
|
|
|
|
opacity: 1
|
|
|
|
})),
|
|
|
|
transition('* => *', [
|
|
|
|
animate('0.3s')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
trigger('2', [
|
|
|
|
state('2', style({
|
|
|
|
opacity: 1
|
|
|
|
})),
|
|
|
|
transition('* => *', [
|
|
|
|
animate('0.3s')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
trigger('3', [
|
|
|
|
state('3', style({
|
|
|
|
opacity: 1
|
|
|
|
})),
|
|
|
|
transition('* => *', [
|
|
|
|
animate('0.3s')
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]
|
2019-09-30 14:51:38 +02:00
|
|
|
})
|
|
|
|
export class HomeComponent {
|
|
|
|
public piwiksub: any;
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
public pageTitle = "OpenAIRE | Monitor";
|
2020-06-03 23:55:32 +02:00
|
|
|
public stakeholders: any[] = [];
|
2020-06-09 11:19:25 +02:00
|
|
|
public selected: Stakeholder = null;
|
2019-09-30 14:51:38 +02:00
|
|
|
public pageContents = null;
|
|
|
|
public divContents = null;
|
2019-12-03 12:10:05 +01:00
|
|
|
// Message variables
|
2019-09-30 14:51:38 +02:00
|
|
|
public status: number;
|
|
|
|
public loading: boolean = true;
|
|
|
|
public subscriberErrorMessage: string = "";
|
|
|
|
public errorCodes: ErrorCodes;
|
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
properties: EnvProperties;
|
|
|
|
public keyword: string = "";
|
2020-06-09 11:19:25 +02:00
|
|
|
public type: string = null;
|
2020-06-03 23:55:32 +02:00
|
|
|
|
|
|
|
public publicationsSize: any = null;
|
|
|
|
public datasetsSize: any = null;
|
2019-12-03 12:10:05 +01:00
|
|
|
public softwareSize: any = null;
|
|
|
|
public otherSize: any = null;
|
2020-06-03 23:55:32 +02:00
|
|
|
public fundersSize: any = null;
|
|
|
|
numberSubs = [];
|
|
|
|
public state = 1;
|
|
|
|
private timeouts: any[] = [];
|
|
|
|
public observer: IntersectionObserver;
|
|
|
|
public captains: boolean = false;
|
|
|
|
@ViewChild('ref') ref: ElementRef;
|
2020-06-09 11:19:25 +02:00
|
|
|
@ViewChild('AlertModal') modal;
|
2020-06-10 23:51:10 +02:00
|
|
|
public directLink: boolean = true;
|
|
|
|
private user: User;
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private _router: Router,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
|
|
|
private _piwikService: PiwikService,
|
2019-12-03 12:10:05 +01:00
|
|
|
private _stakeholderService: StakeholderService,
|
2020-06-09 11:19:25 +02:00
|
|
|
private localStorageService: LocalStorageService,
|
2020-06-10 23:51:10 +02:00
|
|
|
private userManagementService: UserManagementService,
|
2019-09-30 14:51:38 +02:00
|
|
|
private helper: HelperService,
|
2019-12-03 12:10:05 +01:00
|
|
|
private seoService: SEOService,
|
2020-06-03 23:55:32 +02:00
|
|
|
private _refineFieldResultsService: RefineFieldResultsService, private _searchResearchResultsService: SearchResearchResultsService) {
|
|
|
|
|
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
var description = "OpenAIRE - Monitor, Statistics, Search, Funder, EC, European Commision";
|
2019-09-30 14:51:38 +02:00
|
|
|
var title = "OpenAIRE - Monitor";
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
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);
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.status = this.errorCodes.LOADING;
|
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
public ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
2020-09-21 09:28:46 +02:00
|
|
|
var url = this.properties.domain + this.properties.baseLink + this._router.url;
|
2019-09-30 14:51:38 +02:00
|
|
|
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();
|
|
|
|
}
|
2019-12-03 12:10:05 +01:00
|
|
|
this.getNumbers();
|
2020-06-10 23:51:10 +02:00
|
|
|
this.getStakeholders();
|
2019-12-03 12:10:05 +01:00
|
|
|
// this.createGifs();
|
2019-09-30 14:51:38 +02:00
|
|
|
//this.getDivContents();
|
|
|
|
this.getPageContents();
|
2020-06-09 11:19:25 +02:00
|
|
|
this.localStorageService.get().subscribe(value => {
|
|
|
|
this.directLink = value;
|
2020-06-10 23:51:10 +02:00
|
|
|
});
|
|
|
|
this.userManagementService.getUserInfo().subscribe(user => {
|
|
|
|
this.user = user;
|
2020-06-09 11:19:25 +02:00
|
|
|
})
|
2019-09-30 14:51:38 +02:00
|
|
|
});
|
2020-06-10 11:12:17 +02:00
|
|
|
if(typeof document != "undefined") {
|
|
|
|
this.initAnimations();
|
|
|
|
this.startAnimation();
|
|
|
|
}
|
2019-09-30 14:51:38 +02:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
|
|
|
public initAnimations() {
|
|
|
|
this.observer = new IntersectionObserver(entries => {
|
|
|
|
if (entries[0].isIntersecting == true && this.captains == false) {
|
|
|
|
this.captains = true;
|
|
|
|
}
|
|
|
|
}, {threshold: [0]});
|
|
|
|
this.observer.observe(this.ref.nativeElement);
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:12:17 +02:00
|
|
|
public startAnimation(state = 1) {
|
2020-06-03 23:55:32 +02:00
|
|
|
this.clearTimeouts();
|
|
|
|
this.state = state;
|
|
|
|
this.timeouts.push(setTimeout(() => {
|
2020-06-09 11:19:25 +02:00
|
|
|
if (this.state < 3) {
|
2020-06-10 11:12:17 +02:00
|
|
|
this.startAnimation(this.state + 1);
|
2020-06-03 23:55:32 +02:00
|
|
|
} else {
|
2020-06-10 11:12:17 +02:00
|
|
|
this.startAnimation();
|
2020-06-03 23:55:32 +02:00
|
|
|
}
|
|
|
|
}, 6000));
|
|
|
|
}
|
|
|
|
|
|
|
|
private clearTimeouts() {
|
|
|
|
this.timeouts.forEach(timeout => {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
private getPageContents() {
|
2020-05-13 10:41:02 +02:00
|
|
|
this.helper.getPageHelpContents(this.properties, 'monitor', this._router.url).subscribe(contents => {
|
2019-09-30 14:51:38 +02:00
|
|
|
this.pageContents = contents;
|
|
|
|
})
|
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
private getDivContents() {
|
2020-05-13 10:41:02 +02:00
|
|
|
this.helper.getDivHelpContents(this.properties, 'monitor', this._router.url).subscribe(contents => {
|
2019-09-30 14:51:38 +02:00
|
|
|
this.divContents = contents;
|
|
|
|
})
|
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2020-06-09 11:19:25 +02:00
|
|
|
public get stakeholdersNumber(): number {
|
|
|
|
if(this.type === null) {
|
|
|
|
return this.stakeholders.length;
|
|
|
|
} else {
|
|
|
|
return this.stakeholders.filter(stakeholder => stakeholder.type === this.type).length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 23:55:32 +02:00
|
|
|
getNumbers() {
|
|
|
|
this.numberSubs.push(this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"], "project", this.properties).subscribe(
|
2019-12-03 12:10:05 +01:00
|
|
|
data => {
|
2020-06-03 23:55:32 +02:00
|
|
|
if (data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting 'funder' field results of projects", err);
|
|
|
|
}));
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
this.numberSubs.push(this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
|
2020-06-03 23:55:32 +02:00
|
|
|
data => {
|
|
|
|
if (data && data > 0) {
|
|
|
|
this.publicationsSize = NumberUtils.roundNumber(data);
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
},
|
|
|
|
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 > 0) {
|
|
|
|
this.datasetsSize = NumberUtils.roundNumber(data);
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting number of research data", err);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
this.numberSubs.push(this._searchResearchResultsService.numOfSearchResults("software", "", this.properties).subscribe(
|
2020-06-03 23:55:32 +02:00
|
|
|
data => {
|
|
|
|
if (data && data > 0) {
|
|
|
|
this.softwareSize = NumberUtils.roundNumber(data);
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError("Error getting number of software data", err);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
this.numberSubs.push(this._searchResearchResultsService.numOfSearchResults("other", "", this.properties).subscribe(
|
2020-06-03 23:55:32 +02:00
|
|
|
data => {
|
|
|
|
if (data && data > 0) {
|
|
|
|
this.otherSize = NumberUtils.roundNumber(data);
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError("Error getting number of software data", err);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2020-06-10 23:51:10 +02:00
|
|
|
public getStakeholders() {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.loading = true;
|
|
|
|
this.status = this.errorCodes.LOADING;
|
|
|
|
this.subscriberErrorMessage = "";
|
2020-06-03 23:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
this._stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL).subscribe(
|
|
|
|
stakeholders => {
|
|
|
|
if (!stakeholders || stakeholders.length == 0) {
|
|
|
|
this.status = this.errorCodes.NONE;
|
|
|
|
} else {
|
2020-06-10 23:51:10 +02:00
|
|
|
this.stakeholders = stakeholders.filter(stakeholder => stakeholder.isActive && (stakeholder.isPublic || this.isStakeholderManager()));
|
|
|
|
this.stakeholders.forEach((stakeholder, index, stakeholders) => {
|
2020-06-03 23:55:32 +02:00
|
|
|
this.setSizeOfStakeholder(index);
|
|
|
|
});
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.status = this.handleError("Error getting funders", error);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2020-06-10 23:51:10 +02:00
|
|
|
private isStakeholderManager() {
|
|
|
|
return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user);
|
|
|
|
}
|
|
|
|
|
2020-06-03 23:55:32 +02:00
|
|
|
private setSizeOfStakeholder(index) {
|
|
|
|
let mod = index % 9;
|
2020-06-09 11:19:25 +02:00
|
|
|
if (mod === 0 || mod === 4 || mod === 8) {
|
2020-06-03 23:55:32 +02:00
|
|
|
this.stakeholders[index].size = 'large';
|
2020-06-09 11:19:25 +02:00
|
|
|
} else if (mod === 1 || mod === 5 || mod === 6) {
|
2020-06-03 23:55:32 +02:00
|
|
|
this.stakeholders[index].size = 'small';
|
|
|
|
} else {
|
|
|
|
this.stakeholders[index].size = 'medium';
|
|
|
|
}
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2020-06-09 11:19:25 +02:00
|
|
|
public confirmModalOpen(result: Stakeholder) {
|
|
|
|
this.selected = result;
|
|
|
|
this.modal.cancelButton = true;
|
|
|
|
this.modal.okButton = true;
|
|
|
|
this.modal.alertTitle = 'You are going to visit ' + result.name + ' Monitor Dashboard';
|
|
|
|
this.modal.alertMessage = false;
|
|
|
|
this.modal.okButtonLeft = false;
|
|
|
|
this.modal.okButtonText = 'Yes';
|
|
|
|
this.modal.cancelButtonText = 'No';
|
|
|
|
this.modal.choice = true;
|
|
|
|
this.modal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public getStakeholderPageUrl(stakeholder: Stakeholder) {
|
2020-09-21 09:28:46 +02:00
|
|
|
return this.properties.domain + this.properties.baseLink + '/dashboard/' + stakeholder.alias;
|
2020-06-09 11:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public goToPage(data: any) {
|
|
|
|
if (data.value == true) {
|
|
|
|
let url = this.getStakeholderPageUrl(this.selected);
|
|
|
|
this.localStorageService.setCommunityDirectLink(data.choice);
|
|
|
|
window.open(url, '_blank');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
public quote(param: string): string {
|
|
|
|
return StringUtils.quote(param);
|
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
public ngOnDestroy() {
|
|
|
|
if (this.piwiksub) {
|
|
|
|
this.piwiksub.unsubscribe();
|
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
this.clearTimeouts();
|
2020-06-10 11:12:17 +02:00
|
|
|
if(this.observer) {
|
|
|
|
this.observer.disconnect();
|
|
|
|
}
|
2019-09-30 14:51:38 +02:00
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
private handleError(message: string, error): number {
|
|
|
|
var code = "";
|
|
|
|
if (!error.status) {
|
|
|
|
var error = error.json();
|
|
|
|
code = error.code;
|
|
|
|
} else {
|
|
|
|
code = error.status;
|
|
|
|
}
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
console.error("Communities (component): " + message, error);
|
2020-06-03 23:55:32 +02:00
|
|
|
|
2019-09-30 14:51:38 +02:00
|
|
|
return this.errorMessages.getErrorCode(code);
|
|
|
|
}
|
|
|
|
}
|