@@ -2,14 +2,21 @@ import { Component, ViewChild } from '@angular/core';
22import { Nav , Platform , AlertController } from 'ionic-angular' ;
33import { StatusBar } from '@ionic-native/status-bar' ;
44import { SplashScreen } from '@ionic-native/splash-screen' ;
5+
56import { TabsService } from '../providers/tabs-service' ;
67import { UserService } from '../providers/user-service' ;
8+ import { MessageService } from '../providers/message-service' ;
79import { Tab } from '../classes/tab' ;
10+ import { User } from '../classes/user' ;
811
912
1013@Component ( {
1114 templateUrl : 'app.html' ,
12- providers : [ TabsService , UserService ]
15+ providers : [
16+ TabsService ,
17+ UserService ,
18+ MessageService
19+ ]
1320} )
1421export class MyApp {
1522 @ViewChild ( Nav ) nav : Nav ;
@@ -18,7 +25,18 @@ export class MyApp {
1825
1926 tabs : Tab [ ] ;
2027
21- constructor ( public platform : Platform , statusBar : StatusBar , splashScreen : SplashScreen , private tabsService : TabsService , private userService : UserService , private alertCtrl : AlertController ) {
28+ user : User ;
29+ messagesCount : 0 ;
30+
31+ constructor (
32+ public platform : Platform ,
33+ statusBar : StatusBar ,
34+ splashScreen : SplashScreen ,
35+ private tabsService : TabsService ,
36+ private userService : UserService ,
37+ private messageService : MessageService ,
38+ private alertCtrl : AlertController
39+ ) {
2240 platform . ready ( ) . then ( ( ) => {
2341 // Okay, so the platform is ready and our plugins are available.
2442 // Here you can do any higher level native things you might need.
@@ -32,6 +50,7 @@ export class MyApp {
3250
3351 ngAfterViewInit ( ) {
3452 console . log ( 'ng after view init' ) ;
53+
3554 this . tabs = this . tabsService . getTabs ( ) ;
3655 }
3756
@@ -42,6 +61,32 @@ export class MyApp {
4261 } ) ;
4362 }
4463
64+ gotoUserPage ( loginName : String ) {
65+ console . log ( 'goto user' , loginName ) ;
66+ this . nav . setRoot ( 'user' , { loginName : loginName } )
67+ }
68+
69+ gotoMessagePage ( ) {
70+ console . log ( 'go to message page' )
71+ this . nav . setRoot ( 'message' ) ;
72+ }
73+
74+ getMessageCount ( ) {
75+ this . messageService . getMessageCount ( ) . then ( ( response ) => {
76+ this . messagesCount = response . data ;
77+ //setBadge($scope.messagesCount);
78+ } , function ( response ) {
79+ //$log.log('get messages count fail', response);
80+ } ) ;
81+ } ;
82+
83+ // login action callback
84+ loginCallback ( user : User ) {
85+ console . log ( 'login callback' , arguments ) ;
86+ this . user = user ;
87+ this . getMessageCount ( ) ;
88+ }
89+
4590 login ( ) {
4691 console . log ( 'login' ) ;
4792 let alert = this . alertCtrl . create ( {
@@ -67,10 +112,9 @@ export class MyApp {
67112 console . log ( data ) ;
68113 if ( data . token ) {
69114 this . userService . login ( data . token ) . then ( ( response ) => {
70- console . log ( 'done' )
115+ this . loginCallback ( response ) ;
71116 } ) ;
72117 }
73-
74118 }
75119 }
76120 ]
0 commit comments