import {Component, Input, Output, EventEmitter} from '@angular/core'; import {Metrics} from '../../utils/entities/metrics'; import {MetricsService } from '../../services/metrics.service'; import {ErrorCodes} from '../../utils/properties/errorCodes'; import { Subscription } from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; @Component({ selector: 'metrics', template: `
No metrics available
Project metrics are derived from aggregating individual research results metrics.
{{pageViews | number}}
views in OpenAIRE
{{metrics.totalViews | number}} ( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
views in local repository
{{metrics.totalDownloads | number}} ( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE )
downloads in local repository

The information is available from the following content providers:

From Number Of Views Number Of Downloads
{{metrics.infos.get(key).name}} {{metrics.infos.get(key).numOfViews | number}} ( {{metrics.infos.get(key).openaireViews | number}} from OpenAIRE ) {{metrics.infos.get(key).numOfDownloads | number}} ( {{metrics.infos.get(key).openaireDownloads | number}} from OpenAIRE )
Metrics
{{metrics.pageViews | number}} views in OpenAIRE
{{metrics.totalViews | number}} ( {{metrics.totalOpenaireViews | number}} from OpenAIRE ) views in local repository
{{metrics.totalDownloads | number}} ( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE ) downloads in local repository
` }) export class MetricsComponent { @Output() metricsResults = new EventEmitter(); @Input() id: string; @Input() entityType: string; @Input() entity: string; //@Input() name: string = ""; @Input() pageViews: number = 0; @Input() properties:EnvProperties; @Input() shortView:boolean = false; public metrics: Metrics; public errorCodes:ErrorCodes; private sub: Subscription; public status: number; constructor (private _metricsService: MetricsService) {} ngOnInit() { this.errorCodes = new ErrorCodes(); this.status = this.errorCodes.LOADING; this.getMetrics(); } ngOnDestroy() { this.sub.unsubscribe(); } private getMetrics() { //if(this.id == undefined || this.id == "") { // console.log("supplied id in metrics is not acceptable"); //} //if(this.type == undefined || this.type == "") { // console.log("supplied id in metrics is not acceptable"); //} this.sub = this._metricsService.getMetrics(this.id, this.entityType, this.properties).subscribe( data => { this.metrics = data; this.status = this.errorCodes.DONE; this.metricsResults.emit({ totalViews: this.metrics.totalViews, totalDownloads: this.metrics.totalDownloads, pageViews: this.metrics.pageViews }); }, err => { console.log(err); if(err.status == '404') { this.status = this.errorCodes.NOT_FOUND; } else if(err.status == '500') { this.status = this.errorCodes.ERROR; } else { this.status = this.errorCodes.NOT_AVAILABLE; } this.metricsResults.emit({ totalViews: 0, totalDownloads: 0 }); } ); } public getKeys( map) { return Array.from(map.keys()); } }