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 { FormBuilder, FormGroup } from '@angular/forms';
|
7
|
|
8
|
@Component({
|
9
|
selector: 'metrics-usagestats-report-results',
|
10
|
templateUrl: 'metrics-usagestats-report-results.component.html',
|
11
|
styleUrls: ['metrics-usagestats-report-results.component.css']
|
12
|
})
|
13
|
export class MetricsUsagestatsReportResultsComponent implements OnInit {
|
14
|
|
15
|
loadingMessage: string;
|
16
|
errorMessage: string;
|
17
|
infoMessage: string;
|
18
|
|
19
|
repoResponse: ReportResponse;
|
20
|
coveredPeriod: string;
|
21
|
params: URLSearchParams;
|
22
|
page: number;
|
23
|
pageSize: number;
|
24
|
totalPages: number;
|
25
|
selectedItemIndex: number;
|
26
|
|
27
|
pageSizeSelect: FormGroup;
|
28
|
chosenReport: string;
|
29
|
|
30
|
constructor(private route: ActivatedRoute,
|
31
|
private authService: AuthenticationService,
|
32
|
private usageService: UsagestatsService,
|
33
|
private fb: FormBuilder) {}
|
34
|
|
35
|
ngOnInit() {
|
36
|
this.page = 0;
|
37
|
this.pageSize = 10;
|
38
|
this.readParams();
|
39
|
this.pageSizeSelect = this.fb.group({selectPageSize: ['']});
|
40
|
}
|
41
|
|
42
|
readParams() {
|
43
|
this.params = new URLSearchParams();
|
44
|
|
45
|
this.route.queryParams.subscribe( qparams => {
|
46
|
this.params.append('Report', qparams['report']);
|
47
|
this.params.append('Release', '4');
|
48
|
this.params.append('RequestorID', this.authService.getUserEmail());
|
49
|
this.params.append('BeginDate', qparams['beginDate']);
|
50
|
this.params.append('EndDate', qparams['endDate']);
|
51
|
this.params.append('RepositoryIdentifier', qparams['repoId']);
|
52
|
this.params.append('ItemIdentifier', qparams['itemIdentifier']);
|
53
|
this.params.append('ItemDataType', qparams['itemIdentifier']);
|
54
|
this.params.append('Granularity', qparams['granularity']);
|
55
|
});
|
56
|
|
57
|
this.chosenReport = this.params.get('Report');
|
58
|
this.getReportResponse();
|
59
|
}
|
60
|
|
61
|
getReportResponse() {
|
62
|
this.errorMessage = '';
|
63
|
this.loadingMessage = 'Loading results...';
|
64
|
this.infoMessage = '';
|
65
|
this.selectedItemIndex = null;
|
66
|
this.repoResponse = null;
|
67
|
|
68
|
this.usageService.getReportResponse(this.page.toString(), this.pageSize.toString(), this.params).subscribe(
|
69
|
responseWrapper => {
|
70
|
this.repoResponse = responseWrapper.ReportResponse;
|
71
|
},
|
72
|
error => {
|
73
|
this.errorMessage = 'Failed to load the report results!';
|
74
|
this.loadingMessage = '';
|
75
|
},
|
76
|
() => {
|
77
|
this.errorMessage = '';
|
78
|
this.loadingMessage = '';
|
79
|
|
80
|
this.pageSizeSelect.get('selectPageSize').setValue(this.pageSize);
|
81
|
this.pageSizeSelect.get('selectPageSize').updateValueAndValidity();
|
82
|
|
83
|
this.totalPages = Math.ceil(
|
84
|
+this.repoResponse.ReportDefinition.Filters
|
85
|
.ReportAttribute.filter(x => x['Name'] === 'ReportItemCount')[0].Value / this.pageSize);
|
86
|
if ( this.totalPages === 0 ) {
|
87
|
this.infoMessage = 'No results were found';
|
88
|
}
|
89
|
|
90
|
if (this.repoResponse.ReportDefinition && this.repoResponse.ReportDefinition.Filters &&
|
91
|
this.repoResponse.ReportDefinition.Filters.ReportAttribute) {
|
92
|
|
93
|
if (this.repoResponse.Report && this.repoResponse.ReportDefinition.Filters.UsageDateRange &&
|
94
|
this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin &&
|
95
|
this.repoResponse.ReportDefinition.Filters.UsageDateRange.End) {
|
96
|
this.coveredPeriod = this.repoResponse.ReportDefinition.Filters.UsageDateRange.Begin + ' to ';
|
97
|
this.coveredPeriod = this.coveredPeriod + this.repoResponse.ReportDefinition.Filters.UsageDateRange.End;
|
98
|
} else {
|
99
|
const defaultDatePeriod = this.repoResponse.Exception.filter(x => x['Message'] === 'Unspecified Date Arguments');
|
100
|
|
101
|
this.coveredPeriod = defaultDatePeriod[0].Data.split(':')[1].trim() + ' to ';
|
102
|
this.coveredPeriod = this.coveredPeriod + defaultDatePeriod[1].Data.split(':')[1].trim() + ' (default)';
|
103
|
}
|
104
|
|
105
|
} else {
|
106
|
this.repoResponse = null;
|
107
|
}
|
108
|
}
|
109
|
);
|
110
|
|
111
|
}
|
112
|
|
113
|
|
114
|
getPageSize() {
|
115
|
this.pageSize = +(this.pageSizeSelect.get('selectPageSize').value);
|
116
|
this.page = 0;
|
117
|
this.getReportResponse();
|
118
|
}
|
119
|
|
120
|
goToNextPage() {
|
121
|
if ( (this.page + 1) < this.totalPages) {
|
122
|
this.page++;
|
123
|
console.log(`Get me page ${this.page}!`);
|
124
|
this.getReportResponse();
|
125
|
}
|
126
|
}
|
127
|
|
128
|
goToPreviousPage() {
|
129
|
if (this.page > 0) {
|
130
|
this.page--;
|
131
|
console.log(`Get me page ${this.page}!`);
|
132
|
this.getReportResponse();
|
133
|
}
|
134
|
}
|
135
|
|
136
|
displayItemPerformance(i: number) {
|
137
|
if (this.selectedItemIndex === i) {
|
138
|
this.selectedItemIndex = null;
|
139
|
} else {
|
140
|
this.selectedItemIndex = i;
|
141
|
}
|
142
|
}
|
143
|
|
144
|
transformItem(itemIdentifiers: any[]) {
|
145
|
let field: string;
|
146
|
if (this.chosenReport === 'RR1') {
|
147
|
field = 'URL';
|
148
|
} else {
|
149
|
field = 'URLs';
|
150
|
}
|
151
|
const i = itemIdentifiers.findIndex(x => x['Type'] === field);
|
152
|
if ( i > -1 ) {
|
153
|
const urls = itemIdentifiers[i]['Value'];
|
154
|
return urls.split(';');
|
155
|
}
|
156
|
return '';
|
157
|
}
|
158
|
|
159
|
}
|