Commit 5bcde6bae25263a6014469eab6440c2239df434f

Authored by Marcelo Puebla
1 parent 757dbe53eb
Exists in develop

Fix

Desuscribo cuando se destruye compoenentes
src/app/modules/pago-electronico/pago-electronico.component.ts
1 import { Component, OnInit, OnDestroy } from '@angular/core'; 1 import { Component, OnInit, OnDestroy } from '@angular/core';
2 import { ArticuloService } from 'src/app/services/articulo/articulo.service'; 2 import { ArticuloService } from 'src/app/services/articulo/articulo.service';
3 import { Router } from '@angular/router'; 3 import { Router } from '@angular/router';
4 import { APP_SETTINGS } from 'src/etc/AppSettings'; 4 import { APP_SETTINGS } from 'src/etc/AppSettings';
5 import { BsModalService } from 'ngx-bootstrap/modal'; 5 import { BsModalService } from 'ngx-bootstrap/modal';
6 import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; 6 import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component';
7 import { Subscription } from "rxjs";
7 8
8 @Component({ 9 @Component({
9 selector: 'app-pago-electronico', 10 selector: 'app-pago-electronico',
10 templateUrl: './pago-electronico.component.html', 11 templateUrl: './pago-electronico.component.html',
11 styleUrls: ['./pago-electronico.component.scss'] 12 styleUrls: ['./pago-electronico.component.scss']
12 }) 13 })
13 export class PagoElectronicoComponent implements OnInit, OnDestroy { 14 export class PagoElectronicoComponent implements OnInit, OnDestroy {
14 urlQr = `${APP_SETTINGS.apiImagenes}/qr/${APP_SETTINGS.deploy}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`; 15 urlQr = `${APP_SETTINGS.apiImagenes}/qr/${APP_SETTINGS.deploy}/${APP_SETTINGS.codigoP}/tienda/${APP_SETTINGS.terminal}`;
16 subscription: Subscription;
15 17
16 constructor( 18 constructor(
17 private articuloService: ArticuloService, 19 private articuloService: ArticuloService,
18 private router: Router, 20 private router: Router,
19 private modalService: BsModalService, 21 private modalService: BsModalService,
20 ) { } 22 ) { }
21 23
22 ngOnInit() { 24 ngOnInit() {
23 if (!this.articuloService.carrito.length) { 25 if (!this.articuloService.carrito.length) {
24 this.router.navigate(['']); 26 this.router.navigate(['']);
25 return; 27 return;
26 } 28 }
27 const dataPago = { 29 const dataPago = {
28 pedidoAnombreDe: '' 30 pedidoAnombreDe: ''
29 }; 31 };
30 dataPago.pedidoAnombreDe = ''; 32 dataPago.pedidoAnombreDe = '';
31 this.articuloService.pay(dataPago) 33 this.subscription = this.articuloService.pay(dataPago)
32 .subscribe((res: any) => { 34 .subscribe((res: any) => {
33 this.articuloService.idComanda = res.data; 35 this.articuloService.idComanda = res.data;
34 this.router.navigate(['mensaje-final']); 36 this.router.navigate(['mensaje-final']);
35 }, (err) => { 37 }, (err) => {
36 this.modalService.show(ErrorFormaPagoComponent, { 38 this.modalService.show(ErrorFormaPagoComponent, {
37 class: 'modal-lg modal-dialog-centered', 39 class: 'modal-lg modal-dialog-centered',
38 ignoreBackdropClick: true, 40 ignoreBackdropClick: true,
39 }); 41 });
40 }); 42 });
41 this.mediaPantalla(); 43 this.mediaPantalla();
42 } 44 }
43 45
44 ngOnDestroy() { 46 ngOnDestroy() {
47 if (this.subscription) this.subscription.unsubscribe();
45 for (let i = 1; i <= this.modalService.getModalsCount(); i++) { 48 for (let i = 1; i <= this.modalService.getModalsCount(); i++) {
46 this.modalService.hide(i); 49 this.modalService.hide(i);
47 } 50 }
48 } 51 }
49 52
50 mediaPantalla() { 53 mediaPantalla() {
51 if ($('body').hasClass('media-pantalla')) { 54 if ($('body').hasClass('media-pantalla')) {
52 $('.qr-mt').addClass('media-pantalla'); 55 $('.qr-mt').addClass('media-pantalla');
53 } 56 }
54 } 57 }
55 } 58 }
56 59
src/app/modules/pago-tarjeta/pago-tarjeta.component.ts
1 import { Component, OnInit, TemplateRef, OnDestroy, ViewChild } from '@angular/core'; 1 import { Component, OnInit, TemplateRef, OnDestroy, ViewChild } from '@angular/core';
2 import { ArticuloService } from 'src/app/services/articulo/articulo.service'; 2 import { ArticuloService } from 'src/app/services/articulo/articulo.service';
3 import { Router } from '@angular/router'; 3 import { Router } from '@angular/router';
4 import { BsModalService } from 'ngx-bootstrap/modal'; 4 import { BsModalService } from 'ngx-bootstrap/modal';
5 import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; 5 import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component';
6 import { Subscription } from 'rxjs';
6 7
7 @Component({ 8 @Component({
8 selector: 'app-pago-tarjeta', 9 selector: 'app-pago-tarjeta',
9 templateUrl: './pago-tarjeta.component.html', 10 templateUrl: './pago-tarjeta.component.html',
10 styleUrls: ['./pago-tarjeta.component.scss'] 11 styleUrls: ['./pago-tarjeta.component.scss']
11 }) 12 })
12 export class PagoTarjetaComponent implements OnInit, OnDestroy { 13 export class PagoTarjetaComponent implements OnInit, OnDestroy {
13 timer: any; 14 timer: any;
14 @ViewChild('template', {static: true}) public template: TemplateRef<any>; 15 subscription: Subscription;
16 @ViewChild('template', { static: true }) public template: TemplateRef<any>;
15 17
16 constructor( 18 constructor(
17 private articuloService: ArticuloService, 19 private articuloService: ArticuloService,
18 private router: Router, 20 private router: Router,
19 private modalService: BsModalService, 21 private modalService: BsModalService,
20 ) { } 22 ) { }
21 23
22 ngOnInit() { 24 ngOnInit() {
23 if (!this.articuloService.carrito.length) { 25 if (!this.articuloService.carrito.length) {
24 this.router.navigate(['']); 26 this.router.navigate(['']);
25 return; 27 return;
26 } 28 }
27 this.openModalEspera(this.template); 29 this.openModalEspera(this.template);
28 const dataPago = { 30 const dataPago = {
29 pedidoAnombreDe: '' 31 pedidoAnombreDe: ''
30 }; 32 };
31 this.articuloService.pay(dataPago) 33 this.subscription = this.articuloService.pay(dataPago)
32 .subscribe((res: any) => { 34 .subscribe((res: any) => {
33 this.articuloService.idComanda = res.data; 35 this.articuloService.idComanda = res.data;
34 this.router.navigate(['mensaje-final']); 36 this.router.navigate(['mensaje-final']);
35 }, (err) => { 37 }, (err) => {
36 this.modalService.show(ErrorFormaPagoComponent, { 38 this.modalService.show(ErrorFormaPagoComponent, {
37 class: 'modal-lg modal-dialog-centered', 39 class: 'modal-lg modal-dialog-centered',
38 ignoreBackdropClick: true, 40 ignoreBackdropClick: true,
39 }); 41 });
40 }); 42 });
41 this.mediaPantalla(); 43 this.mediaPantalla();
42 } 44 }
43 45
44 ngOnDestroy() { 46 ngOnDestroy() {
47 if (this.subscription) this.subscription.unsubscribe();
45 if (this.timer) clearTimeout(this.timer); 48 if (this.timer) clearTimeout(this.timer);
46 for (let i = 1; i <= this.modalService.getModalsCount(); i++) { 49 for (let i = 1; i <= this.modalService.getModalsCount(); i++) {
47 this.modalService.hide(i); 50 this.modalService.hide(i);
48 } 51 }
49 } 52 }
50 53
51 mediaPantalla() { 54 mediaPantalla() {
52 if ($('body').hasClass('media-pantalla')) { 55 if ($('body').hasClass('media-pantalla')) {
53 $('.pago-tarjeta').addClass('media-pantalla'); 56 $('.pago-tarjeta').addClass('media-pantalla');
54 } 57 }
55 } 58 }
56 59
57 openModalEspera(templateRef: TemplateRef<any>) { 60 openModalEspera(templateRef: TemplateRef<any>) {
58 const modalRef = this.modalService.show(templateRef, { class: 'modal-lg modal-dialog-centered' }); 61 const modalRef = this.modalService.show(templateRef, { class: 'modal-lg modal-dialog-centered' });
59 this.timer = setTimeout(() => { 62 this.timer = setTimeout(() => {
60 modalRef.hide(); 63 modalRef.hide();
61 }, 5000); 64 }, 5000);
62 } 65 }
63 } 66 }
64 67