|
@@ -1,22 +1,122 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
-import { NavController, NavParams } from 'ionic-angular';
|
|
|
+import { NavController, NavParams, AlertController, LoadingController, ToastController } from 'ionic-angular';
|
|
|
|
|
|
-/*
|
|
|
- Generated class for the Tools page.
|
|
|
+import { LoginPage } from "../login/login";
|
|
|
+
|
|
|
+import { SyncService } from "../../services/sync-service";
|
|
|
+import { PouchService } from "../../services/pouch-service";
|
|
|
|
|
|
- See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
|
|
- Ionic pages and navigation.
|
|
|
-*/
|
|
|
@Component({
|
|
|
- selector: 'page-tools',
|
|
|
- templateUrl: 'tools.html'
|
|
|
+ selector: 'page-tools',
|
|
|
+ templateUrl: 'tools.html'
|
|
|
})
|
|
|
export class ToolsPage {
|
|
|
|
|
|
- constructor(public navCtrl: NavController, public navParams: NavParams) {}
|
|
|
+ constructor(
|
|
|
+ public navCtrl: NavController,
|
|
|
+ public navParams: NavParams,
|
|
|
+ public alertCtrl: AlertController,
|
|
|
+ public loadingCtrl: LoadingController,
|
|
|
+ public toastCtrl: ToastController,
|
|
|
+ public sync: SyncService,
|
|
|
+ public pouch: PouchService
|
|
|
+ ) { }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ ionViewDidLoad() {
|
|
|
+ console.log('ionViewDidLoad ToolsPage');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ askIfSyncData(): void {
|
|
|
+ this.alertCtrl.create({
|
|
|
+ title: "Confirmar",
|
|
|
+ message: "Desea sincronizar sus datos ahora?",
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: "Cancelar"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "Aceptar",
|
|
|
+ handler: () => {
|
|
|
+ this.syncData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }).present();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ syncData(): void {
|
|
|
+ let loader = this.loadingCtrl.create({
|
|
|
+ content: "Actualizando datos, espere..."
|
|
|
+ });
|
|
|
+ loader.present();
|
|
|
+
|
|
|
+ let toast = this.toastCtrl.create({
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+
|
|
|
+ this.sync.do().subscribe(s => {
|
|
|
+ toast.setMessage("Datos actualizados correctamente");
|
|
|
+ }, e => {
|
|
|
+ console.log(e);
|
|
|
+
|
|
|
+ toast.setMessage("No se pudo actualizar los datos");
|
|
|
+ }, () => {
|
|
|
+ loader.dismiss();
|
|
|
+ toast.present();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ askIfDeleteAccount() {
|
|
|
+ this.alertCtrl.create({
|
|
|
+ title: "Confirmar",
|
|
|
+ message: "Desea eliminar su cuenta?",
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: "Cancelar"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "Aceptar",
|
|
|
+ handler: () => {
|
|
|
+ this.deleteAccount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }).present();
|
|
|
+ }
|
|
|
|
|
|
- ionViewDidLoad() {
|
|
|
- console.log('ionViewDidLoad ToolsPage');
|
|
|
- }
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ deleteAccount() {
|
|
|
+ let loader = this.loadingCtrl.create({
|
|
|
+ content: "Eliminando cuenta, espere..."
|
|
|
+ });
|
|
|
+ loader.present();
|
|
|
|
|
|
+ let toast = this.toastCtrl.create({
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+
|
|
|
+ this.pouch.destroyAndInitialize().subscribe(s => {
|
|
|
+ localStorage.clear();
|
|
|
+ this.navCtrl.setRoot(LoginPage);
|
|
|
+ }, e => {
|
|
|
+ toast.setMessage("No se pudo eliminar su cuenta");
|
|
|
+ }, () => {
|
|
|
+ loader.dismiss();
|
|
|
+ toast.present();
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|