1 |
50169
|
argiro.kok
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
2 |
|
|
import {Metrics} from '../../utils/entities/metrics';
|
3 |
|
|
import {MetricsService } from '../../services/metrics.service';
|
4 |
50761
|
argiro.kok
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
5 |
50169
|
argiro.kok
|
|
6 |
55964
|
argiro.kok
|
import { Subscription } from 'rxjs';
|
7 |
50586
|
argiro.kok
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
8 |
50169
|
argiro.kok
|
|
9 |
|
|
@Component({
|
10 |
|
|
selector: 'metrics',
|
11 |
|
|
template: `
|
12 |
52373
|
argiro.kok
|
<div *ngIf="!shortView">
|
13 |
52401
|
konstantin
|
<errorMessages [status]="[status]" [type]="'metrics'" tab_error_class=true></errorMessages>
|
14 |
52769
|
argiro.kok
|
|
15 |
|
|
<div *ngIf="metrics && pageViews == 0 && metrics.totalViews == 0 && metrics.totalDownloads == 0" class="uk-alert uk-alert-primary">
|
16 |
|
|
No metrics available
|
17 |
|
|
</div>
|
18 |
|
|
<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="">
|
19 |
52401
|
konstantin
|
<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>
|
20 |
|
|
<div class="metrics-openaire uk-first-column">
|
21 |
|
|
<div class="uk-tile uk-tile-default uk-padding-small">
|
22 |
|
|
<div class="uk-text-center">{{pageViews | number}}</div>
|
23 |
|
|
<div class="uk-text-center">views in OpenAIRE</div>
|
24 |
|
|
</div>
|
25 |
50169
|
argiro.kok
|
</div>
|
26 |
52401
|
konstantin
|
<div class="metrics-views">
|
27 |
|
|
<div class="uk-tile uk-tile-muted uk-padding-small">
|
28 |
|
|
<div class="uk-text-center"> {{metrics.totalViews | number}}
|
29 |
|
|
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
|
30 |
|
|
( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
|
31 |
|
|
</span></div>
|
32 |
|
|
<div class="uk-text-center">views in local repository</div>
|
33 |
|
|
</div>
|
34 |
50169
|
argiro.kok
|
</div>
|
35 |
52401
|
konstantin
|
<div class="metrics-downloads">
|
36 |
|
|
<div class="uk-tile uk-tile-primary uk-padding-small">
|
37 |
|
|
<div class="uk-text-center"> {{metrics.totalDownloads | number}}
|
38 |
|
|
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
|
39 |
|
|
( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE )
|
40 |
|
|
</span></div>
|
41 |
|
|
<div class="uk-text-center">downloads in local repository</div>
|
42 |
|
|
</div>
|
43 |
50169
|
argiro.kok
|
</div>
|
44 |
52401
|
konstantin
|
|
45 |
50169
|
argiro.kok
|
</div>
|
46 |
|
|
|
47 |
52401
|
konstantin
|
<p *ngIf="metrics != undefined && metrics.infos.size > 0" >The information is available from the following content providers: </p>
|
48 |
|
|
<table *ngIf="metrics != undefined && metrics.infos.size > 0"
|
49 |
52769
|
argiro.kok
|
class="uk-table uk-table-small uk-table-striped">
|
50 |
52401
|
konstantin
|
<thead>
|
51 |
|
|
<tr>
|
52 |
|
|
<th class="uk-text-center uk-text-bold">From</th>
|
53 |
|
|
<th class="uk-text-center uk-text-bold">Number Of Views</th>
|
54 |
|
|
<th class="uk-text-center uk-text-bold">Number Of Downloads</th>
|
55 |
|
|
</tr>
|
56 |
|
|
</thead>
|
57 |
|
|
<tbody>
|
58 |
|
|
<tr *ngFor="let key of getKeys(metrics.infos)">
|
59 |
|
|
<td class="uk-text-center">
|
60 |
|
|
<a href="{{metrics.infos.get(key).url}}">
|
61 |
|
|
{{metrics.infos.get(key).name}}
|
62 |
|
|
</a>
|
63 |
|
|
</td>
|
64 |
|
|
<td class="uk-text-center">
|
65 |
|
|
{{metrics.infos.get(key).numOfViews | number}}
|
66 |
|
|
<span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
|
67 |
|
|
( {{metrics.infos.get(key).openaireViews | number}} from OpenAIRE )
|
68 |
|
|
</span>
|
69 |
|
|
</td>
|
70 |
|
|
<td class="uk-text-center">
|
71 |
|
|
{{metrics.infos.get(key).numOfDownloads | number}}
|
72 |
|
|
<span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
|
73 |
|
|
( {{metrics.infos.get(key).openaireDownloads | number}} from OpenAIRE )
|
74 |
|
|
</span>
|
75 |
|
|
</td>
|
76 |
|
|
</tr>
|
77 |
|
|
</tbody>
|
78 |
|
|
</table>
|
79 |
52373
|
argiro.kok
|
</div>
|
80 |
52769
|
argiro.kok
|
<div *ngIf="shortView && metrics && (metrics.pageViews >0 || metrics.totalViews > 0|| metrics.totalDownloads >0)">
|
81 |
52373
|
argiro.kok
|
<dl *ngIf="metrics" class="uk-description-list-line">
|
82 |
52769
|
argiro.kok
|
<dt class="sideInfoTitle">Metrics</dt>
|
83 |
52373
|
argiro.kok
|
<dd class="line" >
|
84 |
|
|
{{metrics.pageViews | number}} views in OpenAIRE
|
85 |
|
|
</dd>
|
86 |
|
|
<dd class="line">
|
87 |
|
|
{{metrics.totalViews | number}}
|
88 |
|
|
<span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
|
89 |
|
|
( {{metrics.totalOpenaireViews | number}} from OpenAIRE )
|
90 |
|
|
</span>
|
91 |
|
|
views in local repository
|
92 |
|
|
</dd>
|
93 |
|
|
<dd class="line">
|
94 |
|
|
{{metrics.totalDownloads | number}}
|
95 |
|
|
<span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
|
96 |
|
|
( {{metrics.totalOpenaireDownloads | number}} from OpenAIRE )
|
97 |
|
|
</span> downloads in local repository
|
98 |
|
|
</dd>
|
99 |
|
|
</dl>
|
100 |
|
|
</div>
|
101 |
50169
|
argiro.kok
|
`
|
102 |
|
|
})
|
103 |
|
|
|
104 |
|
|
export class MetricsComponent {
|
105 |
|
|
@Output() metricsResults = new EventEmitter();
|
106 |
|
|
@Input() id: string;
|
107 |
|
|
@Input() entityType: string;
|
108 |
|
|
@Input() entity: string;
|
109 |
|
|
//@Input() name: string = "";
|
110 |
|
|
@Input() pageViews: number = 0;
|
111 |
50586
|
argiro.kok
|
@Input() properties:EnvProperties;
|
112 |
52373
|
argiro.kok
|
@Input() shortView:boolean = false;
|
113 |
50169
|
argiro.kok
|
|
114 |
|
|
public metrics: Metrics;
|
115 |
|
|
public errorCodes:ErrorCodes;
|
116 |
|
|
private sub: Subscription;
|
117 |
|
|
|
118 |
|
|
public status: number;
|
119 |
|
|
|
120 |
|
|
constructor (private _metricsService: MetricsService) {}
|
121 |
|
|
|
122 |
|
|
ngOnInit() {
|
123 |
|
|
this.errorCodes = new ErrorCodes();
|
124 |
|
|
this.status = this.errorCodes.LOADING;
|
125 |
|
|
this.getMetrics();
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
ngOnDestroy() {
|
129 |
|
|
this.sub.unsubscribe();
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
private getMetrics() {
|
133 |
|
|
//if(this.id == undefined || this.id == "") {
|
134 |
|
|
// console.log("supplied id in metrics is not acceptable");
|
135 |
|
|
//}
|
136 |
|
|
//if(this.type == undefined || this.type == "") {
|
137 |
|
|
// console.log("supplied id in metrics is not acceptable");
|
138 |
|
|
//}
|
139 |
|
|
|
140 |
50586
|
argiro.kok
|
this.sub = this._metricsService.getMetrics(this.id, this.entityType, this.properties).subscribe(
|
141 |
50169
|
argiro.kok
|
data => {
|
142 |
|
|
this.metrics = data;
|
143 |
|
|
this.status = this.errorCodes.DONE;
|
144 |
|
|
this.metricsResults.emit({
|
145 |
|
|
totalViews: this.metrics.totalViews,
|
146 |
|
|
totalDownloads: this.metrics.totalDownloads,
|
147 |
|
|
pageViews: this.metrics.pageViews
|
148 |
|
|
});
|
149 |
|
|
},
|
150 |
|
|
err => {
|
151 |
|
|
console.log(err);
|
152 |
|
|
if(err.status == '404') {
|
153 |
|
|
this.status = this.errorCodes.NOT_FOUND;
|
154 |
|
|
} else if(err.status == '500') {
|
155 |
|
|
this.status = this.errorCodes.ERROR;
|
156 |
|
|
} else {
|
157 |
|
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
158 |
|
|
}
|
159 |
|
|
this.metricsResults.emit({
|
160 |
|
|
totalViews: 0,
|
161 |
|
|
totalDownloads: 0
|
162 |
|
|
});
|
163 |
|
|
}
|
164 |
|
|
);
|
165 |
|
|
}
|
166 |
52401
|
konstantin
|
|
167 |
|
|
public getKeys( map) {
|
168 |
|
|
return Array.from(map.keys());
|
169 |
|
|
}
|
170 |
50169
|
argiro.kok
|
}
|