Project

General

Profile

1
import { Component, OnInit, ViewChild } from '@angular/core';
2
import { RepositoryService } from '../../services/repository.service';
3
import { PiwikInfo } from '../../domain/typeScriptClasses';
4
import { AuthenticationService } from '../../services/authentication.service';
5
import { loadingReposMessage, 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
  showSpinner: boolean;
16
  errorMessage: string;
17
  loadingMessage: string;
18

    
19
  modalTitle = "Approval Confirmation";
20
  modalButton = "Yes, validate";
21
  isModalShown: boolean;
22

    
23
  @ViewChild('confirmApprovalModal')
24
  public confirmApprovalModal: ConfirmationDialogComponent;
25

    
26
  constructor(private repoService: RepositoryService) {}
27

    
28
  ngOnInit() {
29
    this.getPiwiks();
30
    this.isModalShown = false;
31
  }
32

    
33

    
34
  /* NEEDS TO CALL GET PIWIK INFO INSTEAD!! */
35
  getPiwiks(){
36
    this.showSpinner = true;
37
    this.loadingMessage = loadingReposMessage;
38
    this.repoService.getPiwikSitesForRepos()
39
      .subscribe(
40
        piwiks => this.piwiks = piwiks.sort( function(a,b){
41
          if(a.repositoryName<b.repositoryName){
42
            return -1;
43
          } else if(a.repositoryName>b.repositoryName){
44
            return 1;
45
          } else {
46
            return 0;
47
          }
48
        } ),
49
        error => {
50
          console.log(error);
51
          this.showSpinner = false;
52
          this.loadingMessage = '';
53
          this.errorMessage = reposRetrievalError;
54
        },
55
        () => {
56
          this.showSpinner = false;
57
          this.loadingMessage = '';
58
        }
59
      );
60
  }
61

    
62
  /*NOT SURE IF THESE PARAMETERS ARE THE CORRECT ONES*/
63
  confirmApproval(repoId: string) {
64
    this.confirmApprovalModal.ids = [repoId];
65
    this.confirmApprovalModal.showModal();
66
  }
67

    
68
  confirmedApproval(ids: string[]){
69
    let id = ids[0];
70
    console.log(`approved validation of piwik for repo with id: ${id}`);
71
  }
72

    
73
}
(4-4/7)