app.component.ts 1.75 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';
10
import { UserService } from './services/user.service';
Rron Jahja's avatar
Rron Jahja committed
11
12
13
14
15
16
17

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
18
  username="";
19
  isLoginPage = false;
20

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

  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
48
49
50
    private statusBar: StatusBar,
    public restService: RestService,
    private storage: Storage,
51
52
53
    private router: Router,
    public userService: UserService) {
    this.username = this.userService.getUsername();
54

Rron Jahja's avatar
Rron Jahja committed
55
    this.initializeApp();
56
57
58
59
60
61
62

    let href = window.location.pathname
    if(href === "/login") {
      this.restService.isLoginPage = true;
    } else {
      this.restService.isLoginPage = false;
    }
63
64
65
66
67
68
69
    this.storage.get('token').then((token) => {
      if(token === "") {
        this.router.navigateByUrl('/login');
      } else {
        this.restService.isUserLoggedIn = true;
      }
    });
Rron Jahja's avatar
Rron Jahja committed
70
71
72
73
74
75
76
77
78
  }

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