Project

General

Profile

1
/**
2
 * Created by myrto on 11/24/17.
3
 */
4
import { Component, OnInit } from '@angular/core';
5
import { PiwikInfo } from '../../domain/typeScriptClasses';
6
import { ActivatedRoute, Router } from '@angular/router';
7
import { PiwikService } from '../../services/piwik.service';
8
import { AuthenticationService } from '../../services/authentication.service';
9

    
10
@Component ({
11
  selector: 'app-metrics-instructions',
12
  templateUrl: 'metrics-instructions.component.html'
13
})
14

    
15
export class MetricsInstructionsComponent implements OnInit {
16
  piwik: PiwikInfo;
17
  errorMessage: string;
18

    
19
  constructor(
20
    private route: ActivatedRoute,
21
    private router: Router,
22
    private piwikService: PiwikService,
23
    private authService: AuthenticationService) {}
24

    
25
  ngOnInit() {
26
    this.getPiwik();
27
    let body = document.getElementsByTagName('body')[0];
28
    body.classList.remove("top_bar_active");   //remove the class
29
  }
30

    
31
  getPiwik(): void {
32
    const id = this.route.snapshot.paramMap.get('id');
33
    this.piwikService.getPiwikInfo(id).subscribe(
34
      piwik => this.piwik = piwik,
35
      error => console.log(error),
36
      () => {
37
        if ( this.authService.activateFrontAuthorization &&
38
             (this.authService.getUserEmail() !== this.piwik.requestorEmail.trim()) ) {
39
          this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
40
        }
41
      }
42
    );
43
  }
44

    
45
}
(4-4/17)