openaire-library/landingPages/landing-utils/metrics.component.ts

227 lines
12 KiB
TypeScript

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/Subscription';
import{EnvProperties} from '../../utils/properties/env-properties';
@Component({
selector: 'metrics',
template: `
<!--div *ngIf="i>0 && tab.content=='metricsTab' && metrics != undefined" class="uk-panel uk-padding uk-background-muted"-->
<!--/div-->
<!--dl *ngIf="metrics != undefined"
class="uk-description-list-horizontal uk-panel uk-padding uk-background-muted">
<dt *ngIf="type=='results'">Total Downloads: </dt>
<dt *ngIf="type!='results'" class="uk-text-break">
Total <span [innerHTML]="name"></span> Publication Downloads:
</dt>
<dd>{{metrics.totalDownloads}}</dd>
<dt>Total Views: </dt>
<dd>{{metrics.totalViews}}</dd>
</dl-->
<!--div *ngIf="metrics == undefined" class="uk-alert uk-alert-warning">
Metrics are currently unavailable
</div-->
<!--div *ngIf="status == errorCodes.LOADING" class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert"><img class="loading-gif uk-align-center" ></div>
<div *ngIf="status == errorCodes.NONE" class="uk-alert uk-alert-primary" role="alert">No Results found</div>
<div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning" role="alert">An Error Occured</div>
<div *ngIf="status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger" role="alert">Service temprorarily unavailable. Please try again later.</div>
<div *ngIf="status == errorCodes.NOT_FOUND" class="uk-alert uk-alert-danger" role="alert">No metrics found</div-->
<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">
<!--div class="uk-clearfix">
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
title='<div class= "uk-margin uk-padding-small">
<p>Info about the value....</p>
</div>'><span class="uk-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg>
</span>
</div>
</div-->
<div class="uk-text-center">{{pageViews}}</div>
<div class="uk-text-center">views in OpenAIRE</div>
<!--div *ngIf="entityType!='results'" class="uk-text-center">Research results views in OpenAIRE</div-->
<!--div class="uk-margin-top uk-article-meta">
<div *ngIf="entityType != 'results'">Research results page views in OpenAIRE</div>
<div *ngIf="entityType == 'results'">{{entity}} page views in OpenAIRE</div>
</div-->
</div>
</div>
<div class="metrics-views">
<div class="uk-tile uk-tile-muted uk-padding-small">
<!--div class="uk-clearfix">
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
title='<div class= "uk-margin uk-padding-small">
<p>Info about the value....</p>
</div>'><span class="uk-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg>
</span>
</div>
</div-->
<div class="uk-text-center"> {{metrics.totalViews}}
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
( {{metrics.totalOpenaireViews}} from OpenAIRE )
</span></div>
<div class="uk-text-center">views in local repository</div>
<!--div *ngIf="entityType!='results'" class="uk-text-center"> research results views in local repository</div-->
<!--div *ngIf="type!='results'" class="uk-text-center"> Total <span [innerHTML]="name"></span> Research Results Views</div-->
<!--div class="uk-margin-top uk-article-meta">
<div *ngIf="entityType == 'projects'">Research results page views in Repositories</div>
<div *ngIf="entityType == 'datasources'">Research results page views in Repository</div>
<div *ngIf="entityType == 'results'">{{entity}} page views in Repositories</div>
<div *ngIf="entityType!='datasources' && metrics.totalOpenaireViews > 0">
Of the {{metrics.totalViews}} views, repositories accessed {{metrics.totalOpenaireViews}} time(s) from OpenAIRE
</div>
<div *ngIf="entityType=='datasources' && metrics.totalOpenaireViews > 0">
Of the {{metrics.totalViews}} views, repository accessed {{metrics.totalOpenaireViews}} time(s) from OpenAIRE
</div>
</div-->
</div>
</div>
<div class="metrics-downloads">
<div class="uk-tile uk-tile-primary uk-padding-small">
<!--div class="uk-clearfix">
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
title='<div class= "uk-margin uk-padding-small">
<p>Info about the value....</p>
</div>'><span class="uk-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg>
</span>
</div>
</div-->
<div class="uk-text-center"> {{metrics.totalDownloads}}
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
( {{metrics.totalOpenaireDownloads}} from OpenAIRE )
</span></div>
<div class="uk-text-center">downloads in local repository</div>
<!--div *ngIf="entityType!='results'" class="uk-text-center">research results downloads in local repository</div-->
<!--div *ngIf="type!='results'" class="uk-text-center">Total <span [innerHTML]="name"></span> Research Results Downloads</div-->
<!--div class="uk-margin-top uk-article-meta">
<div *ngIf="entityType == 'projects'">Research results page downloads in Repositories</div>
<div *ngIf="entityType == 'datasources'">Research results page downloads in Repository</div>
<div *ngIf="entityType == 'results'">{{entity}} page downloads in Repositories</div>
<div *ngIf="entityType!='datasources' && metrics.totalOpenaireDownloads > 0">
Of the {{metrics.totalDownloads}} downloads, repositories accessed {{metrics.totalOpenaireDownloads}} time(s) from OpenAIRE
</div>
<div *ngIf="entityType=='datasources' && metrics.totalOpenaireDownloads > 0">
Of the {{metrics.totalDownloads}} downloads, repository accessed {{metrics.totalOpenaireDownloads}} time(s) from OpenAIRE
</div>
</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">
{{metrics.infos.get(key).numOfViews}}
<span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
( {{metrics.infos.get(key).openaireViews}} from OpenAIRE )
</span>
</td>
<td class="uk-text-center">
{{metrics.infos.get(key).numOfDownloads}}
<span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
( {{metrics.infos.get(key).openaireDownloads}} from OpenAIRE )
</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;
@Input() properties:EnvProperties;
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
});
}
);
}
}