1
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
2
|
import {Metrics} from '../utils/entities/metrics';
|
3
|
import {MetricsService } from '../services/metrics.service';
|
4
|
import {ErrorCodes} from '../utils/properties/openaireProperties';
|
5
|
|
6
|
@Component({
|
7
|
selector: 'metrics',
|
8
|
template: `
|
9
|
<!--div *ngIf="i>0 && tab.content=='metricsTab' && metrics != undefined" class="uk-panel uk-padding uk-background-muted"-->
|
10
|
<!--/div-->
|
11
|
|
12
|
<!--dl *ngIf="metrics != undefined"
|
13
|
class="uk-description-list-horizontal uk-panel uk-padding uk-background-muted">
|
14
|
<dt *ngIf="type=='results'">Total Downloads: </dt>
|
15
|
<dt *ngIf="type!='results'" class="uk-text-break">
|
16
|
Total <span [innerHTML]="name"></span> Publication Downloads:
|
17
|
</dt>
|
18
|
<dd>{{metrics.totalDownloads}}</dd>
|
19
|
<dt>Total Views: </dt>
|
20
|
<dd>{{metrics.totalViews}}</dd>
|
21
|
</dl-->
|
22
|
|
23
|
<!--div *ngIf="metrics == undefined" class="uk-alert uk-alert-warning">
|
24
|
Metrics are currently unavailable
|
25
|
</div-->
|
26
|
|
27
|
<div *ngIf="status == errorCodes.LOADING" class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="Loading"></div>
|
28
|
<div *ngIf="status == errorCodes.NONE" class="uk-alert uk-alert-primary" role="alert">No Results found</div>
|
29
|
<div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning" role="alert">An Error Occured</div>
|
30
|
<div *ngIf="status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger" role="alert">Service not available</div>
|
31
|
<div *ngIf="metrics != undefined" class="uk-child-width-1-3@m uk-grid-small uk-grid-match uk-grid" uk-grid="">
|
32
|
<div class="uk-first-column">
|
33
|
<div class="uk-card uk-card-default uk-padding-small">
|
34
|
<!--div class="uk-clearfix">
|
35
|
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
|
36
|
title='<div class= "uk-margin uk-padding-small">
|
37
|
<p>Info about the value....</p>
|
38
|
</div>'><span class="uk-icon">
|
39
|
<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>
|
40
|
</span>
|
41
|
</div>
|
42
|
</div-->
|
43
|
<div class="uk-text-center">Page Views</div>
|
44
|
<div class="uk-text-center">{{pageViews}}</div>
|
45
|
</div>
|
46
|
</div>
|
47
|
<div>
|
48
|
<div class="uk-card uk-card-default uk-padding-small">
|
49
|
<!--div class="uk-clearfix">
|
50
|
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
|
51
|
title='<div class= "uk-margin uk-padding-small">
|
52
|
<p>Info about the value....</p>
|
53
|
</div>'><span class="uk-icon">
|
54
|
<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>
|
55
|
</span>
|
56
|
</div>
|
57
|
</div-->
|
58
|
<div *ngIf="type=='results'" class="uk-text-center">Total views</div>
|
59
|
<div *ngIf="type!='results'" class="uk-text-center"> Total <span [innerHTML]="name"></span> Publication Views</div>
|
60
|
|
61
|
<div class="uk-text-center"> {{metrics.totalViews}}
|
62
|
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
|
63
|
( {{metrics.totalOpenaireViews}} from OpenAIRE )
|
64
|
</span></div>
|
65
|
|
66
|
</div>
|
67
|
</div>
|
68
|
<div>
|
69
|
<div class="uk-card uk-card-default uk-padding-small">
|
70
|
<!--div class="uk-clearfix">
|
71
|
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
|
72
|
title='<div class= "uk-margin uk-padding-small">
|
73
|
<p>Info about the value....</p>
|
74
|
</div>'><span class="uk-icon">
|
75
|
<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>
|
76
|
</span>
|
77
|
</div>
|
78
|
</div-->
|
79
|
<div *ngIf="type=='results'" class="uk-text-center">Total Downloads</div>
|
80
|
<div *ngIf="type!='results'" class="uk-text-center">Total <span [innerHTML]="name"></span> Publication Downloads</div>
|
81
|
|
82
|
<div class="uk-text-center"> {{metrics.totalDownloads}}
|
83
|
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
|
84
|
( {{metrics.totalOpenaireDownloads}} from OpenAIRE )
|
85
|
</span></div>
|
86
|
|
87
|
</div>
|
88
|
</div>
|
89
|
|
90
|
</div>
|
91
|
|
92
|
<p *ngIf="metrics != undefined && metrics.infos.size > 0" >The information is available from the following content providers: </p>
|
93
|
<table *ngIf="metrics != undefined && metrics.infos.size > 0"
|
94
|
class="uk-table uk-table-striped">
|
95
|
<thead>
|
96
|
<tr>
|
97
|
<th class="uk-text-center uk-text-bold">From</th>
|
98
|
<th class="uk-text-center uk-text-bold">Number Of Views</th>
|
99
|
<th class="uk-text-center uk-text-bold">Number Of Downloads</th>
|
100
|
</tr>
|
101
|
</thead>
|
102
|
<tbody>
|
103
|
<tr *ngFor="let key of metrics.infos.keys()">
|
104
|
<td class="uk-text-center">
|
105
|
<a href="{{metrics.infos.get(key).url}}">
|
106
|
{{metrics.infos.get(key).name}}
|
107
|
</a>
|
108
|
</td>
|
109
|
<td class="uk-text-center">
|
110
|
{{metrics.infos.get(key).numOfViews}}
|
111
|
<span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
|
112
|
( {{metrics.infos.get(key).openaireViews}} from OpenAIRE )
|
113
|
</span>
|
114
|
</td>
|
115
|
<td class="uk-text-center">
|
116
|
{{metrics.infos.get(key).numOfDownloads}}
|
117
|
<span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
|
118
|
( {{metrics.infos.get(key).openaireDownloads}} from OpenAIRE )
|
119
|
</span>
|
120
|
</td>
|
121
|
</tr>
|
122
|
</tbody>
|
123
|
</table>
|
124
|
`
|
125
|
})
|
126
|
|
127
|
export class MetricsComponent {
|
128
|
@Output() metricsResults = new EventEmitter();
|
129
|
@Input() id: string;
|
130
|
@Input() type: string;
|
131
|
@Input() name: string = "";
|
132
|
@Input() pageViews: number = 0;
|
133
|
public metrics: Metrics;
|
134
|
public errorCodes:ErrorCodes;
|
135
|
public status: number;
|
136
|
|
137
|
constructor (private _metricsService: MetricsService) {}
|
138
|
|
139
|
ngOnInit() {
|
140
|
this.errorCodes = new ErrorCodes();
|
141
|
this.status = this.errorCodes.LOADING;
|
142
|
this.getMetrics();
|
143
|
}
|
144
|
|
145
|
|
146
|
getMetrics() {
|
147
|
//if(this.id == undefined || this.id == "") {
|
148
|
// console.log("supplied id in metrics is not acceptable");
|
149
|
//}
|
150
|
//if(this.type == undefined || this.type == "") {
|
151
|
// console.log("supplied id in metrics is not acceptable");
|
152
|
//}
|
153
|
|
154
|
this._metricsService.getMetrics(this.id, this.type).subscribe(
|
155
|
data => {
|
156
|
this.metrics = data;
|
157
|
this.status = this.errorCodes.DONE;
|
158
|
this.metricsResults.emit({
|
159
|
totalViews: this.metrics.totalViews,
|
160
|
totalDownloads: this.metrics.totalDownloads,
|
161
|
pageViews: this.metrics.pageViews
|
162
|
});
|
163
|
},
|
164
|
err => {
|
165
|
console.log(err);
|
166
|
this.status = this.errorCodes.ERROR;
|
167
|
if(err.status == '404') {
|
168
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
169
|
}
|
170
|
this.metricsResults.emit({
|
171
|
totalViews: 0,
|
172
|
totalDownloads: 0
|
173
|
});
|
174
|
}
|
175
|
);
|
176
|
}
|
177
|
}
|