app.component.ts 1.51 KB
Newer Older
Rron Jahja's avatar
Rron Jahja committed
1
2
3
4
5
import { Component } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
6
7
8
9
import { Storage } from '@ionic/storage';
import { Router } from '@angular/router';

import { RestService } from './rest.service';
Rron Jahja's avatar
Rron Jahja committed
10
11
12
13
14
15
16

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
17

18
  isLoginPage = false;
19

Rron Jahja's avatar
Rron Jahja committed
20
21
22
23
24
25
  public appPages = [
    {
      title: 'Home',
      url: '/home',
      icon: 'home'
    },
26
27
28
29
30
    {
      title: 'My Reservation',
      url: '/myreservation',
      icon: 'clipboard'
    },
Rron Jahja's avatar
Rron Jahja committed
31
    {
32
33
34
      title: 'Logout',
      url: '/login',
      icon: 'exit'
Rron Jahja's avatar
Rron Jahja committed
35
36
37
38
39
40
    }
  ];

  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
41
42
43
    private statusBar: StatusBar,
    public restService: RestService,
    private storage: Storage,
44
45
    private router: Router) {

Rron Jahja's avatar
Rron Jahja committed
46
    this.initializeApp();
47
48
49
50
51
52
53

    let href = window.location.pathname
    if(href === "/login") {
      this.restService.isLoginPage = true;
    } else {
      this.restService.isLoginPage = false;
    }
54
55
56
57
58
59
60
    this.storage.get('token').then((token) => {
      if(token === "") {
        this.router.navigateByUrl('/login');
      } else {
        this.restService.isUserLoggedIn = true;
      }
    });
Rron Jahja's avatar
Rron Jahja committed
61
62
63
64
65
66
67
68
69
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }
}