Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229726

After use --prod code not work

$
0
0

This code not work after use --prod to build:

"this.platform.registerBackButtonAction(() => { ... }

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, ToastController, App, IonicApp, MenuController, AlertController} from 'ionic-angular';
import { StatusBar, Splashscreen, SQLite } from 'ionic-native';

import { HomePage } from '../pages/home/home';
import { OrcamentoPage } from '../pages/orcamento/orcamento';
import { CarrinhoPage } from '../pages/carrinho/carrinho';
import { ConfigPage } from '../pages/config/config';
import { ConfigServidorPage } from '../pages/configservidor/configservidor';
import { PreferenciasPage } from '../pages/preferencias/preferencias';
import { ModalProdutosPage } from '../pages/modalprodutos/modalprodutos';
import { EditarServidorPage } from '../pages/editarservidor/editarservidor';
import { TestePage } from '../pages/teste/teste';
import { Database } from '../providers/database';
import { Webservice } from '../providers/webservice';
import { AppMinimize } from '@ionic-native/app-minimize';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild('nav') nav: Nav;
  rootPage: any = HomePage;
  private storage: SQLite;
  private isOpen: boolean;
  pages: Array<{title: string, component: any}>;
  public usuario: any;
  public token: any;

  constructor(public platform: Platform, public toastCtrl: ToastController, public webservice: Webservice,
  public appCtrl: App, public ionicApp: IonicApp, public menuCtrl: MenuController, public alertCtrl: AlertController,
  public database: Database, public appMinimize: AppMinimize) {
    this.initializeApp();

    // Menu
    this.pages = [
    { title: 'Dashboard', component: OrcamentoPage },
    { title: 'Carrinho', component: CarrinhoPage },
    { title: 'Sair', component: HomePage }
    ];
  }

  initializeApp() {
    this.platform.ready().then(() => {
      if(!this.isOpen) {

        this.storage = new SQLite();
        this.storage.openDatabase({name: "infosysDB.db", location: "default"})
        .then(
          (data) => {
            this.storage.executeSql("CREATE TABLE IF NOT EXISTS configDB(id INTEGER PRIMARY KEY AUTOINCREMENT, descricao VARCHAR, loja VARCHAR, servidor VARCHAR, token VARCHAR, itens VARCHAR, buscapadrao VARCHAR, power VARCHAR)", {})
            .then(
              (data) => {
                console.log("tabela criada com sucesso");
              },
              (error) => {
                this.presentToast(JSON.stringify(error));
              })
          },
          (error) => {
            this.presentToast("Erro ao abrir banco de dados " + error);
        });

        this.storage.openDatabase({name: "infosysDB.db", location: "default"})
        .then(() => {
          this.storage.executeSql("CREATE TABLE IF NOT EXISTS carrinho(codigo VARCHAR, item VARCHAR, valorvenda VARCHAR, valortotal VARCHAR, estoque VARCHAR, quantidade VARCHAR)", {})
          .then(
            (data) => {
              console.log("Tabela criada com sucesso: " + data);
            },
            (error) => {
              this.presentToast("Não foi possível criar a tabela: CARRINHO " + error);

            });
        },
        (error) => {
          this.presentToast("Erro ao abrir banco de dados " + error);
        });

        this.storage.openDatabase({name: "infosysDB.db", location: "default"})
        .then(
          (data) => {
            this.storage.executeSql("CREATE TABLE IF NOT EXISTS usuarioapp(codigo VARCHAR, cripto_pre_cma VARCHAR, cripto_pre_sugerido VARCHAR, cripto_loja VARCHAR)", {})
            .then(
              (data) => {
                console.log("Tabela criada com sucesso: usuarioapp" + data);
              },
              (error) => {
                this.presentToast("Não foi possível criar a tabela: USUARIOAPP " + error);
              });
          },
          (error) => {
            this.presentToast("Erro ao abrir banco de dados " + error);
          });

        this.storage.openDatabase({name: "infosysDB.db", location: "default"})
        .then(
          (data) => {
            this.storage.executeSql("CREATE TABLE IF NOT EXISTS preferencias(tipo VARCHAR, cliente VARCHAR, codigo VARCHAR, tipodepreco VARCHAR, tabeladepreco VARCHAR, tabelacodigo VARCHAR)", {})
            .then(
              (data) => {
                console.log("Tabela criada com sucesso: preferencias" + data);
              },
              (error) => {
                this.presentToast("Não foi possível criar a tabela: preferencias" + error);
              });
          },
          (error) => {
            this.presentToast("Erro ao abrir banco de dados " + error);
          });

      }

      this.platform.registerBackButtonAction(() => {

        let activePortal = this.ionicApp._loadingPortal.getActive() ||
        this.ionicApp._modalPortal.getActive() ||
        this.ionicApp._toastPortal.getActive() ||
        this.ionicApp._overlayPortal.getActive();

        let view = this.nav.getActive();
        let currentRootPage = view.component.name;


        if (activePortal) {
          activePortal.dismiss();
        }
        else if (this.menuCtrl.isOpen()) {
          this.menuCtrl.close();
        }
        else if (this.nav.canGoBack() || view && view.isOverlay) {
          this.nav.pop();
        }
        else if (currentRootPage == "HomePage") {
          this.appMinimize.minimize().then(
            success => console.log('Closed'),
            err => console.log('Something went wrong')
          );
        } else if (currentRootPage == "OrcamentoPage") {
          let alert = this.alertCtrl.create({
            title: 'Deseja fazer logoff ?',
            message: '',
            buttons: [
            {
              text: 'Cancelar',
              role: 'cancel',
              handler: () => {
                alert.dismiss();
              }
            },
            {
              text: 'ok',
              handler: () => {
                this.nav.setRoot(HomePage);
              }
            }
            ]
          });
          alert.present();
        }else if (currentRootPage == "PreferenciasPage") {
          this.nav.setRoot(OrcamentoPage);
        } else if (currentRootPage == "CarrinhoPage") {
          this.nav.setRoot(OrcamentoPage);
        } else if (currentRootPage == "FinalizaPage") {
          this.nav.setRoot(OrcamentoPage);
        } else if (currentRootPage == "ConfigPage") {
          this.nav.setRoot(HomePage);
        }
      });

      StatusBar.styleDefault();
      Splashscreen.hide();
    });
}

public presentToast(mensagem) {
  let toast = this.toastCtrl.create({
    message: mensagem,
    duration: 3000
  });
  toast.present();
}

public openPage(page) {
  this.nav.setRoot(page.component);
}
}

Viewing all articles
Browse latest Browse all 229726

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>