/
app.ts
executable file
·123 lines (104 loc) · 3.74 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { Component, ViewChild } from '@angular/core';
import { Events, ionicBootstrap, MenuController, Nav, Platform } from 'ionic-angular';
import { Splashscreen, StatusBar } from 'ionic-native';
import { AccountPage } from './pages/account/account';
import { ConferenceData } from './providers/conference-data';
import { LoginPage } from './pages/login/login';
import { SignupPage } from './pages/signup/signup';
import { TabsPage } from './pages/tabs/tabs';
import { TutorialPage } from './pages/tutorial/tutorial';
import { UserData } from './providers/user-data';
interface PageObj {
title: string;
component: any;
icon: string;
index?: number;
}
@Component({
templateUrl: 'app.html'
})
class ConferenceApp {
// the root nav is a child of the root app component
// @ViewChild(Nav) gets a reference to the app's root nav
@ViewChild(Nav) nav: Nav;
// List of pages that can be navigated to from the left menu
// the left menu only works after login
// the login page disables the left menu
appPages: PageObj[] = [
{ title: 'Schedule', component: TabsPage, icon: 'calendar' },
{ title: 'Speakers', component: TabsPage, index: 1, icon: 'contacts' },
{ title: 'Map', component: TabsPage, index: 2, icon: 'map' },
{ title: 'About', component: TabsPage, index: 3, icon: 'information-circle' },
];
loggedInPages: PageObj[] = [
{ title: 'Account', component: AccountPage, icon: 'person' },
{ title: 'Logout', component: TabsPage, icon: 'log-out' }
];
loggedOutPages: PageObj[] = [
{ title: 'Login', component: LoginPage, icon: 'log-in' },
{ title: 'Signup', component: SignupPage, icon: 'person-add' }
];
rootPage: any = TutorialPage;
constructor(
private events: Events,
private userData: UserData,
private menu: MenuController,
platform: Platform,
confData: ConferenceData
) {
// Call any initial plugins when ready
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
});
// load the conference data
confData.load();
// decide which menu items should be hidden by current login status stored in local storage
this.userData.hasLoggedIn().then((hasLoggedIn) => {
this.enableMenu(hasLoggedIn === 'true');
});
this.listenToLoginEvents();
}
openPage(page: PageObj) {
// the nav component was found using @ViewChild(Nav)
// reset the nav to remove previous pages and only have this page
// we wouldn't want the back button to show in this scenario
if (page.index) {
this.nav.setRoot(page.component, {tabIndex: page.index});
} else {
this.nav.setRoot(page.component);
}
if (page.title === 'Logout') {
// Give the menu time to close before changing to logged out
setTimeout(() => {
this.userData.logout();
}, 1000);
}
}
listenToLoginEvents() {
this.events.subscribe('user:login', () => {
this.enableMenu(true);
});
this.events.subscribe('user:signup', () => {
this.enableMenu(true);
});
this.events.subscribe('user:logout', () => {
this.enableMenu(false);
});
}
enableMenu(loggedIn) {
this.menu.enable(loggedIn, 'loggedInMenu');
this.menu.enable(!loggedIn, 'loggedOutMenu');
}
}
// Pass the main App component as the first argument
// Pass any providers for your app in the second argument
// Set any config for your app as the third argument, see the docs for
// more ways to configure your app:
// http://ionicframework.com/docs/v2/api/config/Config/
// Place the tabs on the bottom for all platforms
// See the theming docs for the default values:
// http://ionicframework.com/docs/v2/theming/platform-specific-styles/
ionicBootstrap(ConferenceApp, [ConferenceData, UserData], {
tabbarPlacement: 'bottom'
});