1 |
56889
|
antonis.le
|
import {Component, Input, OnInit, ViewChild} from '@angular/core';
|
2 |
54479
|
myrto.kouk
|
import { PiwikService } from '../../services/piwik.service';
|
3 |
|
|
import { PiwikInfo } from '../../domain/typeScriptClasses';
|
4 |
54747
|
myrto.kouk
|
import {
|
5 |
|
|
enabledMetricsError,
|
6 |
|
|
enablingMetrics,
|
7 |
|
|
loadingReposMessage,
|
8 |
|
|
reposRetrievalError,
|
9 |
|
|
validatePiwikSiteSuccess
|
10 |
|
|
} from '../../domain/shared-messages';
|
11 |
54479
|
myrto.kouk
|
import { ConfirmationDialogComponent } from '../../shared/reusablecomponents/confirmation-dialog.component';
|
12 |
56889
|
antonis.le
|
import {URLParameter} from '../../domain/url-parameter';
|
13 |
|
|
import {FormBuilder, FormGroup} from '@angular/forms';
|
14 |
|
|
import {RepositoryService} from '../../services/repository.service';
|
15 |
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
16 |
|
|
import {PiwikInfoPage} from '../../domain/page-content';
|
17 |
|
|
import {environment} from '../../../environments/environment';
|
18 |
54479
|
myrto.kouk
|
|
19 |
|
|
@Component ({
|
20 |
|
|
selector: 'app-admin-metrics',
|
21 |
|
|
templateUrl: 'adminPg-metrics.component.html'
|
22 |
|
|
})
|
23 |
|
|
|
24 |
|
|
export class AdminPgMetricsComponent implements OnInit {
|
25 |
56889
|
antonis.le
|
piwiks: PiwikInfoPage;
|
26 |
|
|
urlParams: URLParameter[] = [];
|
27 |
54479
|
myrto.kouk
|
errorMessage: string;
|
28 |
54747
|
myrto.kouk
|
successMessage: string;
|
29 |
54479
|
myrto.kouk
|
loadingMessage: string;
|
30 |
|
|
|
31 |
|
|
modalTitle = 'Approval Confirmation';
|
32 |
|
|
modalButton = 'Yes, validate';
|
33 |
|
|
isModalShown: boolean;
|
34 |
|
|
|
35 |
56889
|
antonis.le
|
formPrepare = {
|
36 |
|
|
searchField: '',
|
37 |
|
|
orderField: 'REPOSITORY_NAME',
|
38 |
|
|
order: 'ASC',
|
39 |
|
|
page: '0',
|
40 |
|
|
quantity: '25',
|
41 |
|
|
from: '0'
|
42 |
|
|
};
|
43 |
|
|
|
44 |
|
|
dataForm: FormGroup;
|
45 |
|
|
|
46 |
61424
|
stefania.m
|
@ViewChild('confirmApprovalModal', { static: true })
|
47 |
54479
|
myrto.kouk
|
public confirmApprovalModal: ConfirmationDialogComponent;
|
48 |
56889
|
antonis.le
|
private pageTotal: number;
|
49 |
|
|
private piwiksTotal: number;
|
50 |
56891
|
stefania.m
|
public pages = [];
|
51 |
56889
|
antonis.le
|
private offset = 2;
|
52 |
54479
|
myrto.kouk
|
|
53 |
56889
|
antonis.le
|
constructor(private piwikService: PiwikService,
|
54 |
|
|
private fb: FormBuilder,
|
55 |
|
|
private route: ActivatedRoute,
|
56 |
|
|
private router: Router) {}
|
57 |
54479
|
myrto.kouk
|
|
58 |
|
|
ngOnInit() {
|
59 |
56889
|
antonis.le
|
this.dataForm = this.fb.group(this.formPrepare);
|
60 |
|
|
this.urlParams = [];
|
61 |
|
|
this.route.queryParams
|
62 |
|
|
.subscribe(params => {
|
63 |
|
|
for (const i in params) {
|
64 |
|
|
this.dataForm.get(i).setValue(params[i]);
|
65 |
|
|
}
|
66 |
|
|
for (let i in this.dataForm.controls) {
|
67 |
|
|
if (this.dataForm.get(i).value) {
|
68 |
|
|
this.urlParams.push({key: i, value: [this.dataForm.get(i).value]});
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
this.handleChange();
|
72 |
|
|
},
|
73 |
|
|
error => this.errorMessage = <any>error
|
74 |
|
|
);
|
75 |
|
|
|
76 |
54479
|
myrto.kouk
|
this.isModalShown = false;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
56889
|
antonis.le
|
downloadCSV() {
|
80 |
|
|
const url = environment.API_ENDPOINT;
|
81 |
|
|
let csvUrlParams = '/piwik/getPiwikSitesForRepos/csv?';
|
82 |
|
|
for (let i in this.dataForm.controls) {
|
83 |
|
|
if (this.dataForm.get(i).value !== '') {
|
84 |
|
|
csvUrlParams = csvUrlParams.concat(i, '=', this.dataForm.get(i).value, '&');
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
csvUrlParams = csvUrlParams.split('&page=')[0];
|
88 |
|
|
window.open(url + csvUrlParams, '_blank');
|
89 |
|
|
}
|
90 |
54479
|
myrto.kouk
|
|
91 |
|
|
getPiwiks() {
|
92 |
|
|
this.loadingMessage = loadingReposMessage;
|
93 |
56889
|
antonis.le
|
this.piwikService.getPiwikSitesForRepos(this.urlParams)
|
94 |
|
|
.subscribe(
|
95 |
|
|
piwiks => {
|
96 |
|
|
this.piwiks = piwiks;
|
97 |
|
|
this.getPages();
|
98 |
|
|
},
|
99 |
54479
|
myrto.kouk
|
error => {
|
100 |
|
|
console.log(error);
|
101 |
|
|
this.loadingMessage = '';
|
102 |
|
|
this.errorMessage = reposRetrievalError;
|
103 |
|
|
},
|
104 |
|
|
() => {
|
105 |
|
|
this.loadingMessage = '';
|
106 |
54747
|
myrto.kouk
|
window.scroll(1, 1);
|
107 |
54479
|
myrto.kouk
|
}
|
108 |
|
|
);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
confirmApproval(repoId: string) {
|
112 |
|
|
this.confirmApprovalModal.ids = [repoId];
|
113 |
|
|
this.confirmApprovalModal.showModal();
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
confirmedApproval(ids: string[]) {
|
117 |
|
|
const id = ids[0];
|
118 |
|
|
console.log(`approving validation of piwik for repo with id: ${id}`);
|
119 |
|
|
this.approvePiwik(id);
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
approvePiwik(id: string) {
|
123 |
|
|
this.loadingMessage = enablingMetrics;
|
124 |
|
|
this.errorMessage = '';
|
125 |
54747
|
myrto.kouk
|
this.successMessage = '';
|
126 |
54479
|
myrto.kouk
|
|
127 |
|
|
/*this.piwikService.approvePiwikSite(id).subscribe(*/
|
128 |
|
|
this.piwikService.markPiwikSiteAsValidated(id).subscribe(
|
129 |
|
|
response => console.log(`approvePiwikSite responded: ${JSON.stringify(response)}`),
|
130 |
|
|
error => {
|
131 |
|
|
console.log(error);
|
132 |
|
|
this.loadingMessage = '';
|
133 |
|
|
this.errorMessage = enabledMetricsError;
|
134 |
|
|
},
|
135 |
|
|
() => {
|
136 |
|
|
this.loadingMessage = '';
|
137 |
|
|
this.errorMessage = '';
|
138 |
54747
|
myrto.kouk
|
this.successMessage = validatePiwikSiteSuccess;
|
139 |
54479
|
myrto.kouk
|
this.getPiwiks();
|
140 |
|
|
}
|
141 |
|
|
);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
56889
|
antonis.le
|
handleChange() {
|
145 |
|
|
this.urlParams = [];
|
146 |
|
|
const map: { [name: string]: string; } = {};
|
147 |
|
|
for (let i in this.dataForm.controls) {
|
148 |
|
|
if (this.dataForm.get(i).value !== '') {
|
149 |
|
|
this.urlParams.push({key: i, value: [this.dataForm.get(i).value]});
|
150 |
|
|
map[i] = this.dataForm.get(i).value;
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
this.router.navigate([`/admin/metrics`], {queryParams: map});
|
155 |
|
|
this.getPiwiks();
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
handleChangeAndResetPage() {
|
159 |
|
|
this.dataForm.get('page').setValue(0);
|
160 |
|
|
this.dataForm.get('from').setValue(0);
|
161 |
|
|
this.handleChange();
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
getPages() {
|
165 |
|
|
let addToEndCounter = 0;
|
166 |
|
|
let addToStartCounter = 0;
|
167 |
|
|
this.pages = [];
|
168 |
|
|
this.pageTotal = Math.ceil(this.piwiks.total / (this.dataForm.get('quantity').value));
|
169 |
|
|
for ( let i = (+this.dataForm.get('page').value - this.offset); i < (+this.dataForm.get('page').value + 1 + this.offset); ++i ) {
|
170 |
|
|
if ( i < 0 ) { addToEndCounter++; }
|
171 |
|
|
if ( i >= this.pageTotal ) { addToStartCounter++; }
|
172 |
|
|
if ((i >= 0) && (i < this.pageTotal)) {
|
173 |
|
|
this.pages.push(i);
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
for ( let i = 0; i < addToEndCounter; ++i ) {
|
177 |
|
|
if (this.pages.length < this.pageTotal) {
|
178 |
|
|
this.pages.push(this.pages.length);
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
for ( let i = 0; i < addToStartCounter; ++i ) {
|
182 |
|
|
if (this.pages[0] > 0) {
|
183 |
|
|
this.pages.unshift(this.pages[0] - 1 );
|
184 |
|
|
}
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
selectPage(page) {
|
189 |
|
|
this.dataForm.get('page').setValue(page);
|
190 |
|
|
this.dataForm.get('from').setValue(((+this.dataForm.get('page').value) * (+this.dataForm.get('quantity').value)));
|
191 |
|
|
this.handleChange();
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
previousPage() {
|
195 |
|
|
if (this.dataForm.get('page').value > 0) {
|
196 |
|
|
this.dataForm.get('page').setValue(+this.dataForm.get('page').value - 1);
|
197 |
|
|
this.dataForm.get('from').setValue(+this.dataForm.get('from').value - +this.dataForm.get('quantity').value);
|
198 |
|
|
this.handleChange();
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
nextPage() {
|
203 |
|
|
// if ((this.dataForm.get('searchField').value) !== '') { this.piwiksTotal = this.piwiks.to; } else { this.piwiksTotal = this.piwiks.total; }
|
204 |
|
|
this.pageTotal = Math.ceil(this.piwiks.total / (this.dataForm.get('quantity').value)) - 1;
|
205 |
|
|
if (this.dataForm.get('page').value < this.pageTotal) {
|
206 |
|
|
this.dataForm.get('page').setValue(+this.dataForm.get('page').value + 1);
|
207 |
|
|
this.dataForm.get('from').setValue(+this.dataForm.get('from').value + +this.dataForm.get('quantity').value);
|
208 |
|
|
this.handleChange();
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
|
212 |
54479
|
myrto.kouk
|
}
|