2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
|
|
|
import {Metrics} from '../../utils/entities/metrics';
|
|
|
|
import {MetricsService } from '../../services/metrics.service';
|
2018-02-15 11:36:12 +01:00
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
import { Subscription } from 'rxjs/Subscription';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'metrics',
|
|
|
|
template: `
|
|
|
|
<errorMessages [status]="[status]" [type]="'metrics'"></errorMessages>
|
|
|
|
<div *ngIf="metrics != undefined" class="uk-child-width-1-3@m uk-grid-small uk-grid-match uk-grid" uk-grid="">
|
|
|
|
<div *ngIf="entityType == 'projects'" class="uk-width-1-1 uk-text-center uk-text-meta uk-margin">Project metrics are derived from aggregating individual research results metrics.</div>
|
|
|
|
<div class="metrics-openaire uk-first-column">
|
|
|
|
<div class="uk-tile uk-tile-default uk-padding-small">
|
2018-05-18 14:47:26 +02:00
|
|
|
<div class="uk-text-center">{{pageViews | number}}</div>
|
|
|
|
<div class="uk-text-center">views in OpenAIRE</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="metrics-views">
|
|
|
|
<div class="uk-tile uk-tile-muted uk-padding-small">
|
2018-05-18 14:47:26 +02:00
|
|
|
<div class="uk-text-center"> {{metrics.totalViews | number}}
|
2017-12-19 13:53:46 +01:00
|
|
|
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
|
2018-05-18 14:47:26 +02:00
|
|
|
( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
|
2017-12-19 13:53:46 +01:00
|
|
|
</span></div>
|
|
|
|
<div class="uk-text-center">views in local repository</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="metrics-downloads">
|
|
|
|
<div class="uk-tile uk-tile-primary uk-padding-small">
|
2018-05-18 14:47:26 +02:00
|
|
|
<div class="uk-text-center"> {{metrics.totalDownloads | number}}
|
2017-12-19 13:53:46 +01:00
|
|
|
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
|
2018-05-18 14:47:26 +02:00
|
|
|
( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE )
|
2017-12-19 13:53:46 +01:00
|
|
|
</span></div>
|
|
|
|
<div class="uk-text-center">downloads in local repository</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<p *ngIf="metrics != undefined && metrics.infos.size > 0" >The information is available from the following content providers: </p>
|
|
|
|
<table *ngIf="metrics != undefined && metrics.infos.size > 0"
|
|
|
|
class="uk-table uk-table-striped">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th class="uk-text-center uk-text-bold">From</th>
|
|
|
|
<th class="uk-text-center uk-text-bold">Number Of Views</th>
|
|
|
|
<th class="uk-text-center uk-text-bold">Number Of Downloads</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr *ngFor="let key of metrics.infos.keys()">
|
|
|
|
<td class="uk-text-center">
|
|
|
|
<a href="{{metrics.infos.get(key).url}}">
|
|
|
|
{{metrics.infos.get(key).name}}
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
<td class="uk-text-center">
|
2018-05-18 14:47:26 +02:00
|
|
|
{{metrics.infos.get(key).numOfViews | number}}
|
2017-12-19 13:53:46 +01:00
|
|
|
<span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
|
2018-05-18 14:47:26 +02:00
|
|
|
( {{metrics.infos.get(key).openaireViews | number}} from OpenAIRE )
|
2017-12-19 13:53:46 +01:00
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td class="uk-text-center">
|
2018-05-18 14:47:26 +02:00
|
|
|
{{metrics.infos.get(key).numOfDownloads | number}}
|
2017-12-19 13:53:46 +01:00
|
|
|
<span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
|
2018-05-18 14:47:26 +02:00
|
|
|
( {{metrics.infos.get(key).openaireDownloads | number}} from OpenAIRE )
|
2017-12-19 13:53:46 +01:00
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class MetricsComponent {
|
|
|
|
@Output() metricsResults = new EventEmitter();
|
|
|
|
@Input() id: string;
|
|
|
|
@Input() entityType: string;
|
|
|
|
@Input() entity: string;
|
|
|
|
//@Input() name: string = "";
|
|
|
|
@Input() pageViews: number = 0;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() properties:EnvProperties;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
//}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
this.sub = this._metricsService.getMetrics(this.id, this.entityType, this.properties).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|