Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { UsageStatsSummary } from '../../domain/typeScriptClasses';
3
import { AuthenticationService } from '../../services/authentication.service';
4
import { StatisticsService } from '../../services/statistics.service';
5
import { Router } from '@angular/router';
6

    
7
@Component ({
8
  selector: 'app-landing',
9
  templateUrl: './landing.component.html'
10
})
11

    
12
export class LandingComponent implements OnInit {
13

    
14
  statisticsNumbers: UsageStatsSummary;
15
  inBeta: boolean;
16

    
17

    
18
  constructor(private authService: AuthenticationService,
19
              private statsService: StatisticsService,
20
              private router: Router) { }
21

    
22
  ngOnInit() {
23
    this.getStatisticsNumbers();
24

    
25
    const baseUrl = window.location.origin;
26
    this.inBeta = ( baseUrl.includes('beta') || baseUrl.includes('athenarc') );
27
  }
28

    
29

    
30
  login() {
31
    this.authService.loginWithState();
32
  }
33

    
34
  getStatisticsNumbers() {
35
    this.statsService.getStatisticsNumbers().subscribe(
36
      res => {
37
        this.statisticsNumbers = res;
38
        this.statisticsNumbers.lastYearUsagestats = JSON.parse(res['lastYearUsagestats'].toString());
39
      },
40
      error => console.log(error),
41
      () => {
42
        console.log('statisticsNumbers is', JSON.stringify(this.statisticsNumbers));
43
      }
44
    );
45
  }
46

    
47
  goToPage(pageUrl: string) {
48
    if (this.authService.getIsUserLoggedIn()) {
49
      this.router.navigate([pageUrl]);
50
    } else {
51
      this.authService.redirectUrl = pageUrl;
52
      this.login();
53
    }
54
  }
55

    
56
}
(2-2/2)