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
|
import { Subscription } from 'rxjs/Subscription';
|
7
|
|
8
|
@Component({
|
9
|
selector: 'metrics',
|
10
|
template: `
|
11
|
<!--div *ngIf="i>0 && tab.content=='metricsTab' && metrics != undefined" class="uk-panel uk-padding uk-background-muted"-->
|
12
|
<!--/div-->
|
13
|
|
14
|
<!--dl *ngIf="metrics != undefined"
|
15
|
class="uk-description-list-horizontal uk-panel uk-padding uk-background-muted">
|
16
|
<dt *ngIf="type=='results'">Total Downloads: </dt>
|
17
|
<dt *ngIf="type!='results'" class="uk-text-break">
|
18
|
Total <span [innerHTML]="name"></span> Publication Downloads:
|
19
|
</dt>
|
20
|
<dd>{{metrics.totalDownloads}}</dd>
|
21
|
<dt>Total Views: </dt>
|
22
|
<dd>{{metrics.totalViews}}</dd>
|
23
|
</dl-->
|
24
|
|
25
|
<!--div *ngIf="metrics == undefined" class="uk-alert uk-alert-warning">
|
26
|
Metrics are currently unavailable
|
27
|
</div-->
|
28
|
|
29
|
<!--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>
|
30
|
<div *ngIf="status == errorCodes.NONE" class="uk-alert uk-alert-primary" role="alert">No Results found</div>
|
31
|
<div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning" role="alert">An Error Occured</div>
|
32
|
<div *ngIf="status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger" role="alert">Service temprorarily unavailable. Please try again later.</div>
|
33
|
<div *ngIf="status == errorCodes.NOT_FOUND" class="uk-alert uk-alert-danger" role="alert">No metrics found</div-->
|
34
|
<errorMessages [status]="[status]" [type]="'metrics'"></errorMessages>
|
35
|
<div *ngIf="metrics != undefined" class="uk-child-width-1-3@m uk-grid-small uk-grid-match uk-grid" uk-grid="">
|
36
|
<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>
|
37
|
<div class="metrics-openaire uk-first-column">
|
38
|
<div class="uk-tile uk-tile-default uk-padding-small">
|
39
|
<!--div class="uk-clearfix">
|
40
|
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
|
41
|
title='<div class= "uk-margin uk-padding-small">
|
42
|
<p>Info about the value....</p>
|
43
|
</div>'><span class="uk-icon">
|
44
|
<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>
|
45
|
</span>
|
46
|
</div>
|
47
|
</div-->
|
48
|
<div class="uk-text-center">{{pageViews}}</div>
|
49
|
<div class="uk-text-center">views in OpenAIRE</div>
|
50
|
<!--div *ngIf="entityType!='results'" class="uk-text-center">Research results views in OpenAIRE</div-->
|
51
|
<!--div class="uk-margin-top uk-article-meta">
|
52
|
<div *ngIf="entityType != 'results'">Research results page views in OpenAIRE</div>
|
53
|
<div *ngIf="entityType == 'results'">{{entity}} page views in OpenAIRE</div>
|
54
|
</div-->
|
55
|
|
56
|
</div>
|
57
|
</div>
|
58
|
<div class="metrics-views">
|
59
|
<div class="uk-tile uk-tile-muted uk-padding-small">
|
60
|
<!--div class="uk-clearfix">
|
61
|
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
|
62
|
title='<div class= "uk-margin uk-padding-small">
|
63
|
<p>Info about the value....</p>
|
64
|
</div>'><span class="uk-icon">
|
65
|
<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>
|
66
|
</span>
|
67
|
</div>
|
68
|
</div-->
|
69
|
<div class="uk-text-center"> {{metrics.totalViews}}
|
70
|
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
|
71
|
( {{metrics.totalOpenaireViews}} from OpenAIRE )
|
72
|
</span></div>
|
73
|
<div class="uk-text-center">views in local repository</div>
|
74
|
<!--div *ngIf="entityType!='results'" class="uk-text-center"> research results views in local repository</div-->
|
75
|
<!--div *ngIf="type!='results'" class="uk-text-center"> Total <span [innerHTML]="name"></span> Research Results Views</div-->
|
76
|
|
77
|
|
78
|
<!--div class="uk-margin-top uk-article-meta">
|
79
|
<div *ngIf="entityType == 'projects'">Research results page views in Repositories</div>
|
80
|
<div *ngIf="entityType == 'datasources'">Research results page views in Repository</div>
|
81
|
<div *ngIf="entityType == 'results'">{{entity}} page views in Repositories</div>
|
82
|
<div *ngIf="entityType!='datasources' && metrics.totalOpenaireViews > 0">
|
83
|
Of the {{metrics.totalViews}} views, repositories accessed {{metrics.totalOpenaireViews}} time(s) from OpenAIRE
|
84
|
</div>
|
85
|
<div *ngIf="entityType=='datasources' && metrics.totalOpenaireViews > 0">
|
86
|
Of the {{metrics.totalViews}} views, repository accessed {{metrics.totalOpenaireViews}} time(s) from OpenAIRE
|
87
|
</div>
|
88
|
</div-->
|
89
|
</div>
|
90
|
</div>
|
91
|
<div class="metrics-downloads">
|
92
|
<div class="uk-tile uk-tile-primary uk-padding-small">
|
93
|
<!--div class="uk-clearfix">
|
94
|
<div class="uk-float-left " uk-tooltip="pos:right; delay:5"
|
95
|
title='<div class= "uk-margin uk-padding-small">
|
96
|
<p>Info about the value....</p>
|
97
|
</div>'><span class="uk-icon">
|
98
|
<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>
|
99
|
</span>
|
100
|
</div>
|
101
|
</div-->
|
102
|
<div class="uk-text-center"> {{metrics.totalDownloads}}
|
103
|
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
|
104
|
( {{metrics.totalOpenaireDownloads}} from OpenAIRE )
|
105
|
</span></div>
|
106
|
<div class="uk-text-center">downloads in local repository</div>
|
107
|
<!--div *ngIf="entityType!='results'" class="uk-text-center">research results downloads in local repository</div-->
|
108
|
<!--div *ngIf="type!='results'" class="uk-text-center">Total <span [innerHTML]="name"></span> Research Results Downloads</div-->
|
109
|
|
110
|
|
111
|
<!--div class="uk-margin-top uk-article-meta">
|
112
|
<div *ngIf="entityType == 'projects'">Research results page downloads in Repositories</div>
|
113
|
<div *ngIf="entityType == 'datasources'">Research results page downloads in Repository</div>
|
114
|
<div *ngIf="entityType == 'results'">{{entity}} page downloads in Repositories</div>
|
115
|
<div *ngIf="entityType!='datasources' && metrics.totalOpenaireDownloads > 0">
|
116
|
Of the {{metrics.totalDownloads}} downloads, repositories accessed {{metrics.totalOpenaireDownloads}} time(s) from OpenAIRE
|
117
|
</div>
|
118
|
<div *ngIf="entityType=='datasources' && metrics.totalOpenaireDownloads > 0">
|
119
|
Of the {{metrics.totalDownloads}} downloads, repository accessed {{metrics.totalOpenaireDownloads}} time(s) from OpenAIRE
|
120
|
</div>
|
121
|
</div-->
|
122
|
|
123
|
</div>
|
124
|
</div>
|
125
|
|
126
|
</div>
|
127
|
|
128
|
<p *ngIf="metrics != undefined && metrics.infos.size > 0" >The information is available from the following content providers: </p>
|
129
|
<table *ngIf="metrics != undefined && metrics.infos.size > 0"
|
130
|
class="uk-table uk-table-striped">
|
131
|
<thead>
|
132
|
<tr>
|
133
|
<th class="uk-text-center uk-text-bold">From</th>
|
134
|
<th class="uk-text-center uk-text-bold">Number Of Views</th>
|
135
|
<th class="uk-text-center uk-text-bold">Number Of Downloads</th>
|
136
|
</tr>
|
137
|
</thead>
|
138
|
<tbody>
|
139
|
<tr *ngFor="let key of metrics.infos.keys()">
|
140
|
<td class="uk-text-center">
|
141
|
<a href="{{metrics.infos.get(key).url}}">
|
142
|
{{metrics.infos.get(key).name}}
|
143
|
</a>
|
144
|
</td>
|
145
|
<td class="uk-text-center">
|
146
|
{{metrics.infos.get(key).numOfViews}}
|
147
|
<span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
|
148
|
( {{metrics.infos.get(key).openaireViews}} from OpenAIRE )
|
149
|
</span>
|
150
|
</td>
|
151
|
<td class="uk-text-center">
|
152
|
{{metrics.infos.get(key).numOfDownloads}}
|
153
|
<span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
|
154
|
( {{metrics.infos.get(key).openaireDownloads}} from OpenAIRE )
|
155
|
</span>
|
156
|
</td>
|
157
|
</tr>
|
158
|
</tbody>
|
159
|
</table>
|
160
|
`
|
161
|
})
|
162
|
|
163
|
export class MetricsComponent {
|
164
|
@Output() metricsResults = new EventEmitter();
|
165
|
@Input() id: string;
|
166
|
@Input() entityType: string;
|
167
|
@Input() entity: string;
|
168
|
//@Input() name: string = "";
|
169
|
@Input() pageViews: number = 0;
|
170
|
|
171
|
public metrics: Metrics;
|
172
|
public errorCodes:ErrorCodes;
|
173
|
private sub: Subscription;
|
174
|
|
175
|
public status: number;
|
176
|
|
177
|
constructor (private _metricsService: MetricsService) {}
|
178
|
|
179
|
ngOnInit() {
|
180
|
this.errorCodes = new ErrorCodes();
|
181
|
this.status = this.errorCodes.LOADING;
|
182
|
this.getMetrics();
|
183
|
}
|
184
|
|
185
|
ngOnDestroy() {
|
186
|
this.sub.unsubscribe();
|
187
|
}
|
188
|
|
189
|
private getMetrics() {
|
190
|
//if(this.id == undefined || this.id == "") {
|
191
|
// console.log("supplied id in metrics is not acceptable");
|
192
|
//}
|
193
|
//if(this.type == undefined || this.type == "") {
|
194
|
// console.log("supplied id in metrics is not acceptable");
|
195
|
//}
|
196
|
|
197
|
this.sub = this._metricsService.getMetrics(this.id, this.entityType).subscribe(
|
198
|
data => {
|
199
|
this.metrics = data;
|
200
|
this.status = this.errorCodes.DONE;
|
201
|
|
202
|
this.metricsResults.emit({
|
203
|
totalViews: this.metrics.totalViews,
|
204
|
totalDownloads: this.metrics.totalDownloads,
|
205
|
pageViews: this.metrics.pageViews
|
206
|
});
|
207
|
},
|
208
|
err => {
|
209
|
console.log(err);
|
210
|
if(err.status == '404') {
|
211
|
this.status = this.errorCodes.NOT_FOUND;
|
212
|
} else if(err.status == '500') {
|
213
|
this.status = this.errorCodes.ERROR;
|
214
|
} else {
|
215
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
216
|
}
|
217
|
this.metricsResults.emit({
|
218
|
totalViews: 0,
|
219
|
totalDownloads: 0
|
220
|
});
|
221
|
}
|
222
|
);
|
223
|
}
|
224
|
}
|