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
0 || metrics.totalViews > 0|| metrics.totalDownloads >0)" class="uk-child-width-1-3@m uk-grid-small uk-grid-match uk-grid" uk-grid="">
Project metrics are derived from aggregating individual research results metrics.
{{pageViews | number}}
views in OpenAIRE
{{metrics.totalViews | number}}
0 && metrics.totalOpenaireViews > 0">
( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
views in local repository
{{metrics.totalDownloads | number}}
0 && metrics.totalOpenaireDownloads > 0">
( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE )
downloads in local repository
0" >The information is available from the following content providers:
0"
class="uk-table uk-table-small uk-table-striped">
From |
Number Of Views |
Number Of Downloads |
{{metrics.infos.get(key).name}}
|
{{metrics.infos.get(key).numOfViews | number}}
0 && metrics.infos.get(key).openaireViews > 0">
( {{metrics.infos.get(key).openaireViews | number}} from OpenAIRE )
|
{{metrics.infos.get(key).numOfDownloads | number}}
0 && metrics.infos.get(key).openaireDownloads > 0">
( {{metrics.infos.get(key).openaireDownloads | number}} from OpenAIRE )
|
0 || metrics.totalViews > 0|| metrics.totalDownloads >0)">
- Metrics
-
{{metrics.pageViews | number}} views in OpenAIRE
-
{{metrics.totalViews | number}}
0 && metrics.totalOpenaireViews > 0">
( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
views in local repository
-
{{metrics.totalDownloads | number}}
0 && metrics.totalOpenaireDownloads > 0">
( {{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());
}
}