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,
|
8
|
RepositorySnippet,
|
9
|
RepositorySummaryInfo, StoredJob, UsageSummary
|
10
|
} from '../../domain/typeScriptClasses';
|
11
|
import {
|
12
|
loadingAggregationHistory, loadingAggregationHistoryError, loadingMetrics, loadingMetricsError,
|
13
|
loadingReposMessage, loadingSubscriptions, loadingTopics, loadingTopicsError,
|
14
|
loadingUserRepoInfoEmpty, noAggregationHistory, noSubscriptionsFound, noTopicsFound, reposRetrievalError,
|
15
|
loadingJobSummary, loadingJobSummaryError
|
16
|
} from '../../domain/shared-messages';
|
17
|
import {DashboardService} from '../../services/dashboard.service';
|
18
|
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
|
19
|
import {PiwikService} from '../../services/piwik.service';
|
20
|
import {ValidatorService} from '../../services/validator.service';
|
21
|
|
22
|
@Component ({
|
23
|
selector: 'app-dashboard',
|
24
|
templateUrl: 'dashboard.component.html'
|
25
|
})
|
26
|
|
27
|
export class DashboardComponent implements OnInit {
|
28
|
|
29
|
reposOfUser: RepositorySnippet[] = [];
|
30
|
selectedRepo: RepositorySnippet = null;
|
31
|
// tilesView: boolean;
|
32
|
errorMessage: string;
|
33
|
noRepos: string;
|
34
|
loadingMessage: string;
|
35
|
|
36
|
constructor(private authService: AuthenticationService,
|
37
|
private repositoryService: RepositoryService,
|
38
|
private dashboardService: DashboardService,
|
39
|
private piwikService: PiwikService,
|
40
|
private validatorService: ValidatorService,
|
41
|
private sanitizer: DomSanitizer) { }
|
42
|
|
43
|
repositories: RepositorySummaryInfo[] = [];
|
44
|
userEmail: string;
|
45
|
|
46
|
loading: boolean = true;
|
47
|
|
48
|
|
49
|
// Aggregations
|
50
|
collectionMonitorSummary: CollectionMonitorSummary;
|
51
|
lastIndexedVersion: AggregationDetails;
|
52
|
latestAggregations: AggregationDetails[] = [];
|
53
|
errorAggregationsMessage: string;
|
54
|
noAggregations: string;
|
55
|
loadingAggregationsMessage: string;
|
56
|
|
57
|
// Usage Statistics
|
58
|
usageSummary: UsageSummary;
|
59
|
piwik: PiwikInfo;
|
60
|
repoMetrics: MetricsInfo;
|
61
|
errorUsageStatsMessage: string;
|
62
|
noUsageStats: string;
|
63
|
loadingUsageStatsMessage: string;
|
64
|
pageViews = '--';
|
65
|
totalViews = '--';
|
66
|
totalDownloads = '--';
|
67
|
viewsUrl: SafeResourceUrl;
|
68
|
downloadsUrl: SafeResourceUrl;
|
69
|
shortSelectedRepoId: string;
|
70
|
currentDate: string;
|
71
|
|
72
|
// Broker
|
73
|
brokerSummary: BrokerSummary;
|
74
|
errorTopicsMessage: string;
|
75
|
noTopics: string;
|
76
|
loadingTopicsMessage: string;
|
77
|
errorSubscriptionsMessage: string;
|
78
|
noSubscriptions: string;
|
79
|
loadingSubscriptionsMessage: string;
|
80
|
totalNumberOfEvents: number = 0;
|
81
|
moreList: BrowseEntry[] = [];
|
82
|
missingList: BrowseEntry[] = [];
|
83
|
totalMore: number = 0;
|
84
|
totalMissing: number = 0;
|
85
|
|
86
|
// Validation
|
87
|
storedJob: StoredJob[] = [];
|
88
|
noValidationsMessage: string;
|
89
|
errorValidationsMessage: string;
|
90
|
loadingJobSummaryMessage: string;
|
91
|
|
92
|
ngOnInit() {
|
93
|
// this.getUserEmail();
|
94
|
this.userEmail = sessionStorage.getItem('email');
|
95
|
if (this.userEmail) {
|
96
|
this.getReposOfUser();
|
97
|
// this.getRepositoriesSummaryInfo(this.userEmail);
|
98
|
}
|
99
|
let body = document.getElementsByTagName('body')[0];
|
100
|
body.classList.remove("top_bar_active");
|
101
|
body.classList.remove("page_heading_active");
|
102
|
body.classList.remove("landing");
|
103
|
body.classList.add("dashboard");
|
104
|
|
105
|
const currentTime = new Date();
|
106
|
this.currentDate = currentTime.getFullYear() + '-' + (currentTime.getMonth() + 1);
|
107
|
}
|
108
|
|
109
|
getReposOfUser(): void {
|
110
|
this.loadingMessage = loadingReposMessage;
|
111
|
this.repositoryService.getRepositoriesOfUser()
|
112
|
.subscribe(
|
113
|
repos => {
|
114
|
this.sortRepositoriesByName(repos);
|
115
|
if (this.reposOfUser && this.reposOfUser.length > 0) {
|
116
|
this.selectedRepo = this.reposOfUser[0];
|
117
|
this.getSelectedRepositorySummaryInfo(this.reposOfUser[0]);
|
118
|
}
|
119
|
},
|
120
|
error => {
|
121
|
console.log(error);
|
122
|
this.loadingMessage = '';
|
123
|
this.errorMessage = reposRetrievalError;
|
124
|
},
|
125
|
() => {
|
126
|
this.loadingMessage = '';
|
127
|
if (!this.reposOfUser || !this.reposOfUser.length) {
|
128
|
this.noRepos = loadingUserRepoInfoEmpty;
|
129
|
}
|
130
|
}
|
131
|
);
|
132
|
}
|
133
|
|
134
|
sortRepositoriesByName(repos: RepositorySnippet[]) {
|
135
|
this.reposOfUser = repos.sort( function(a, b) {
|
136
|
if (a.officialname < b.officialname) {
|
137
|
return -1;
|
138
|
} else if (a.officialname > b.officialname) {
|
139
|
return 1;
|
140
|
} else {
|
141
|
return 0;
|
142
|
}
|
143
|
});
|
144
|
}
|
145
|
|
146
|
changeSelectedRepository(repoId: string) {
|
147
|
this.selectedRepo = this.reposOfUser.find(x => x.id == repoId);
|
148
|
console.log('selectedRepo ' + this.selectedRepo.id);
|
149
|
this.getSelectedRepositorySummaryInfo(this.selectedRepo);
|
150
|
}
|
151
|
|
152
|
getSelectedRepositorySummaryInfo(selectedRepo: RepositorySnippet) {
|
153
|
|
154
|
// Aggregations
|
155
|
this.loadingAggregationsMessage = loadingAggregationHistory;
|
156
|
this.latestAggregations = [];
|
157
|
this.lastIndexedVersion = null;
|
158
|
this.dashboardService.getCollectionMonitorSummary(selectedRepo.id, 5).subscribe(
|
159
|
collectionMonitorSummary => this.getCollectionMonitorSummary(collectionMonitorSummary),
|
160
|
error => {
|
161
|
this.loadingAggregationsMessage = '';
|
162
|
this.errorAggregationsMessage = loadingAggregationHistoryError;
|
163
|
},
|
164
|
() => {
|
165
|
this.loadingAggregationsMessage = '';
|
166
|
this.errorAggregationsMessage = '';
|
167
|
}
|
168
|
);
|
169
|
|
170
|
// Usage Statistics
|
171
|
this.loadingUsageStatsMessage = loadingMetrics;
|
172
|
this.usageSummary = null;
|
173
|
this.piwik = null;
|
174
|
this.repoMetrics = null;
|
175
|
this.pageViews = '--';
|
176
|
this.totalViews = '--';
|
177
|
this.totalDownloads = '--';
|
178
|
this.viewsUrl = null;
|
179
|
this.downloadsUrl = null;
|
180
|
this.shortSelectedRepoId = null;
|
181
|
this.dashboardService.getUsageSummary(selectedRepo.id).subscribe(
|
182
|
usageSummary => this.getUsageSummary(usageSummary),
|
183
|
error => {
|
184
|
this.loadingUsageStatsMessage = '';
|
185
|
this.errorUsageStatsMessage = loadingMetricsError;
|
186
|
console.log(error);
|
187
|
} ,
|
188
|
() => {
|
189
|
this.shortSelectedRepoId = selectedRepo.id.replace(/_/g, '').replace('::', ':');
|
190
|
this.loadingUsageStatsMessage = '';
|
191
|
this.errorUsageStatsMessage = '';
|
192
|
}
|
193
|
);
|
194
|
|
195
|
// Broker
|
196
|
this.loadingTopicsMessage = loadingTopics;
|
197
|
this.loadingSubscriptionsMessage = loadingSubscriptions;
|
198
|
this.brokerSummary = null;
|
199
|
this.totalNumberOfEvents = 0;
|
200
|
this.moreList = [];
|
201
|
this.missingList = [];
|
202
|
this.totalMore = 0;
|
203
|
this.totalMissing = 0;
|
204
|
this.dashboardService.getBrokerSummary(this.getCorrectName()).subscribe(
|
205
|
brokerSummary => this.getBrokerSummary(brokerSummary),
|
206
|
error => {
|
207
|
this.loadingTopicsMessage = '';
|
208
|
this.loadingSubscriptionsMessage = '';
|
209
|
this.errorTopicsMessage = loadingTopicsError;
|
210
|
this.errorSubscriptionsMessage = 'Failed to load the subscriptions for your datasource';
|
211
|
console.log(error);
|
212
|
},
|
213
|
() => {
|
214
|
this.loadingTopicsMessage = '';
|
215
|
this.loadingSubscriptionsMessage = '';
|
216
|
this.errorTopicsMessage = '';
|
217
|
this.errorSubscriptionsMessage = '';
|
218
|
}
|
219
|
);
|
220
|
|
221
|
// Validation
|
222
|
this.loadingJobSummaryMessage = loadingJobSummary;
|
223
|
this.noValidationsMessage = '';
|
224
|
this.errorValidationsMessage = '';
|
225
|
this.validatorService.getValidationSummary(selectedRepo.id).subscribe(
|
226
|
validationSummary => {
|
227
|
this.storedJob = validationSummary;
|
228
|
console.log(validationSummary);
|
229
|
},
|
230
|
error => {
|
231
|
this.errorValidationsMessage = loadingJobSummaryError;
|
232
|
this.loadingJobSummaryMessage = '';
|
233
|
console.log(error);
|
234
|
} ,
|
235
|
() => {
|
236
|
this.getValidationSummary(this.storedJob);
|
237
|
this.loadingJobSummaryMessage = '';
|
238
|
}
|
239
|
);
|
240
|
}
|
241
|
|
242
|
getCollectionMonitorSummary(collectionMonitorSummary: CollectionMonitorSummary) {
|
243
|
|
244
|
this.latestAggregations = collectionMonitorSummary.aggregationDetails;
|
245
|
this.lastIndexedVersion = collectionMonitorSummary.lastIndexedVersion;
|
246
|
|
247
|
if ( !this.latestAggregations || (this.latestAggregations.length === 0) ) {
|
248
|
this.noAggregations = noAggregationHistory;
|
249
|
}
|
250
|
}
|
251
|
|
252
|
getBrokerSummary(brokerSummary: BrokerSummary) {
|
253
|
|
254
|
this.noSubscriptions = '';
|
255
|
this.noTopics = '';
|
256
|
|
257
|
this.brokerSummary = brokerSummary;
|
258
|
|
259
|
if(this.brokerSummary.userSubs==null)
|
260
|
this.noSubscriptions = noTopicsFound;
|
261
|
if(this.brokerSummary.topicsForDatasource==null)
|
262
|
this.noTopics = noSubscriptionsFound;
|
263
|
|
264
|
this.totalNumberOfEvents = 0;
|
265
|
this.totalMore = 0;
|
266
|
this.totalMissing = 0;
|
267
|
if(brokerSummary.topicsForDatasource) {
|
268
|
for (let browseEntry of brokerSummary.topicsForDatasource) {
|
269
|
this.totalNumberOfEvents += browseEntry.size;
|
270
|
if (browseEntry.value.startsWith('ENRICH/MORE')) {
|
271
|
this.totalMore += browseEntry.size;
|
272
|
this.moreList.push(browseEntry);
|
273
|
} else if (browseEntry.value.startsWith('ENRICH/MISSING')) {
|
274
|
this.totalMissing += browseEntry.size;
|
275
|
this.missingList.push(browseEntry);
|
276
|
}
|
277
|
}
|
278
|
}
|
279
|
|
280
|
|
281
|
}
|
282
|
|
283
|
getUsageSummary(usageSummary: UsageSummary) {
|
284
|
|
285
|
this.noUsageStats = '';
|
286
|
|
287
|
if (usageSummary.piwikInfo == null) {
|
288
|
this.noUsageStats = 'This repository does not have our Usage Statistics service enabled yet';
|
289
|
} else {
|
290
|
this.usageSummary = usageSummary;
|
291
|
this.piwik = usageSummary.piwikInfo;
|
292
|
this.repoMetrics = usageSummary.metricsInfo;
|
293
|
if (this.repoMetrics.metricsNumbers.pageviews) {
|
294
|
this.pageViews = this.repoMetrics.metricsNumbers.pageviews;
|
295
|
}
|
296
|
if (this.repoMetrics.metricsNumbers.total_views) {
|
297
|
this.totalViews = this.repoMetrics.metricsNumbers.total_views;
|
298
|
}
|
299
|
if (this.repoMetrics.metricsNumbers.total_downloads) {
|
300
|
this.totalDownloads = this.repoMetrics.metricsNumbers.total_downloads;
|
301
|
}
|
302
|
this.getViewsUrl();
|
303
|
this.getDownloadsUrl();
|
304
|
}
|
305
|
}
|
306
|
|
307
|
getValidationSummary(validationSummary: StoredJob[]) {
|
308
|
if (validationSummary == null) { this.noValidationsMessage = 'There is no validation history for this repository at the moment'; }
|
309
|
}
|
310
|
|
311
|
getViewsUrl () {
|
312
|
this.viewsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
|
313
|
`${this.repoMetrics.diagramsBaseURL}merge.php?com=query
|
314
|
&data=[{"query":"dtsrcRepoViews","dtsrcName":"${this.piwik.openaireId}",
|
315
|
"table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","yaxis":1,"c":false}],
|
316
|
"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,
|
317
|
"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"",
|
318
|
"xaxistitle":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]
|
319
|
&info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]
|
320
|
&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},
|
321
|
{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)
|
322
|
&colors[]=rgba(124,181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,1)
|
323
|
&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,1)&colors[]=rgba(241, 92, 128, 1)
|
324
|
&colors[]=rgba(228, 211, 84,1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,1)
|
325
|
&colors[]=rgba(145, 232, 225,1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false`
|
326
|
);
|
327
|
}
|
328
|
|
329
|
getDownloadsUrl () {
|
330
|
this.downloadsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
|
331
|
`${this.repoMetrics.diagramsBaseURL}merge.php?com=query
|
332
|
&data=[{"query":"dtsrcRepoDownloads","dtsrcName":"${this.piwik.openaireId}",
|
333
|
"table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","yaxis":1,"c":false}],
|
334
|
"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,
|
335
|
"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"",
|
336
|
"xaxistitle":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]
|
337
|
&info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]
|
338
|
&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0,1)","size":"18"},
|
339
|
{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)
|
340
|
&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,1)
|
341
|
&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,1)&colors[]=rgba(241, 92, 128, 1)
|
342
|
&colors[]=rgba(228, 211, 84,1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,1)
|
343
|
&colors[]=rgba(145, 232, 225,1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false`
|
344
|
);
|
345
|
}
|
346
|
|
347
|
getCorrectName() {
|
348
|
const temp = this.selectedRepo.officialname.split('|');
|
349
|
let correctName = temp[0];
|
350
|
let repoName = temp[0];
|
351
|
for (let i = 1; i < temp.length; i++) {
|
352
|
correctName += `/${temp[i]}`;
|
353
|
repoName += ` | ${temp[i]}`;
|
354
|
}
|
355
|
|
356
|
return correctName;
|
357
|
}
|
358
|
|
359
|
getIsUserLoggedIn() {
|
360
|
return this.authService.getIsUserLoggedIn();
|
361
|
}
|
362
|
|
363
|
getUserEmail() {
|
364
|
this.userEmail = this.authService.getUserEmail();
|
365
|
}
|
366
|
|
367
|
getRepos() {
|
368
|
console.log('in getRepos');
|
369
|
this.getRepositoriesSummaryInfo(this.userEmail);
|
370
|
}
|
371
|
|
372
|
getRepositoriesSummaryInfo(userEmail: string) {
|
373
|
this.repositoryService.getRepositoriesSummaryInfo().subscribe(
|
374
|
repositories => { this.repositories = repositories; this.loading=false },
|
375
|
error => { console.log('getRepSumError'); this.loading=false },
|
376
|
() => { console.log(this.repositories); this.loading=false }
|
377
|
);
|
378
|
}
|
379
|
}
|