Commit 3d2b5c1f83a1781e74fd897e37acb62baead242e
1 parent
f1c447c302
Exists in
develop
Fix
Al cerrar modal confirmacion
Showing
2 changed files
with
12 additions
and
4 deletions
 
Show diff stats
src/app/shared/confirmacion/confirmacion.component.ts
| 1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener } from '@angular/core'; | 
| 2 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 
| 3 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 3 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 
| 4 | import { Subject } from 'rxjs'; | 4 | import { Subject } from 'rxjs'; | 
| 5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 
| 6 | 6 | ||
| 7 | @Component({ | 7 | @Component({ | 
| 8 | selector: 'app-confirmacion', | 8 | selector: 'app-confirmacion', | 
| 9 | templateUrl: './confirmacion.component.html', | 9 | templateUrl: './confirmacion.component.html', | 
| 10 | styleUrls: ['./confirmacion.component.scss'] | 10 | styleUrls: ['./confirmacion.component.scss'] | 
| 11 | }) | 11 | }) | 
| 12 | export class ConfirmacionComponent implements OnInit { | 12 | export class ConfirmacionComponent implements OnInit { | 
| 13 | titleMessage: string; | 13 | titleMessage: string; | 
| 14 | imagenPath: any; | 14 | imagenPath: any; | 
| 15 | footerMessageFirst: string; | 15 | footerMessageFirst: string; | 
| 16 | footerMessageSecond: string; | 16 | footerMessageSecond: string; | 
| 17 | footerConfirmation: number; | 17 | footerConfirmation: number; | 
| 18 | footerClose: string; | 18 | footerClose: string; | 
| 19 | onClose: Subject<any>; | 19 | onClose: Subject<any>; | 
| 20 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 20 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 
| 21 | 21 | ||
| 22 | constructor( | 22 | constructor( | 
| 23 | public modalRef: BsModalRef, | 23 | public modalRef: BsModalRef, | 
| 24 | private inactiveScreen: InactiveScreenService, | 24 | private inactiveScreen: InactiveScreenService, | 
| 25 | ) { | 25 | ) { | 
| 26 | this.onClose = new Subject(); | 26 | this.onClose = new Subject(); | 
| 27 | } | 27 | } | 
| 28 | 28 | ||
| 29 | ngOnInit() { | 29 | ngOnInit() { | 
| 30 | } | 30 | } | 
| 31 | 31 | ||
| 32 | confirmar() { | 32 | confirmar() { | 
| 33 | this.onClose.next(); | 33 | this.onClose.next(true); | 
| 34 | this.modalRef.hide(); | 34 | this.modalRef.hide(); | 
| 35 | } | 35 | } | 
| 36 | 36 | ||
| 37 | close() { | 37 | close() { | 
| 38 | this.onClose.next(); | ||
| 38 | this.modalRef.hide(); | 39 | this.modalRef.hide(); | 
| 39 | } | 40 | } | 
| 40 | 41 | ||
| 41 | @HostListener('document:click', ['$event']) | 42 | @HostListener('document:click', ['$event']) | 
| 42 | eventListener(event: Event) { | 43 | eventListener(event: Event) { | 
| 43 | clearTimeout(this.inactiveScreen.timerReposo); | 44 | clearTimeout(this.inactiveScreen.timerReposo); | 
| 44 | this.inactiveScreen.startTimeOutInactividad(); | 45 | this.inactiveScreen.startTimeOutInactividad(); | 
| 45 | } | 46 | } | 
| 46 | } | 47 | } | 
| 47 | 48 | 
src/app/shared/header-publicidad/header-publicidad.component.ts
| 1 | import { Component, OnInit, TemplateRef } from '@angular/core'; | 1 | import { Component, OnInit, TemplateRef } from '@angular/core'; | 
| 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 
| 3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; | 3 | import { IPublicidad } from 'src/app/interfaces/IPublicidad'; | 
| 4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; | 4 | import { PublicidadService } from 'src/app/services/publicidad/publicidad.service'; | 
| 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 5 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 
| 6 | import { PromocionComponent } from '../promocion/promocion.component'; | 6 | import { PromocionComponent } from '../promocion/promocion.component'; | 
| 7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; | 7 | import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; | 
| 8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 8 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 
| 9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; | 9 | import { ConfirmacionComponent } from '../confirmacion/confirmacion.component'; | 
| 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 10 | import { SinonimoService } from 'src/app/services/sinonimo/sinonimo.service'; | 
| 11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 11 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 
| 12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 12 | import { SinonimoComponent } from '../sinonimo/sinonimo.component'; | 
| 13 | import * as _ from 'lodash'; | 13 | import * as _ from 'lodash'; | 
| 14 | 14 | ||
| 15 | @Component({ | 15 | @Component({ | 
| 16 | selector: 'app-header-publicidad', | 16 | selector: 'app-header-publicidad', | 
| 17 | templateUrl: './header-publicidad.component.html', | 17 | templateUrl: './header-publicidad.component.html', | 
| 18 | styleUrls: ['./header-publicidad.component.scss'] | 18 | styleUrls: ['./header-publicidad.component.scss'] | 
| 19 | }) | 19 | }) | 
| 20 | export class HeaderPublicidadComponent implements OnInit { | 20 | export class HeaderPublicidadComponent implements OnInit { | 
| 21 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 21 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 
| 22 | publicidades: IPublicidad[] = []; | 22 | publicidades: IPublicidad[] = []; | 
| 23 | modalRef: BsModalRef; | 23 | modalRef: BsModalRef; | 
| 24 | modalSinonimo: BsModalRef; | ||
| 24 | 25 | ||
| 25 | constructor( | 26 | constructor( | 
| 26 | private publicidadService: PublicidadService, | 27 | private publicidadService: PublicidadService, | 
| 27 | private articuloService: ArticuloService, | 28 | private articuloService: ArticuloService, | 
| 28 | private modalService: BsModalService, | 29 | private modalService: BsModalService, | 
| 29 | private sinonimoService: SinonimoService | 30 | private sinonimoService: SinonimoService | 
| 30 | ) { } | 31 | ) { } | 
| 31 | 32 | ||
| 32 | ngOnInit() { | 33 | ngOnInit() { | 
| 33 | this.getPublicidades(); | 34 | this.getPublicidades(); | 
| 34 | this.mediaPantalla(); | 35 | this.mediaPantalla(); | 
| 35 | } | 36 | } | 
| 36 | 37 | ||
| 37 | getPublicidades() { | 38 | getPublicidades() { | 
| 38 | this.publicidadService.getAll() | 39 | this.publicidadService.getAll() | 
| 39 | .subscribe((res: IPublicidad[]) => { | 40 | .subscribe((res: IPublicidad[]) => { | 
| 40 | this.publicidades = res; | 41 | this.publicidades = res; | 
| 41 | }, err => console.error(err)); | 42 | }, err => console.error(err)); | 
| 42 | } | 43 | } | 
| 43 | 44 | ||
| 44 | elegirArticulo(publicidad: IPublicidad) { | 45 | elegirArticulo(publicidad: IPublicidad) { | 
| 45 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 46 | if (publicidad.id_articulo) this.getByID(publicidad.id_articulo); | 
| 46 | } | 47 | } | 
| 47 | 48 | ||
| 48 | getByID(id: number) { | 49 | getByID(id: number) { | 
| 49 | this.articuloService.getById(id) | 50 | this.articuloService.getById(id) | 
| 50 | .subscribe((res: IArticulo) => { | 51 | .subscribe((res: IArticulo) => { | 
| 51 | if (res.FPP) { | 52 | if (res.FPP) { | 
| 52 | this.openModalPromos(res); | 53 | this.openModalPromos(res); | 
| 53 | return; | 54 | return; | 
| 54 | } else { | 55 | } else { | 
| 55 | this.openModalConfirmacion(res); | 56 | this.openModalConfirmacion(res); | 
| 56 | return; | 57 | return; | 
| 57 | } | 58 | } | 
| 58 | }, err => console.error(err)); | 59 | }, err => console.error(err)); | 
| 59 | } | 60 | } | 
| 60 | 61 | ||
| 61 | openModalPromos(articulo: IArticulo) { | 62 | openModalPromos(articulo: IArticulo) { | 
| 63 | if (this.modalRef) return; | ||
| 62 | this.modalRef = this.modalService.show(PromocionComponent, | 64 | this.modalRef = this.modalService.show(PromocionComponent, | 
| 63 | { | 65 | { | 
| 64 | initialState: { | 66 | initialState: { | 
| 65 | idArticulo: articulo.id | 67 | idArticulo: articulo.id | 
| 66 | }, | 68 | }, | 
| 67 | class: 'modal-dialog-centered' | 69 | class: 'modal-dialog-centered' | 
| 68 | }); | 70 | }); | 
| 69 | } | 71 | } | 
| 70 | 72 | ||
| 71 | openModalConfirmacion(articulo: IArticulo) { | 73 | openModalConfirmacion(articulo: IArticulo) { | 
| 74 | if (this.modalRef) return; | ||
| 72 | this.articuloService.setArticulosSinImagen([articulo]); | 75 | this.articuloService.setArticulosSinImagen([articulo]); | 
| 73 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 76 | this.modalRef = this.modalService.show(ConfirmacionComponent, | 
| 74 | { | 77 | { | 
| 75 | initialState: { | 78 | initialState: { | 
| 76 | titleMessage: articulo.DET_LAR, | 79 | titleMessage: articulo.DET_LAR, | 
| 77 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 80 | imagenPath: articulo.imagenes.length ? articulo.imagenes[0].imagen : 'assets/img/imagen-no-encontrada.jpg', | 
| 78 | footerMessageFirst: `¿DESEA AGREGAR ESTE COMBO`, | 81 | footerMessageFirst: `¿DESEA AGREGAR ESTE COMBO`, | 
| 79 | footerMessageSecond: `a su carrito?`, | 82 | footerMessageSecond: `a su carrito?`, | 
| 80 | footerConfirmation: articulo.PreVen, | 83 | footerConfirmation: articulo.PreVen, | 
| 81 | footerClose: `volver` | 84 | footerClose: `volver` | 
| 82 | }, | 85 | }, | 
| 86 | ignoreBackdropClick: true, | ||
| 83 | class: 'modal-dialog-centered' | 87 | class: 'modal-dialog-centered' | 
| 84 | }); | 88 | }); | 
| 85 | this.modalRef.content.onClose.subscribe(() => { | 89 | this.modalRef.content.onClose.subscribe((res) => { | 
| 90 | this.modalRef = null; | ||
| 91 | if (!res) return; | ||
| 86 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 92 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 
| 87 | .subscribe((res: ISinonimo[]) => { | 93 | .subscribe((res: ISinonimo[]) => { | 
| 88 | if (res.length) { | 94 | if (res.length) { | 
| 89 | const sinonimos = []; | 95 | const sinonimos = []; | 
| 90 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 96 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 
| 91 | Object.keys(gruposArticulos).forEach(key => { | 97 | Object.keys(gruposArticulos).forEach(key => { | 
| 92 | sinonimos.push({ productos: gruposArticulos[key] }); | 98 | sinonimos.push({ productos: gruposArticulos[key] }); | 
| 93 | }); | 99 | }); | 
| 94 | res = sinonimos; | 100 | res = sinonimos; | 
| 95 | this.openModalSinonimos(res, articulo); | 101 | this.openModalSinonimos(res, articulo); | 
| 96 | } else { | 102 | } else { | 
| 97 | articulo.cantidad = 1; | 103 | articulo.cantidad = 1; | 
| 98 | this.articuloService.setArticulo(articulo); | 104 | this.articuloService.setArticulo(articulo); | 
| 99 | } | 105 | } | 
| 100 | }, err => console.error(err)); | 106 | }, err => console.error(err)); | 
| 101 | }); | 107 | }); | 
| 102 | this.mediaPantalla(); | 108 | this.mediaPantalla(); | 
| 103 | } | 109 | } | 
| 104 | 110 | ||
| 105 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 111 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 
| 106 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 112 | if (this.modalSinonimo) return; | 
| 113 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { | ||
| 107 | initialState: { | 114 | initialState: { | 
| 108 | sinonimos: sinonimosData, | 115 | sinonimos: sinonimosData, | 
| 109 | articulo | 116 | articulo | 
| 110 | }, | 117 | }, | 
| 111 | class: 'modal-dialog-centered' | 118 | class: 'modal-dialog-centered' | 
| 112 | }); | 119 | }); | 
| 113 | modalSinonimo.content.onClose | 120 | this.modalSinonimo.content.onClose | 
| 114 | .subscribe((res: any) => { | 121 | .subscribe((res: any) => { | 
| 115 | for (const a of articulo.productos) { | 122 | for (const a of articulo.productos) { | 
| 116 | for (const aRes of res.articulos) { | 123 | for (const aRes of res.articulos) { | 
| 117 | if (a.idSinonimo === aRes.ID_SIN) { | 124 | if (a.idSinonimo === aRes.ID_SIN) { | 
| 118 | a.CODA = aRes.CodArt; | 125 | a.CODA = aRes.CodArt; | 
| 119 | a.CodArt = aRes.CodArt; | 126 | a.CodArt = aRes.CodArt; | 
| 120 | a.SECA = aRes.CodSec; | 127 | a.SECA = aRes.CodSec; | 
| 121 | aRes.CodSec = aRes.CodSec; | 128 | aRes.CodSec = aRes.CodSec; | 
| 122 | a.PreVen = aRes.PreVen; | 129 | a.PreVen = aRes.PreVen; | 
| 123 | a.id = aRes.id; | 130 | a.id = aRes.id; | 
| 124 | a.DET_LAR = aRes.DET_LAR; | 131 | a.DET_LAR = aRes.DET_LAR; | 
| 125 | a.DetArt = aRes.DetArt; | 132 | a.DetArt = aRes.DetArt; | 
| 126 | } | 133 | } | 
| 127 | } | 134 | } | 
| 128 | } | 135 | } | 
| 129 | this.articuloService.setArticulo(articulo); | 136 | this.articuloService.setArticulo(articulo); | 
| 130 | }); | 137 | }); | 
| 131 | } | 138 | } | 
| 132 | 139 | ||
| 133 | mediaPantalla() { | 140 | mediaPantalla() { | 
| 134 | if ($('body').hasClass('media-pantalla')) { | 141 | if ($('body').hasClass('media-pantalla')) { | 
| 135 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 142 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 
| 136 | } | 143 | } | 
| 137 | } | 144 | } | 
| 138 | } | 145 | } | 
| 139 | 146 |