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: `
|
2018-06-06 12:09:56 +02:00
|
|
|
<div *ngIf="!shortView">
|
2018-06-08 13:21:42 +02:00
|
|
|
<errorMessages [status]="[status]" [type]="'metrics'" tab_error_class=true></errorMessages>
|
2018-07-19 12:47:21 +02:00
|
|
|
|
|
|
|
<div *ngIf="metrics && pageViews == 0 && metrics.totalViews == 0 && metrics.totalDownloads == 0" class="uk-alert uk-alert-primary">
|
|
|
|
No metrics available
|
|
|
|
</div>
|
|
|
|
<div *ngIf="metrics != undefined && (pageViews >0 || metrics.totalViews > 0|| metrics.totalDownloads >0)" class="uk-child-width-1-3@m uk-grid-small uk-grid-match uk-grid" uk-grid="">
|
2018-06-08 13:21:42 +02:00
|
|
|
<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">
|
|
|
|
<div class="uk-text-center">{{pageViews | number}}</div>
|
|
|
|
<div class="uk-text-center">views in OpenAIRE</div>
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2018-06-08 13:21:42 +02:00
|
|
|
<div class="metrics-views">
|
|
|
|
<div class="uk-tile uk-tile-muted uk-padding-small">
|
|
|
|
<div class="uk-text-center"> {{metrics.totalViews | number}}
|
|
|
|
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
|
|
|
|
( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
|
|
|
|
</span></div>
|
|
|
|
<div class="uk-text-center">views in local repository</div>
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2018-06-08 13:21:42 +02:00
|
|
|
<div class="metrics-downloads">
|
|
|
|
<div class="uk-tile uk-tile-primary uk-padding-small">
|
|
|
|
<div class="uk-text-center"> {{metrics.totalDownloads | number}}
|
|
|
|
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
|
|
|
|
( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE )
|
|
|
|
</span></div>
|
|
|
|
<div class="uk-text-center">downloads in local repository</div>
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
|
|
|
|
2018-06-08 13:21:42 +02:00
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-06-08 13:21:42 +02:00
|
|
|
<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"
|
2018-07-19 12:47:21 +02:00
|
|
|
class="uk-table uk-table-small uk-table-striped">
|
2018-06-08 13:21:42 +02:00
|
|
|
<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 getKeys(metrics.infos)">
|
|
|
|
<td class="uk-text-center">
|
|
|
|
<a href="{{metrics.infos.get(key).url}}">
|
|
|
|
{{metrics.infos.get(key).name}}
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
<td class="uk-text-center">
|
|
|
|
{{metrics.infos.get(key).numOfViews | number}}
|
|
|
|
<span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
|
|
|
|
( {{metrics.infos.get(key).openaireViews | number}} from OpenAIRE )
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td class="uk-text-center">
|
|
|
|
{{metrics.infos.get(key).numOfDownloads | number}}
|
|
|
|
<span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
|
|
|
|
( {{metrics.infos.get(key).openaireDownloads | number}} from OpenAIRE )
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2018-06-06 12:09:56 +02:00
|
|
|
</div>
|
2018-07-19 12:47:21 +02:00
|
|
|
<div *ngIf="shortView && metrics && (metrics.pageViews >0 || metrics.totalViews > 0|| metrics.totalDownloads >0)">
|
2018-06-06 12:09:56 +02:00
|
|
|
<dl *ngIf="metrics" class="uk-description-list-line">
|
2018-07-19 12:47:21 +02:00
|
|
|
<dt class="sideInfoTitle">Metrics</dt>
|
2018-06-06 12:09:56 +02:00
|
|
|
<dd class="line" >
|
|
|
|
{{metrics.pageViews | number}} views in OpenAIRE
|
|
|
|
</dd>
|
|
|
|
<dd class="line">
|
|
|
|
{{metrics.totalViews | number}}
|
|
|
|
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
|
|
|
|
( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
|
|
|
|
</span>
|
|
|
|
views in local repository
|
|
|
|
</dd>
|
|
|
|
<dd class="line">
|
|
|
|
{{metrics.totalDownloads | number}}
|
|
|
|
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
|
|
|
|
( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE )
|
|
|
|
</span> downloads in local repository
|
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
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;
|
2018-06-06 12:09:56 +02:00
|
|
|
@Input() shortView:boolean = false;
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-06-08 13:21:42 +02:00
|
|
|
|
|
|
|
public getKeys( map) {
|
|
|
|
return Array.from(map.keys());
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|