app.component.ts 1.91 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
    {
      title: 'My Reservation',
      url: '/myreservation',
Priyanka Upadhye's avatar
Priyanka Upadhye committed
30
      icon: 'cart'
gap95's avatar
gap95 committed
31
32
33
    }, {
      title: 'My Rides',
      url: '/hirebike',
Priyanka Upadhye's avatar
Priyanka Upadhye committed
34
      icon: 'bicycle'
35
    },
36
    {
gap95's avatar
gap95 committed
37
      title: 'Ride History',
gap95's avatar
gap95 committed
38
      url: '/ridehistory',
39
      icon: 'clipboard'
gap95's avatar
gap95 committed
40
    },
41
  
Priyanka Upadhye's avatar
Priyanka Upadhye committed
42
43
44
45
46
    {
      title: 'Help',
      url: '/help-line',
      icon: 'call'
    },
Rron Jahja's avatar
Rron Jahja committed
47
    {
48
49
50
      title: 'Logout',
      url: '/login',
      icon: 'exit'
Rron Jahja's avatar
Rron Jahja committed
51
52
    }
  ];
53
  
Rron Jahja's avatar
Rron Jahja committed
54
55
56
57

  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
58
59
60
    private statusBar: StatusBar,
    public restService: RestService,
    private storage: Storage,
61
62
63
    private router: Router,
    public userService: UserService) {
    this.username = this.userService.getUsername();
64

Rron Jahja's avatar
Rron Jahja committed
65
    this.initializeApp();
66
67
68
69
70
71
72

    let href = window.location.pathname
    if(href === "/login") {
      this.restService.isLoginPage = true;
    } else {
      this.restService.isLoginPage = false;
    }
73
74
75
76
77
78
79
    this.storage.get('token').then((token) => {
      if(token === "") {
        this.router.navigateByUrl('/login');
      } else {
        this.restService.isUserLoggedIn = true;
      }
    });
Rron Jahja's avatar
Rron Jahja committed
80
81
82
83
84
85
86
87
88
  }

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