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
|
loadingMessage: string;
|
15
|
errorMessage: string;
|
16
|
infoMessage: string;
|
17
|
|
18
|
repoResponse: ReportResponse;
|
19
|
coveredPeriod: string;
|
20
|
params: URLSearchParams;
|
21
|
page:number;
|
22
|
pageSize:number;
|
23
|
totalPages:number;
|
24
|
selectedItemIndex: number;
|
25
|
|
26
|
constructor(private route: ActivatedRoute,
|
27
|
private authService: AuthenticationService,
|
28
|
private usageService: UsagestatsService) {}
|
29
|
|
30
|
ngOnInit() {
|
31
|
this.page = 0;
|
32
|
this.pageSize = 10;
|
33
|
this.readParams();
|
34
|
}
|
35
|
|
36
|
readParams() {
|
37
|
this.params = new URLSearchParams();
|
38
|
|
39
|
this.route.queryParams.subscribe( qparams => {
|
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']);
|
49
|
});
|
50
|
|
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(
|
62
|
responseWrapper => {
|
63
|
this.repoResponse = responseWrapper.ReportResponse;
|
64
|
},
|
65
|
error => {
|
66
|
this.errorMessage = 'Failed to load the report results!';
|
67
|
this.loadingMessage = '';
|
68
|
},
|
69
|
() => {
|
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
|
|
95
|
} else {
|
96
|
this.repoResponse = null;
|
97
|
}
|
98
|
}
|
99
|
);
|
100
|
|
101
|
}
|
102
|
|
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(';');
|
136
|
let output = '';
|
137
|
for (let u of temp) {
|
138
|
if (output.length > 0) {
|
139
|
output = output + '\n';
|
140
|
}
|
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;';
|
150
|
}
|
151
|
}
|
152
|
|
153
|
}
|