2020-05-19 16:12:10 +02:00
|
|
|
import {Component, Input, Output, EventEmitter, ChangeDetectorRef} from '@angular/core';
|
2020-05-05 12:37:36 +02:00
|
|
|
import {Metrics} from '../../../utils/entities/metrics';
|
|
|
|
import {MetricsService} from '../../../services/metrics.service';
|
|
|
|
import {ErrorCodes} from '../../../utils/properties/errorCodes';
|
|
|
|
|
2021-09-08 14:21:30 +02:00
|
|
|
import {Subscription, zip} from 'rxjs';
|
2020-05-05 12:37:36 +02:00
|
|
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
|
|
|
import {animate, state, style, transition, trigger} from "@angular/animations";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'metrics',
|
|
|
|
styleUrls: ['metrics.component.css'],
|
|
|
|
template: `
|
|
|
|
<div *ngIf="metrics && (pageViews >0 || metrics.totalViews > 0|| metrics.totalDownloads >0)" class="metrics"
|
|
|
|
click-outside-or-esc (clickOutside)="close($event)"
|
|
|
|
id="metrics" targetId="metrics">
|
|
|
|
<div class="m-badge clickable" (click)="toggle($event)">
|
2021-08-10 12:46:33 +02:00
|
|
|
<img src="assets/common-assets/logo-small-usage-counts.png" loading="lazy" alt="usage counts">
|
2020-05-05 12:37:36 +02:00
|
|
|
<div class="number">{{total | number}}</div>
|
|
|
|
</div>
|
|
|
|
<div class="widget" [@widget]="state.toString()">
|
|
|
|
<div class="body">
|
|
|
|
<div [@body]="state.toString()">
|
|
|
|
<div *ngIf="entityType == 'projects'" class="uk-margin-bottom">
|
|
|
|
<i class="uk-text-center">Project metrics
|
|
|
|
are derived from aggregating individual research results metrics.
|
|
|
|
</i>
|
|
|
|
</div>
|
2021-04-09 17:39:42 +02:00
|
|
|
<div class="uk-child-width-1-3@m uk-grid-small uk-grid-divider uk-grid-match" uk-grid>
|
2020-05-05 12:37:36 +02:00
|
|
|
<div class="uk-text-center uk-first-column">
|
|
|
|
<div class="number">{{metrics.totalDownloads | number}}</div>
|
|
|
|
<div>Downloads</div>
|
|
|
|
</div>
|
2021-04-09 17:39:42 +02:00
|
|
|
<div class="uk-text-center">
|
2020-05-05 12:37:36 +02:00
|
|
|
<div class="number">{{pageViews | number}}</div>
|
|
|
|
<div>OpenAIRE views</div>
|
2021-04-09 17:39:42 +02:00
|
|
|
</div>
|
2020-05-05 12:37:36 +02:00
|
|
|
<div class="uk-text-center">
|
|
|
|
<div class="number">{{metrics.totalViews | number}}</div>
|
|
|
|
<div>Total views</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="(metrics.totalViews > 0 && viewsFrameUrl) || (metrics.totalDownloads > 0 && downloadsFrameUrl)"
|
|
|
|
[@charts]="state.toString()"
|
|
|
|
class="charts uk-visible-toggle" tabindex="-1" uk-slider>
|
2020-05-19 16:12:10 +02:00
|
|
|
<ul class="uk-slider-items uk-child-width-1-1">
|
2020-10-22 14:10:17 +02:00
|
|
|
<li *ngIf="metrics && metrics.infos.size > 0" class="uk-overflow-auto" style="height: 200px">
|
|
|
|
<table
|
|
|
|
class="uk-table uk-table-small uk-table-striped">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th class="uk-text-center uk-text-bold">From</th>
|
|
|
|
<th class="uk-text-center uk-text-bold">Views</th>
|
|
|
|
<th class="uk-text-center uk-text-bold">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}}
|
2021-04-05 12:49:47 +02:00
|
|
|
<!-- <span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
|
2020-10-22 14:10:17 +02:00
|
|
|
( {{metrics.infos.get(key).openaireViews | number}} from OpenAIRE )
|
2021-04-05 12:49:47 +02:00
|
|
|
</span>-->
|
2020-10-22 14:10:17 +02:00
|
|
|
</td>
|
|
|
|
<td class="uk-text-center">
|
|
|
|
{{metrics.infos.get(key).numOfDownloads | number}}
|
2021-04-05 12:49:47 +02:00
|
|
|
<!--<span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
|
2020-10-22 14:10:17 +02:00
|
|
|
( {{metrics.infos.get(key).openaireDownloads | number}} from OpenAIRE )
|
2021-04-05 12:49:47 +02:00
|
|
|
</span>-->
|
2020-10-22 14:10:17 +02:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</li>
|
2021-04-06 10:19:54 +02:00
|
|
|
<!-- remove check for datasources when with the new charts -->
|
2021-09-08 14:21:30 +02:00
|
|
|
<li #element>
|
2020-06-10 13:05:59 +02:00
|
|
|
<i-frame *ngIf="metricsClicked && metrics.totalViews > 0 && viewsFrameUrl"
|
|
|
|
[height]="200"
|
2021-09-08 14:21:30 +02:00
|
|
|
[url]=viewsFrameUrl [addClass]="false">
|
2020-05-05 12:37:36 +02:00
|
|
|
</i-frame>
|
|
|
|
</li>
|
2021-09-08 14:21:30 +02:00
|
|
|
<li #element>
|
2020-06-10 13:05:59 +02:00
|
|
|
<i-frame *ngIf="metricsClicked && metrics.totalDownloads > 0 && downloadsFrameUrl"
|
|
|
|
[height]="200"
|
2021-09-08 14:21:30 +02:00
|
|
|
[url]=downloadsFrameUrl [addClass]="false">
|
2020-05-05 12:37:36 +02:00
|
|
|
</i-frame>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2020-10-22 14:10:17 +02:00
|
|
|
<div class="uk-text-right uk-margin-small-top">
|
2020-05-05 12:37:36 +02:00
|
|
|
<a href="#" uk-slidenav-previous uk-slider-item="previous"></a>
|
2022-04-12 13:21:54 +02:00
|
|
|
<a href="#" class="uk-margin-small-left" uk-slidenav-next uk-slider-item="next"></a>
|
2020-05-05 12:37:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="footer uk-flex uk-flex-middle" [@footer]="state.toString()">
|
|
|
|
<span>Powered by</span>
|
2021-01-22 16:28:08 +01:00
|
|
|
<a href="https://usagecounts.openaire.eu" target="_blank">
|
2021-08-10 12:46:33 +02:00
|
|
|
<img width="120" src="assets/common-assets/logo-large-usage-counts.png" loading="lazy" alt="usage counts">
|
2021-01-22 16:28:08 +01:00
|
|
|
</a>
|
2020-05-05 12:37:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
animations: [
|
|
|
|
trigger('widget', [
|
|
|
|
state('-1', style({
|
|
|
|
width: '150px',
|
|
|
|
opacity: 0,
|
|
|
|
height: '60px',
|
|
|
|
})),
|
|
|
|
state('0', style({
|
|
|
|
width: '150px',
|
|
|
|
opacity: 0,
|
|
|
|
height: '60px',
|
|
|
|
"margin-top": '-25px'
|
|
|
|
})),
|
|
|
|
state('1', style({
|
|
|
|
width: '150px',
|
|
|
|
opacity: 1,
|
|
|
|
height: '60px',
|
|
|
|
})),
|
|
|
|
state('2', style({
|
|
|
|
width: '350px',
|
|
|
|
height: 'auto',
|
|
|
|
})),
|
|
|
|
state('3', style({
|
|
|
|
width: '350px',
|
|
|
|
height: 'auto',
|
|
|
|
})),
|
|
|
|
state('4', style({
|
|
|
|
width: '350px',
|
|
|
|
height: 'auto',
|
|
|
|
})),
|
|
|
|
transition('0 => 1', [
|
|
|
|
animate('300ms ease-out')
|
|
|
|
]),
|
|
|
|
transition('1 => 2', [
|
|
|
|
animate('400ms cubic-bezier(.18,.89,.56,1)')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
trigger('body', [
|
|
|
|
state('2', style({
|
|
|
|
opacity: 1,
|
|
|
|
height: 'auto',
|
|
|
|
})),
|
|
|
|
state('3', style({
|
|
|
|
opacity: 1,
|
|
|
|
height: 'auto'
|
|
|
|
})),
|
|
|
|
state('4', style({
|
|
|
|
opacity: 1,
|
|
|
|
height: 'auto'
|
|
|
|
})),
|
|
|
|
transition('* => 2', [
|
|
|
|
animate('400ms cubic-bezier(.18,.89,.56,1)')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
trigger('charts', [
|
|
|
|
state('3', style({
|
|
|
|
opacity: 1
|
|
|
|
})),
|
|
|
|
state('4', style({
|
|
|
|
opacity: 1
|
|
|
|
})),
|
|
|
|
transition('* => 3', [
|
|
|
|
animate('800ms ease-out')
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
trigger('footer', [
|
|
|
|
state('4', style({
|
|
|
|
transform: 'translateY(0)'
|
|
|
|
})),
|
|
|
|
transition('3 => 4', [
|
|
|
|
animate('800ms ease-out')
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
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;
|
|
|
|
@Input() open = false;
|
|
|
|
@Input() viewsFrameUrl: string;
|
|
|
|
@Input() downloadsFrameUrl: string;
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
public metrics: Metrics;
|
|
|
|
public errorCodes: ErrorCodes;
|
|
|
|
private sub: Subscription;
|
|
|
|
private timeouts: any[] = [];
|
2020-06-10 13:05:59 +02:00
|
|
|
|
2022-03-15 22:31:10 +01:00
|
|
|
public metricsClicked: boolean = false;
|
2020-06-10 13:05:59 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
public status: number;
|
|
|
|
public state: number = -1;
|
2020-05-19 16:12:10 +02:00
|
|
|
constructor(private metricsService: MetricsService, private cdr: ChangeDetectorRef) {
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.errorCodes = new ErrorCodes();
|
2020-06-10 13:05:59 +02:00
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
this.status = this.errorCodes.LOADING;
|
|
|
|
this.getMetrics();
|
|
|
|
}
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
ngOnDestroy() {
|
2020-06-10 13:05:59 +02:00
|
|
|
if(this.sub) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
public get total(): number {
|
2021-04-09 17:39:42 +02:00
|
|
|
return +this.pageViews + +this.metrics.totalViews + +this.metrics.totalDownloads;
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
private getMetrics() {
|
2021-09-08 14:21:30 +02:00
|
|
|
//queries from old API - replaced with queries to the stats tool
|
|
|
|
/* this.sub = this.metricsService.getMetrics(this.id, this.entityType, this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
this.metrics = data;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
this.metricsResults.emit({
|
|
|
|
totalViews: this.metrics.totalViews,
|
|
|
|
totalDownloads: this.metrics.totalDownloads,
|
|
|
|
pageViews: this.metrics.pageViews
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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
|
|
|
|
});
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
);*/
|
|
|
|
let obs;
|
|
|
|
if (this.entityType == "results") {
|
|
|
|
obs = zip(this.metricsService.getMetricsNumber(this.id, "usagestats.results.views", this.properties),
|
|
|
|
this.metricsService.getMetricsNumber(this.id, "usagestats.results.downloads", this.properties),
|
|
|
|
this.metricsService.getMetricsNumber(this.id, "usagestats.results.views.openaire", this.properties),
|
|
|
|
this.metricsService.getMetricsNumbersByRepository(this.id, "usagestats.results.viewsdownloads.repository", this.properties)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else if (this.entityType == "projects") {
|
|
|
|
obs = zip(this.metricsService.getMetricsNumber(this.id, "usagestats.projects.views", this.properties),
|
|
|
|
this.metricsService.getMetricsNumber(this.id, "usagestats.projects.downloads", this.properties),
|
|
|
|
this.metricsService.getMetricsNumber(this.id, "usagestats.projects.views.openaire", this.properties));
|
|
|
|
|
|
|
|
} else if (this.entityType == "datasources") {
|
|
|
|
obs = zip(this.metricsService.getMetricsNumber(this.id, "usagestats.views.repository.local", this.properties),
|
|
|
|
this.metricsService.getMetricsNumber(this.id, "usagestats.downloads.repository.local", this.properties),
|
|
|
|
this.metricsService.getMetricsNumber(this.id, "usagestats.views.openaire", this.properties),
|
|
|
|
// this.metricsService.getMetricsNumber(this.id, "usagestats.downloads.repository.openaire", this.properties)
|
|
|
|
);
|
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
|
|
|
this.sub = obs.subscribe(
|
|
|
|
data => {
|
|
|
|
this.metrics = new Metrics();
|
|
|
|
this.metrics.infos = new Map<string, { "name": string, "url": string, "numOfDownloads": string, "numOfViews": string, "openaireDownloads": string, "openaireViews": string }>();
|
|
|
|
this.metrics.totalViews = data[0] ? data[0] : 0;
|
|
|
|
this.metrics.totalDownloads = data[1] ? data[1] : 0;
|
|
|
|
this.metrics.pageViews = data[2] ? data[2] : 0;
|
|
|
|
this.metrics.infos = data[3] ? data[3] : 0;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
this.metricsResults.emit({
|
|
|
|
totalViews: this.metrics.totalViews,
|
|
|
|
totalDownloads: this.metrics.totalDownloads,
|
|
|
|
pageViews: this.metrics.pageViews
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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,
|
2022-04-04 11:14:54 +02:00
|
|
|
totalDownloads: 0,
|
|
|
|
pageViews: 0
|
2021-09-08 14:21:30 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
public close(event) {
|
|
|
|
if(event.value && this.state !== -1) {
|
|
|
|
this.timeouts.forEach(timeout => {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
});
|
|
|
|
this.state = -1;
|
|
|
|
this.timeouts = [];
|
|
|
|
}
|
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
public toggle(event) {
|
2020-06-10 13:05:59 +02:00
|
|
|
this.metricsClicked = true;
|
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
event.stopPropagation();
|
|
|
|
if(this.state !== -1) {
|
|
|
|
this.timeouts.forEach(timeout => {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
});
|
|
|
|
this.state = -1;
|
|
|
|
this.timeouts = [];
|
|
|
|
} else {
|
|
|
|
this.state++;
|
|
|
|
this.timeouts.push(setTimeout(() => {
|
|
|
|
this.state++;
|
|
|
|
this.timeouts.push(setTimeout(() => {
|
|
|
|
this.state++;
|
|
|
|
this.timeouts.push(setTimeout(() => {
|
|
|
|
this.state++;
|
|
|
|
this.timeouts.push(setTimeout(() => {
|
|
|
|
this.state++;
|
|
|
|
}, 400));
|
|
|
|
}, 800));
|
|
|
|
}, 300));
|
|
|
|
}, 100));
|
|
|
|
}
|
2020-05-19 16:12:10 +02:00
|
|
|
this.cdr.detectChanges();
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2020-05-05 12:37:36 +02:00
|
|
|
public getKeys(map) {
|
|
|
|
return Array.from(map.keys());
|
|
|
|
}
|
|
|
|
}
|