Advertisement
Guest User

app.component

a guest
May 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Storage } from '@ionic/storage';
  2. //import { NativeStorage } from '@ionic-native/native-storage/';
  3. import { UtilsProvider } from './../providers/utils/utils';
  4. /* import others libraries */
  5. import { Component, ViewChild, TestabilityRegistry } from '@angular/core';
  6. import { Nav, Platform, LoadingController, AlertController, MenuController } from 'ionic-angular';
  7. import { StatusBar } from '@ionic-native/status-bar';
  8. import { SplashScreen } from '@ionic-native/splash-screen';
  9.  
  10. /* import providers */
  11. import { DatabaseProvider } from '../providers/database/database';
  12. import { UserProvider } from './../providers/user/user';
  13. /* import pages */
  14. import { HomePage } from '../pages/home/home';
  15. import { LoginPage } from '../pages/login/login';
  16. import { ProductPage } from '../pages/product/product';
  17. import { ClientPage } from '../pages/client/client';
  18. import { ChartPage } from '../pages/chart/chart';
  19. import {NgZone} from '@angular/core';
  20.  
  21. @Component({
  22.     templateUrl: 'app.html'
  23. })
  24. export class MyApp {
  25.     @ViewChild(Nav) nav:Nav;
  26.  
  27.     rootPage: any = null;
  28.     pages: Array<{title: string, subtitle: string, component: any, icon: any}>;
  29.    
  30.     emailu: string;
  31.     numcgc: string;
  32.     token: string;
  33.     codven: string;
  34.     user: any;
  35.  
  36.     constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private dbProvider: DatabaseProvider, public loadingCtrl: LoadingController, public alertCtrl: AlertController, private userProvider: UserProvider, private utils: UtilsProvider, ngzone: NgZone, private storage: Storage) {
  37.  
  38.         platform.ready().then(() => {
  39.             statusBar.overlaysWebView(false);
  40.             statusBar.backgroundColorByHexString('#405491');
  41.             splashScreen.hide();
  42.            
  43.             this.storage.get("user").then((user) => {
  44.                 if(user) {
  45.                     ngzone.run(() => {
  46.                         this.emailu = user.emailu;
  47.                         this.token  = user.token;
  48.                         this.codven = user.codven;
  49.            
  50.                         dbProvider.createDatabase();
  51.                         this.nav.setRoot(HomePage);
  52.                     });
  53.                 } else {
  54.                     this.emailu = '';
  55.                     this.token  = '';
  56.                     this.codven = '';
  57.                     this.openLoginPage(splashScreen);
  58.                 }
  59.             }).catch((err) => {console.log("app.component.ts " + err.message)});
  60.         });
  61.  
  62.         this.pages = [
  63.             { title: 'Pedidos', subtitle: '', component: HomePage, icon: 'document'},
  64.             { title: 'Clientes', subtitle: '', component: ClientPage, icon: 'person'},
  65.             { title: 'Produtos', subtitle: '', component: ProductPage, icon: 'cube'},
  66.             { title: 'Relatórios', subtitle: '', component: ChartPage, icon: 'podium'},
  67.             { title: 'Sistema Online', subtitle: '', component: null, icon: 'cloud'},
  68.             { title: 'Sincronizar', subtitle: '', component: null, icon: 'sync'},
  69.             { title: 'Sair', subtitle: '', component: null, icon: 'power'}
  70.         ];
  71.     }
  72.  
  73.     private openLoginPage(splashScreen: SplashScreen) {
  74.         splashScreen.hide();
  75.         this.rootPage = LoginPage;
  76.     }
  77.  
  78.     openPage(page) {
  79.         if(page.title == 'Sair') {
  80.             this.nav.setRoot(LoginPage)
  81.             this.nav.popToRoot();
  82.         } else if(page.title == 'Sincronizar') {
  83.             if(this.utils.checkConnection()) {
  84.                 let loader = this.loadingCtrl.create({content: "Sincronizando, aguarde..."});
  85.              
  86.                 loader.present().then(() => {
  87.                     this.dbProvider.syncDatabase(this.token, this.codven).then(() => {
  88.                         loader.dismiss();
  89.                         this.nav.push('HomePage');
  90.                     }).catch((err) => {
  91.                         loader.dismiss();
  92.                         this.utils.showAlert('Sincronizar', err.message);
  93.                     });
  94.                 });
  95.             }  else {
  96.                 this.utils.showAlert('Sincronizar', 'Você não está conectado a internet, verifique!');
  97.             }
  98.         } else if(page.title == 'Sistema Online') {
  99.             window.open("http://200.98.129.191:8080/dashboard/", '_system', 'location=yes');
  100.         } else {
  101.             this.nav.push(page.component);
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement