Commit 7cd4da6e661e01ee01878b64003ba3084ee3786a
1 parent
09655c3ece
Exists in
develop
Arreglo timeout de cancelar compra
Showing
2 changed files
with
14 additions
and
12 deletions
Show diff stats
src/app/modules/admin/admin.component.ts
1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener, OnDestroy } from '@angular/core'; |
2 | import { Router } from '@angular/router'; | 2 | import { Router } from '@angular/router'; |
3 | 3 | ||
4 | @Component({ | 4 | @Component({ |
5 | selector: 'app-admin', | 5 | selector: 'app-admin', |
6 | templateUrl: './admin.component.html', | 6 | templateUrl: './admin.component.html', |
7 | styleUrls: ['./admin.component.scss'] | 7 | styleUrls: ['./admin.component.scss'] |
8 | }) | 8 | }) |
9 | 9 | ||
10 | export class AdminComponent implements OnInit { | 10 | export class AdminComponent implements OnInit, OnDestroy { |
11 | timerReposo: any; | 11 | timerReposo: any; |
12 | 12 | ||
13 | constructor( | 13 | constructor( |
14 | private router: Router, | 14 | private router: Router, |
15 | ) { } | 15 | ) { } |
16 | 16 | ||
17 | ngOnInit() { | 17 | ngOnInit() { |
18 | this.startTimeOutInactividad(); | 18 | this.startTimeOutInactividad(); |
19 | } | 19 | } |
20 | 20 | ||
21 | @HostListener('document:click', ['$event']) | 21 | ngOnDestroy() { |
22 | 22 | clearTimeout(this.timerReposo); | |
23 | documentClick(event: MouseEvent) { | ||
24 | if (event) { | ||
25 | this.restartTimer(); | ||
26 | } | ||
27 | } | 23 | } |
28 | 24 | ||
29 | restartTimer() { | 25 | @HostListener('document:click', ['$event']) |
26 | documentClick(event: MouseEvent) { | ||
30 | clearTimeout(this.timerReposo); | 27 | clearTimeout(this.timerReposo); |
31 | this.startTimeOutInactividad(); | 28 | this.startTimeOutInactividad(); |
32 | } | 29 | } |
33 | 30 | ||
34 | startTimeOutInactividad() { | 31 | startTimeOutInactividad() { |
35 | this.timerReposo = setTimeout(() => { | 32 | this.timerReposo = setTimeout(() => { |
36 | this.router.navigate(['cancelar-compra']); | 33 | this.router.navigate(['cancelar-compra']); |
37 | }, 90000); | 34 | }, 90000); |
38 | } | 35 | } |
39 | 36 | ||
40 | } | 37 | } |
src/app/modules/cancelar-compra/cancelar-compra.component.ts
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; |
2 | import { Location } from '@angular/common'; | 2 | import { Location } from '@angular/common'; |
3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
4 | import { Router } from '@angular/router'; | 4 | import { Router } from '@angular/router'; |
5 | 5 | ||
6 | @Component({ | 6 | @Component({ |
7 | selector: 'app-cancelar-compra', | 7 | selector: 'app-cancelar-compra', |
8 | templateUrl: './cancelar-compra.component.html', | 8 | templateUrl: './cancelar-compra.component.html', |
9 | styleUrls: ['./cancelar-compra.component.scss'] | 9 | styleUrls: ['./cancelar-compra.component.scss'] |
10 | }) | 10 | }) |
11 | export class CancelarCompraComponent implements OnInit { | 11 | export class CancelarCompraComponent implements OnInit, OnDestroy { |
12 | timer: any; | ||
12 | 13 | ||
13 | constructor( | 14 | constructor( |
14 | private location: Location, | 15 | private location: Location, |
15 | private router: Router, | 16 | private router: Router, |
16 | private articuloService: ArticuloService | 17 | private articuloService: ArticuloService |
17 | ) { } | 18 | ) { } |
18 | 19 | ||
19 | ngOnInit() { | 20 | ngOnInit() { |
20 | setTimeout(() => { | 21 | this.timer = setTimeout(() => { |
21 | this.limpiarCarritoYvolver(); | 22 | this.limpiarCarritoYvolver(); |
22 | }, 90000); | 23 | }, 90000); |
23 | } | 24 | } |
24 | 25 | ||
26 | ngOnDestroy() { | ||
27 | clearTimeout(this.timer); | ||
28 | } | ||
29 | |||
25 | volverPreviousPage() { | 30 | volverPreviousPage() { |
26 | this.location.back(); | 31 | this.location.back(); |
27 | } | 32 | } |
28 | 33 | ||
29 | limpiarCarritoYvolver() { | 34 | limpiarCarritoYvolver() { |
30 | this.articuloService.carrito = []; | 35 | this.articuloService.carrito = []; |
31 | this.router.navigate(['/']); | 36 | this.router.navigate(['/']); |
32 | } | 37 | } |
33 | } | 38 | } |
34 | 39 |