1
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2
|
import { PiwikService } from '../../services/piwik.service';
|
3
|
import { PiwikInfo } from '../../domain/typeScriptClasses';
|
4
|
import { enabledMetricsError, enablingMetrics, loadingReposMessage,
|
5
|
reposRetrievalError } from '../../domain/shared-messages';
|
6
|
import { ConfirmationDialogComponent } from '../../shared/reusablecomponents/confirmation-dialog.component';
|
7
|
|
8
|
@Component ({
|
9
|
selector: 'app-admin-metrics',
|
10
|
templateUrl: 'adminPg-metrics.component.html'
|
11
|
})
|
12
|
|
13
|
export class AdminPgMetricsComponent implements OnInit {
|
14
|
piwiks: PiwikInfo[] = [];
|
15
|
errorMessage: string;
|
16
|
loadingMessage: string;
|
17
|
|
18
|
modalTitle = 'Approval Confirmation';
|
19
|
modalButton = 'Yes, validate';
|
20
|
isModalShown: boolean;
|
21
|
|
22
|
@ViewChild('confirmApprovalModal')
|
23
|
public confirmApprovalModal: ConfirmationDialogComponent;
|
24
|
|
25
|
constructor(private piwikService: PiwikService) {}
|
26
|
|
27
|
ngOnInit() {
|
28
|
this.getPiwiks();
|
29
|
this.isModalShown = false;
|
30
|
}
|
31
|
|
32
|
|
33
|
getPiwiks() {
|
34
|
this.loadingMessage = loadingReposMessage;
|
35
|
this.piwikService.getPiwikSitesForRepos()
|
36
|
.subscribe (
|
37
|
piwiks => this.piwiks = piwiks.sort( function(a, b) {
|
38
|
if (a.repositoryName < b.repositoryName) {
|
39
|
return -1;
|
40
|
} else if (a.repositoryName > b.repositoryName) {
|
41
|
return 1;
|
42
|
} else {
|
43
|
return 0;
|
44
|
}
|
45
|
} ),
|
46
|
error => {
|
47
|
console.log(error);
|
48
|
this.loadingMessage = '';
|
49
|
this.errorMessage = reposRetrievalError;
|
50
|
},
|
51
|
() => {
|
52
|
this.loadingMessage = '';
|
53
|
}
|
54
|
);
|
55
|
}
|
56
|
|
57
|
confirmApproval(repoId: string) {
|
58
|
this.confirmApprovalModal.ids = [repoId];
|
59
|
this.confirmApprovalModal.showModal();
|
60
|
}
|
61
|
|
62
|
confirmedApproval(ids: string[]) {
|
63
|
const id = ids[0];
|
64
|
console.log(`approving validation of piwik for repo with id: ${id}`);
|
65
|
this.approvePiwik(id);
|
66
|
}
|
67
|
|
68
|
approvePiwik(id: string) {
|
69
|
this.loadingMessage = enablingMetrics;
|
70
|
this.errorMessage = '';
|
71
|
|
72
|
/*this.piwikService.approvePiwikSite(id).subscribe(*/
|
73
|
this.piwikService.markPiwikSiteAsValidated(id).subscribe(
|
74
|
response => console.log(`approvePiwikSite responded: ${JSON.stringify(response)}`),
|
75
|
error => {
|
76
|
console.log(error);
|
77
|
this.loadingMessage = '';
|
78
|
this.errorMessage = enabledMetricsError;
|
79
|
},
|
80
|
() => {
|
81
|
this.loadingMessage = '';
|
82
|
this.errorMessage = '';
|
83
|
this.getPiwiks();
|
84
|
}
|
85
|
);
|
86
|
}
|
87
|
|
88
|
}
|