1
|
import { Component, OnInit } from '@angular/core';
|
2
|
import { AuthenticationService } from '../../../services/authentication.service';
|
3
|
import { RepositoryService } from '../../../services/repository.service';
|
4
|
import {
|
5
|
AggregationDetails, BrokerSummary, BrowseEntry, CollectionMonitorSummary,
|
6
|
MetricsInfo, PiwikInfo,
|
7
|
Repository, StoredJob, UsageSummary
|
8
|
} from '../../../domain/typeScriptClasses';
|
9
|
import {
|
10
|
loadingAggregationHistory, loadingAggregationHistoryError, loadingMetrics,
|
11
|
loadingMetricsError, loadingSubscriptions, loadingTopics, loadingTopicsError,
|
12
|
noAggregationHistory, noSubscriptionsFound, noTopicsFound,
|
13
|
loadingJobSummary, loadingJobSummaryError
|
14
|
} from '../../../domain/shared-messages';
|
15
|
import {DashboardService} from '../../../services/dashboard.service';
|
16
|
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
|
17
|
import {PiwikService} from '../../../services/piwik.service';
|
18
|
import {ValidatorService} from '../../../services/validator.service';
|
19
|
import {ActivatedRoute} from "@angular/router";
|
20
|
import {SharedService} from "../../../services/shared.service";
|
21
|
|
22
|
@Component ({
|
23
|
selector: 'app-dashboard',
|
24
|
templateUrl: 'dashboard.component.html'
|
25
|
})
|
26
|
|
27
|
export class DashboardComponent implements OnInit {
|
28
|
|
29
|
repository: Repository = null;
|
30
|
errorMessage: string;
|
31
|
loadingMessage: string;
|
32
|
|
33
|
constructor(private authService: AuthenticationService,
|
34
|
private repositoryService: RepositoryService,
|
35
|
private sharedService: SharedService,
|
36
|
private dashboardService: DashboardService,
|
37
|
private piwikService: PiwikService,
|
38
|
private validatorService: ValidatorService,
|
39
|
private sanitizer: DomSanitizer,
|
40
|
private route: ActivatedRoute) {
|
41
|
}
|
42
|
|
43
|
loading: boolean = true;
|
44
|
|
45
|
|
46
|
// Aggregations
|
47
|
collectionMonitorSummary: CollectionMonitorSummary;
|
48
|
lastIndexedVersion: AggregationDetails;
|
49
|
latestAggregations: AggregationDetails[] = [];
|
50
|
errorAggregationsMessage: string;
|
51
|
noAggregations: string;
|
52
|
loadingAggregationsMessage: string;
|
53
|
|
54
|
// Usage Statistics
|
55
|
usageSummary: UsageSummary;
|
56
|
piwik: PiwikInfo;
|
57
|
repoMetrics: MetricsInfo;
|
58
|
errorUsageStatsMessage: string;
|
59
|
noUsageStats: string;
|
60
|
loadingUsageStatsMessage: string;
|
61
|
pageViews = '--';
|
62
|
totalViews = '--';
|
63
|
totalDownloads = '--';
|
64
|
viewsUrl: SafeResourceUrl;
|
65
|
downloadsUrl: SafeResourceUrl;
|
66
|
shortRepositoryId: string;
|
67
|
currentDate: string;
|
68
|
|
69
|
// Broker
|
70
|
brokerSummary: BrokerSummary;
|
71
|
errorTopicsMessage: string;
|
72
|
noTopics: string;
|
73
|
loadingTopicsMessage: string;
|
74
|
errorSubscriptionsMessage: string;
|
75
|
noSubscriptions: string;
|
76
|
loadingSubscriptionsMessage: string;
|
77
|
totalNumberOfEvents: number = 0;
|
78
|
moreList: BrowseEntry[] = [];
|
79
|
missingList: BrowseEntry[] = [];
|
80
|
totalMore: number = 0;
|
81
|
totalMissing: number = 0;
|
82
|
|
83
|
// Validation
|
84
|
storedJob: StoredJob[] = [];
|
85
|
noValidationsMessage: string;
|
86
|
errorValidationsMessage: string;
|
87
|
loadingJobSummaryMessage: string;
|
88
|
|
89
|
ngOnInit() {
|
90
|
|
91
|
if(this.sharedService.getRepository()) {
|
92
|
this.repository = this.sharedService.getRepository();
|
93
|
this.getSelectedRepositorySummaryInfo(this.repository);
|
94
|
}
|
95
|
|
96
|
this.sharedService.repository$.subscribe(
|
97
|
r => {
|
98
|
this.repository = r;
|
99
|
// console.log("RepositoryID: ", this.repository.id);
|
100
|
this.getSelectedRepositorySummaryInfo(this.repository);
|
101
|
}
|
102
|
);
|
103
|
|
104
|
let body = document.getElementsByTagName('body')[0];
|
105
|
body.classList.remove("top_bar_active");
|
106
|
body.classList.remove("page_heading_active");
|
107
|
body.classList.remove("landing");
|
108
|
body.classList.add("dashboard");
|
109
|
|
110
|
const currentTime = new Date();
|
111
|
this.currentDate = currentTime.getFullYear() + '-' + (currentTime.getMonth() + 1);
|
112
|
}
|
113
|
|
114
|
getSelectedRepositorySummaryInfo(repository: Repository) {
|
115
|
|
116
|
// Aggregations
|
117
|
this.loadingAggregationsMessage = loadingAggregationHistory;
|
118
|
this.latestAggregations = [];
|
119
|
this.lastIndexedVersion = null;
|
120
|
this.dashboardService.getCollectionMonitorSummary(repository.id, 5).subscribe(
|
121
|
collectionMonitorSummary => this.getCollectionMonitorSummary(collectionMonitorSummary),
|
122
|
error => {
|
123
|
this.loadingAggregationsMessage = '';
|
124
|
this.errorAggregationsMessage = loadingAggregationHistoryError;
|
125
|
},
|
126
|
() => {
|
127
|
this.loadingAggregationsMessage = '';
|
128
|
this.errorAggregationsMessage = '';
|
129
|
}
|
130
|
);
|
131
|
|
132
|
// Usage Statistics
|
133
|
this.loadingUsageStatsMessage = loadingMetrics;
|
134
|
this.usageSummary = null;
|
135
|
this.piwik = null;
|
136
|
this.repoMetrics = null;
|
137
|
this.pageViews = '--';
|
138
|
this.totalViews = '--';
|
139
|
this.totalDownloads = '--';
|
140
|
this.viewsUrl = null;
|
141
|
this.downloadsUrl = null;
|
142
|
this.shortRepositoryId = null;
|
143
|
this.dashboardService.getUsageSummary(repository.id).subscribe(
|
144
|
usageSummary => this.getUsageSummary(usageSummary),
|
145
|
error => {
|
146
|
this.loadingUsageStatsMessage = '';
|
147
|
this.errorUsageStatsMessage = loadingMetricsError;
|
148
|
console.log(error);
|
149
|
} ,
|
150
|
() => {
|
151
|
this.shortRepositoryId = repository.id.replace(/_/g, '').replace('::', ':');
|
152
|
this.loadingUsageStatsMessage = '';
|
153
|
this.errorUsageStatsMessage = '';
|
154
|
}
|
155
|
);
|
156
|
|
157
|
// Broker
|
158
|
this.loadingTopicsMessage = loadingTopics;
|
159
|
this.loadingSubscriptionsMessage = loadingSubscriptions;
|
160
|
this.brokerSummary = null;
|
161
|
this.totalNumberOfEvents = 0;
|
162
|
this.moreList = [];
|
163
|
this.missingList = [];
|
164
|
this.totalMore = 0;
|
165
|
this.totalMissing = 0;
|
166
|
this.dashboardService.getBrokerSummary(this.getCorrectName()).subscribe(
|
167
|
brokerSummary => this.getBrokerSummary(brokerSummary),
|
168
|
error => {
|
169
|
this.loadingTopicsMessage = '';
|
170
|
this.loadingSubscriptionsMessage = '';
|
171
|
this.errorTopicsMessage = loadingTopicsError;
|
172
|
this.errorSubscriptionsMessage = 'Failed to load the subscriptions for your datasource';
|
173
|
console.log(error);
|
174
|
},
|
175
|
() => {
|
176
|
this.loadingTopicsMessage = '';
|
177
|
this.loadingSubscriptionsMessage = '';
|
178
|
this.errorTopicsMessage = '';
|
179
|
this.errorSubscriptionsMessage = '';
|
180
|
}
|
181
|
);
|
182
|
|
183
|
// Validation
|
184
|
this.loadingJobSummaryMessage = loadingJobSummary;
|
185
|
this.noValidationsMessage = '';
|
186
|
this.errorValidationsMessage = '';
|
187
|
this.validatorService.getValidationSummary(repository.id).subscribe(
|
188
|
validationSummary => {
|
189
|
this.storedJob = validationSummary;
|
190
|
// console.log(validationSummary);
|
191
|
},
|
192
|
error => {
|
193
|
this.errorValidationsMessage = loadingJobSummaryError;
|
194
|
this.loadingJobSummaryMessage = '';
|
195
|
console.log(error);
|
196
|
} ,
|
197
|
() => {
|
198
|
this.getValidationSummary(this.storedJob);
|
199
|
this.loadingJobSummaryMessage = '';
|
200
|
}
|
201
|
);
|
202
|
}
|
203
|
|
204
|
getCollectionMonitorSummary(collectionMonitorSummary: CollectionMonitorSummary) {
|
205
|
|
206
|
this.latestAggregations = collectionMonitorSummary.aggregationDetails;
|
207
|
this.lastIndexedVersion = collectionMonitorSummary.lastIndexedVersion;
|
208
|
|
209
|
if ( !this.latestAggregations || (this.latestAggregations.length === 0) ) {
|
210
|
this.noAggregations = noAggregationHistory;
|
211
|
}
|
212
|
}
|
213
|
|
214
|
getBrokerSummary(brokerSummary: BrokerSummary) {
|
215
|
|
216
|
this.noSubscriptions = '';
|
217
|
this.noTopics = '';
|
218
|
|
219
|
this.brokerSummary = brokerSummary;
|
220
|
|
221
|
if(this.brokerSummary.userSubs==null)
|
222
|
this.noSubscriptions = noTopicsFound;
|
223
|
if(this.brokerSummary.topicsForDatasource==null)
|
224
|
this.noTopics = noSubscriptionsFound;
|
225
|
|
226
|
this.totalNumberOfEvents = 0;
|
227
|
this.totalMore = 0;
|
228
|
this.totalMissing = 0;
|
229
|
if(brokerSummary.topicsForDatasource) {
|
230
|
for (let browseEntry of brokerSummary.topicsForDatasource) {
|
231
|
this.totalNumberOfEvents += browseEntry.size;
|
232
|
if (browseEntry.value.startsWith('ENRICH/MORE')) {
|
233
|
this.totalMore += browseEntry.size;
|
234
|
this.moreList.push(browseEntry);
|
235
|
} else if (browseEntry.value.startsWith('ENRICH/MISSING')) {
|
236
|
this.totalMissing += browseEntry.size;
|
237
|
this.missingList.push(browseEntry);
|
238
|
}
|
239
|
}
|
240
|
}
|
241
|
|
242
|
|
243
|
}
|
244
|
|
245
|
getUsageSummary(usageSummary: UsageSummary) {
|
246
|
|
247
|
this.noUsageStats = '';
|
248
|
|
249
|
if (usageSummary.piwikInfo == null) {
|
250
|
this.noUsageStats = 'This repository does not have our Usage Statistics service enabled yet';
|
251
|
} else {
|
252
|
this.usageSummary = usageSummary;
|
253
|
this.piwik = usageSummary.piwikInfo;
|
254
|
this.repoMetrics = usageSummary.metricsInfo;
|
255
|
if (this.repoMetrics.metricsNumbers.pageviews) {
|
256
|
this.pageViews = this.repoMetrics.metricsNumbers.pageviews;
|
257
|
}
|
258
|
if (this.repoMetrics.metricsNumbers.total_views) {
|
259
|
this.totalViews = this.repoMetrics.metricsNumbers.total_views;
|
260
|
}
|
261
|
if (this.repoMetrics.metricsNumbers.total_downloads) {
|
262
|
this.totalDownloads = this.repoMetrics.metricsNumbers.total_downloads;
|
263
|
}
|
264
|
this.getViewsUrl();
|
265
|
this.getDownloadsUrl();
|
266
|
}
|
267
|
}
|
268
|
|
269
|
getValidationSummary(validationSummary: StoredJob[]) {
|
270
|
if (validationSummary == null) { this.noValidationsMessage = 'There is no validation history for this repository at the moment'; }
|
271
|
}
|
272
|
|
273
|
getViewsUrl () {
|
274
|
|
275
|
let encodedURL = encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Monthly views","type":"line","query":{"name":"usagestats.views.monthly", "parameters":["' + this.piwik.openaireId + '"], "profile":"OpenAIRE All-inclusive" }}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{"text":"Monthly views"}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}');
|
276
|
this.viewsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(`${this.repoMetrics.diagramsBaseURL}chart?json=${encodedURL}`);
|
277
|
}
|
278
|
|
279
|
getDownloadsUrl () {
|
280
|
|
281
|
let encodedURL = encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Monthly downloads","type":"line","query":{"name":"usagestats.downloads.monthly", "parameters":["' + this.piwik.openaireId + '"], "profile":"OpenAIRE All-inclusive" }}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{"text":"Monthly downloads"}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}');
|
282
|
this.downloadsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(`${this.repoMetrics.diagramsBaseURL}chart?json=${encodedURL}`);
|
283
|
}
|
284
|
|
285
|
getCorrectName() {
|
286
|
const temp = this.repository.officialname.split('|');
|
287
|
let correctName = temp[0];
|
288
|
let repoName = temp[0];
|
289
|
for (let i = 1; i < temp.length; i++) {
|
290
|
correctName += `/${temp[i]}`;
|
291
|
repoName += ` | ${temp[i]}`;
|
292
|
}
|
293
|
|
294
|
return correctName;
|
295
|
}
|
296
|
}
|