Commit ba604922f0bcd5a6abecfc5753e602865f932ad6
1 parent
3d204ecbdc
Exists in
develop
Fix
scroll event
Showing
1 changed file
with
6 additions
and
0 deletions
Show diff stats
src/app/shared/promocion/promocion.component.ts
1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener } from '@angular/core'; |
2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 4 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; | 5 | import { PromocionService } from 'src/app/services/promocion/promocion.service'; |
6 | import { Subject } from 'rxjs'; | 6 | import { Subject } from 'rxjs'; |
7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 7 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 8 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 9 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; |
10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 10 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 11 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; |
12 | 12 | ||
13 | @Component({ | 13 | @Component({ |
14 | selector: 'app-promocion', | 14 | selector: 'app-promocion', |
15 | templateUrl: './promocion.component.html', | 15 | templateUrl: './promocion.component.html', |
16 | styleUrls: ['./promocion.component.scss'] | 16 | styleUrls: ['./promocion.component.scss'] |
17 | }) | 17 | }) |
18 | export class PromocionComponent implements OnInit { | 18 | export class PromocionComponent implements OnInit { |
19 | articulosPromo: IArticulo[] = []; | 19 | articulosPromo: IArticulo[] = []; |
20 | promociones: IArticulo[] = []; | 20 | promociones: IArticulo[] = []; |
21 | onClose: Subject<any>; | 21 | onClose: Subject<any>; |
22 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 22 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
23 | 23 | ||
24 | constructor( | 24 | constructor( |
25 | public modalPromocion: BsModalRef, | 25 | public modalPromocion: BsModalRef, |
26 | private modalService: BsModalService, | 26 | private modalService: BsModalService, |
27 | private articuloService: ArticuloService, | 27 | private articuloService: ArticuloService, |
28 | private promocionService: PromocionService, | 28 | private promocionService: PromocionService, |
29 | private sinonimoService: SinonimoService, | 29 | private sinonimoService: SinonimoService, |
30 | private inactiveScreen: InactiveScreenService, | 30 | private inactiveScreen: InactiveScreenService, |
31 | ) { | 31 | ) { |
32 | this.onClose = new Subject(); | 32 | this.onClose = new Subject(); |
33 | } | 33 | } |
34 | 34 | ||
35 | ngOnInit() { | 35 | ngOnInit() { |
36 | this.getPromociones(); | 36 | this.getPromociones(); |
37 | } | 37 | } |
38 | 38 | ||
39 | selectPromo(promo: IArticulo) { | 39 | selectPromo(promo: IArticulo) { |
40 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) | 40 | this.sinonimoService.getSinonimos(promo.CodSec, promo.CodArt) |
41 | .subscribe((res: ISinonimo[]) => { | 41 | .subscribe((res: ISinonimo[]) => { |
42 | if (res.length) { | 42 | if (res.length) { |
43 | this.openModalSinonimos(res); | 43 | this.openModalSinonimos(res); |
44 | } else { | 44 | } else { |
45 | promo.cantidad = 1; | 45 | promo.cantidad = 1; |
46 | this.articuloService.setArticulo(promo); | 46 | this.articuloService.setArticulo(promo); |
47 | this.modalPromocion.hide(); | 47 | this.modalPromocion.hide(); |
48 | } | 48 | } |
49 | }, err => console.error(err)); | 49 | }, err => console.error(err)); |
50 | this.mediaPantalla(); | 50 | this.mediaPantalla(); |
51 | } | 51 | } |
52 | 52 | ||
53 | openModalSinonimos(sinonimosData: ISinonimo[]) { | 53 | openModalSinonimos(sinonimosData: ISinonimo[]) { |
54 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 54 | const modalSinonimo = this.modalService.show(SinonimoComponent, { |
55 | initialState: { sinonimos: sinonimosData }, | 55 | initialState: { sinonimos: sinonimosData }, |
56 | class: 'modal-promo modal-dialog-centered' | 56 | class: 'modal-promo modal-dialog-centered' |
57 | }); | 57 | }); |
58 | 58 | ||
59 | modalSinonimo.content.onClose | 59 | modalSinonimo.content.onClose |
60 | .subscribe((articulo: IArticulo) => { | 60 | .subscribe((articulo: IArticulo) => { |
61 | this.articuloService.setArticulo(articulo); | 61 | this.articuloService.setArticulo(articulo); |
62 | this.modalPromocion.hide(); | 62 | this.modalPromocion.hide(); |
63 | }); | 63 | }); |
64 | } | 64 | } |
65 | 65 | ||
66 | getPromociones() { | 66 | getPromociones() { |
67 | const sector = this.articulosPromo[0].CodSec; | 67 | const sector = this.articulosPromo[0].CodSec; |
68 | const codigo = this.articulosPromo[0].CodArt; | 68 | const codigo = this.articulosPromo[0].CodArt; |
69 | this.promocionService.getPromociones(sector, codigo) | 69 | this.promocionService.getPromociones(sector, codigo) |
70 | .subscribe((res: IArticulo[]) => { | 70 | .subscribe((res: IArticulo[]) => { |
71 | this.promociones = res; | 71 | this.promociones = res; |
72 | }, error => { console.error(error); }); | 72 | }, error => { console.error(error); }); |
73 | } | 73 | } |
74 | 74 | ||
75 | @HostListener('document:click', ['$event']) | 75 | @HostListener('document:click', ['$event']) |
76 | eventListener(event: Event) { | 76 | eventListener(event: Event) { |
77 | clearTimeout(this.inactiveScreen.timerReposo); | 77 | clearTimeout(this.inactiveScreen.timerReposo); |
78 | this.inactiveScreen.startTimeOutInactividad(); | 78 | this.inactiveScreen.startTimeOutInactividad(); |
79 | } | 79 | } |
80 | 80 | ||
81 | @HostListener('scroll', ['$event']) | ||
82 | scrollEvent(event: Event) { | ||
83 | clearTimeout(this.inactiveScreen.timerReposo); | ||
84 | this.inactiveScreen.startTimeOutInactividad(); | ||
85 | } | ||
86 | |||
81 | mediaPantalla() { | 87 | mediaPantalla() { |
82 | if ($('body').hasClass('media-pantalla')) { | 88 | if ($('body').hasClass('media-pantalla')) { |
83 | $('.modal-content').addClass('media-pantalla'); | 89 | $('.modal-content').addClass('media-pantalla'); |
84 | } | 90 | } |
85 | } | 91 | } |
86 | } | 92 | } |
87 | 93 |