1
|
import { Component, OnInit } from '@angular/core';
|
2
|
import { ActivatedRoute } from '@angular/router';
|
3
|
import { AuthenticationService } from '../../services/authentication.service';
|
4
|
import { UsagestatsService } from '../../services/usagestats.service';
|
5
|
import { ReportResponse } from '../../domain/usageStatsClasses';
|
6
|
import {ar1_report_results} from "../../domain/sushilite_demo_data/AR1_ex";
|
7
|
|
8
|
@Component({
|
9
|
selector: 'metrics-usagestats-report-results',
|
10
|
templateUrl: 'metrics-usagestats-report-results.component.html'
|
11
|
})
|
12
|
export class MetricsUsagestatsReportResultsComponent implements OnInit {
|
13
|
|
14
|
errorMessage: string;
|
15
|
|
16
|
repoResponse = ar1_report_results['ReportResponse'];
|
17
|
coveredPeriod: string;
|
18
|
|
19
|
constructor(private route: ActivatedRoute,
|
20
|
private authService: AuthenticationService,
|
21
|
private usageService: UsagestatsService) {}
|
22
|
|
23
|
ngOnInit() {
|
24
|
//this.getReportResponse();
|
25
|
if (this.repoResponse.Report && this.repoResponse.ReportDefinition.Filters.UsageDateRange &&
|
26
|
this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin && this.repoResponse.ReportDefinition.Filters.UsageDateRange.End) {
|
27
|
this.coveredPeriod = this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin + ' to ' + this.repoResponse.ReportDefinition.Filters.UsageDateRange.End;
|
28
|
} else {
|
29
|
let defaultDatePeriod = this.repoResponse.Exception.filter(x => x['Message'] === 'Unspecified Date Arguments');
|
30
|
this.coveredPeriod = defaultDatePeriod[0].Data.split(':')[1].trim() + ' to ' + defaultDatePeriod[1].Data.split(':')[1].trim() + ' (default)';
|
31
|
}
|
32
|
}
|
33
|
|
34
|
getReportResponse() {
|
35
|
let params = new URLSearchParams();
|
36
|
|
37
|
this.route.queryParams.subscribe( qparams => {
|
38
|
params.append('Report', qparams['report']);
|
39
|
params.append('Release', '4');
|
40
|
params.append('RequestorID', this.authService.getUserEmail());
|
41
|
params.append('BeginDate', qparams['beginDate']);
|
42
|
params.append('EndDate', qparams['endDate']);
|
43
|
params.append('RepositoryIdentifier', qparams['repoId']);
|
44
|
if (qparams['itemIdentifier']) {
|
45
|
params.append('ItemIdentifier', qparams['itemIdentifier']);
|
46
|
}
|
47
|
if (qparams['itemDataType']) {
|
48
|
params.append('ItemDataType', qparams['itemIdentifier']);
|
49
|
}
|
50
|
params.append('Granularity', qparams['granularity']);
|
51
|
if (qparams['pretty'] && qparams['pretty']==='true') {
|
52
|
params.append('Pretty', 'Pretty');
|
53
|
}
|
54
|
});
|
55
|
|
56
|
this.usageService.getReportResponse(params).subscribe(
|
57
|
responseWrapper => {
|
58
|
this.repoResponse = responseWrapper.ReportResponse
|
59
|
},
|
60
|
error => {
|
61
|
this.errorMessage = 'Failed to load the report results!';
|
62
|
},
|
63
|
() => {
|
64
|
if (this.repoResponse.Report && this.repoResponse.ReportDefinition.Filters.UsageDateRange &&
|
65
|
this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin && this.repoResponse.ReportDefinition.Filters.UsageDateRange.End) {
|
66
|
this.coveredPeriod = this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin + ' to ' + this.repoResponse.ReportDefinition.Filters.UsageDateRange.End;
|
67
|
} else {
|
68
|
let defaultDatePeriod = this.repoResponse.Exception.filter(x => x['Message'] === 'Unspecified Date Arguments');
|
69
|
this.coveredPeriod = defaultDatePeriod[0].Data.split(':')[1].trim() + ' to ' + defaultDatePeriod[1].Data.split(':')[1].trim() + ' (default)';
|
70
|
}
|
71
|
}
|
72
|
);
|
73
|
|
74
|
}
|
75
|
|
76
|
transformItem(url: string) {
|
77
|
const temp = url.split(';');
|
78
|
let output = '';
|
79
|
for (let u of temp) {
|
80
|
if (output.length === 0) {
|
81
|
output = output + '\n';
|
82
|
}
|
83
|
output = output + u.replace(/\\/g,'');
|
84
|
}
|
85
|
return output;
|
86
|
}
|
87
|
|
88
|
}
|