Revision 52995
Added by Myrto Koukouli over 5 years ago
metrics-usagestats-report-results.component.ts | ||
---|---|---|
11 | 11 |
}) |
12 | 12 |
export class MetricsUsagestatsReportResultsComponent implements OnInit { |
13 | 13 |
|
14 |
loadingMessage: string; |
|
14 | 15 |
errorMessage: string; |
16 |
infoMessage: string; |
|
15 | 17 |
|
16 |
repoResponse = ar1_report_results['ReportResponse'];
|
|
18 |
repoResponse: ReportResponse;
|
|
17 | 19 |
coveredPeriod: string; |
20 |
params: URLSearchParams; |
|
21 |
page:number; |
|
22 |
pageSize:number; |
|
23 |
totalPages:number; |
|
24 |
selectedItemIndex: number; |
|
18 | 25 |
|
19 | 26 |
constructor(private route: ActivatedRoute, |
20 | 27 |
private authService: AuthenticationService, |
21 | 28 |
private usageService: UsagestatsService) {} |
22 | 29 |
|
23 | 30 |
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 |
} |
|
31 |
this.page = 0; |
|
32 |
this.pageSize = 10; |
|
33 |
this.readParams(); |
|
32 | 34 |
} |
33 | 35 |
|
34 |
getReportResponse() {
|
|
35 |
let params = new URLSearchParams();
|
|
36 |
readParams() {
|
|
37 |
this.params = new URLSearchParams();
|
|
36 | 38 |
|
37 | 39 |
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 |
} |
|
40 |
this.params.append('Report', qparams['report']); |
|
41 |
this.params.append('Release', '4'); |
|
42 |
this.params.append('RequestorID', this.authService.getUserEmail()); |
|
43 |
this.params.append('BeginDate', qparams['beginDate']); |
|
44 |
this.params.append('EndDate', qparams['endDate']); |
|
45 |
this.params.append('RepositoryIdentifier', qparams['repoId']); |
|
46 |
this.params.append('ItemIdentifier', qparams['itemIdentifier']); |
|
47 |
this.params.append('ItemDataType', qparams['itemIdentifier']); |
|
48 |
this.params.append('Granularity', qparams['granularity']); |
|
54 | 49 |
}); |
55 | 50 |
|
56 |
this.usageService.getReportResponse(params).subscribe( |
|
51 |
this.getReportResponse(); |
|
52 |
} |
|
53 |
|
|
54 |
getReportResponse() { |
|
55 |
this.errorMessage = ''; |
|
56 |
this.loadingMessage = 'Loading results...'; |
|
57 |
this.infoMessage = ''; |
|
58 |
this.selectedItemIndex = null; |
|
59 |
this.repoResponse = null; |
|
60 |
|
|
61 |
this.usageService.getReportResponse(this.page.toString(), this.pageSize.toString(), this.params).subscribe( |
|
57 | 62 |
responseWrapper => { |
58 |
this.repoResponse = responseWrapper.ReportResponse |
|
63 |
this.repoResponse = responseWrapper.ReportResponse;
|
|
59 | 64 |
}, |
60 | 65 |
error => { |
61 | 66 |
this.errorMessage = 'Failed to load the report results!'; |
67 |
this.loadingMessage = ''; |
|
62 | 68 |
}, |
63 | 69 |
() => { |
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; |
|
70 |
this.errorMessage = ''; |
|
71 |
this.loadingMessage = ''; |
|
72 |
|
|
73 |
this.totalPages = Math.ceil( |
|
74 |
+this.repoResponse.ReportDefinition.Filters |
|
75 |
.ReportAttribute.filter(x => x['Name'] === 'ReportItemCount')[0].Value / this.pageSize); |
|
76 |
if ( this.totalPages === 0 ) { |
|
77 |
this.infoMessage = 'No results were found'; |
|
78 |
} |
|
79 |
|
|
80 |
if (this.repoResponse.ReportDefinition && this.repoResponse.ReportDefinition.Filters && |
|
81 |
this.repoResponse.ReportDefinition.Filters.ReportAttribute) { |
|
82 |
|
|
83 |
if (this.repoResponse.Report && this.repoResponse.ReportDefinition.Filters.UsageDateRange && |
|
84 |
this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin && |
|
85 |
this.repoResponse.ReportDefinition.Filters.UsageDateRange.End) { |
|
86 |
this.coveredPeriod = this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin + ' to '; |
|
87 |
this.coveredPeriod = this.coveredPeriod + this.repoResponse.ReportDefinition.Filters.UsageDateRange.End; |
|
88 |
} else { |
|
89 |
let defaultDatePeriod = this.repoResponse.Exception.filter(x => x['Message'] === 'Unspecified Date Arguments'); |
|
90 |
|
|
91 |
this.coveredPeriod = defaultDatePeriod[0].Data.split(':')[1].trim() + ' to '; |
|
92 |
this.coveredPeriod = this.coveredPeriod + defaultDatePeriod[1].Data.split(':')[1].trim() + ' (default)'; |
|
93 |
} |
|
94 |
|
|
67 | 95 |
} 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)'; |
|
96 |
this.repoResponse = null; |
|
70 | 97 |
} |
71 | 98 |
} |
72 | 99 |
); |
73 | 100 |
|
74 | 101 |
} |
75 | 102 |
|
76 |
transformItem(url: string) { |
|
77 |
const temp = url.split(';'); |
|
103 |
|
|
104 |
getPageSize(num: string){ |
|
105 |
this.pageSize = +num; |
|
106 |
this.page = 0; |
|
107 |
this.getReportResponse(); |
|
108 |
} |
|
109 |
|
|
110 |
goToNextPage(){ |
|
111 |
if( (this.page+1) < this.totalPages) { |
|
112 |
this.page++; |
|
113 |
console.log(`Get me page ${this.page}!`); |
|
114 |
this.getReportResponse(); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
goToPreviousPage(){ |
|
119 |
if(this.page > 0) { |
|
120 |
this.page--; |
|
121 |
console.log(`Get me page ${this.page}!`); |
|
122 |
this.getReportResponse(); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
displayItemPerformance(i: number) { |
|
127 |
if (this.selectedItemIndex === i) { |
|
128 |
this.selectedItemIndex = null; |
|
129 |
} else { |
|
130 |
this.selectedItemIndex = i; |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
transformItem(urls: string) { |
|
135 |
/*const temp = urls.split(';'); |
|
78 | 136 |
let output = ''; |
79 | 137 |
for (let u of temp) { |
80 |
if (output.length === 0) {
|
|
138 |
if (output.length > 0) {
|
|
81 | 139 |
output = output + '\n'; |
82 | 140 |
} |
83 |
output = output + u.replace(/\\/g,''); |
|
141 |
output = output + u.replace(/\\/g,'').trim(); |
|
142 |
}*/ |
|
143 |
return urls.split(';'); |
|
144 |
} |
|
145 |
|
|
146 |
getBg(i: number) { |
|
147 |
if (i % 2 === 0) { |
|
148 |
console.log('true!'); |
|
149 |
return 'background-color:white;'; |
|
84 | 150 |
} |
85 |
return output; |
|
86 | 151 |
} |
87 | 152 |
|
88 | 153 |
} |
Also available in: Unified diff
almost ready for release