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