Commit 0fe454ec4c1ca180dd886360ac3515930a443258
Exists in
develop
Merge branch 'develop' into 'develop'
Develop See merge request !94
Showing
2 changed files
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 | }, | 84 | }, |
| 82 | class: 'modal-dialog-centered' | 85 | ignoreBackdropClick: true, |
| 86 | class: 'modal-dialog-centered' | ||
| 83 | }); | 87 | }); |
| 84 | this.modalRef.content.onClose.subscribe(() => { | 88 | this.modalRef.content.onClose.subscribe((res) => { |
| 85 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | 89 | this.modalRef = null; |
| 90 | if (!res) return; | ||
| 91 | this.sinonimoService.getSinonimos(articulo.CodSec, articulo.CodArt) | ||
| 86 | .subscribe((res: ISinonimo[]) => { | 92 | .subscribe((res: ISinonimo[]) => { |
| 87 | if (res.length) { | 93 | if (res.length) { |
| 88 | const sinonimos = []; | 94 | const sinonimos = []; |
| 89 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); | 95 | const gruposArticulos = _.groupBy(res[0].productos, 'ID_SIN'); |
| 90 | Object.keys(gruposArticulos).forEach(key => { | 96 | Object.keys(gruposArticulos).forEach(key => { |
| 91 | sinonimos.push({ productos: gruposArticulos[key] }); | 97 | sinonimos.push({ productos: gruposArticulos[key] }); |
| 92 | }); | 98 | }); |
| 93 | res = sinonimos; | 99 | res = sinonimos; |
| 94 | this.openModalSinonimos(res, articulo); | 100 | this.openModalSinonimos(res, articulo); |
| 95 | } else { | 101 | } else { |
| 96 | articulo.cantidad = 1; | 102 | articulo.cantidad = 1; |
| 97 | this.articuloService.setArticulo(articulo); | 103 | this.articuloService.setArticulo(articulo); |
| 98 | } | 104 | } |
| 99 | }, err => console.error(err)); | 105 | }, err => console.error(err)); |
| 100 | }); | 106 | }); |
| 101 | this.mediaPantalla(); | 107 | this.mediaPantalla(); |
| 102 | } | 108 | } |
| 103 | 109 | ||
| 104 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { | 110 | openModalSinonimos(sinonimosData: ISinonimo[], articulo: IArticulo) { |
| 105 | const modalSinonimo = this.modalService.show(SinonimoComponent, { | 111 | if (this.modalSinonimo) return; |
| 106 | initialState: { | 112 | this.modalSinonimo = this.modalService.show(SinonimoComponent, { |
| 113 | initialState: { | ||
| 107 | sinonimos: sinonimosData, | 114 | sinonimos: sinonimosData, |
| 108 | articulo | 115 | articulo |
| 109 | }, | 116 | }, |
| 110 | class: 'modal-dialog-centered' | 117 | class: 'modal-dialog-centered' |
| 111 | }); | 118 | }); |
| 112 | modalSinonimo.content.onClose | 119 | this.modalSinonimo.content.onClose |
| 113 | .subscribe((res: any) => { | 120 | .subscribe((res: any) => { |
| 114 | for (const a of articulo.productos) { | 121 | for (const a of articulo.productos) { |
| 115 | for (const aRes of res.articulos) { | 122 | for (const aRes of res.articulos) { |
| 116 | if (a.idSinonimo === aRes.ID_SIN) { | 123 | if (a.idSinonimo === aRes.ID_SIN) { |
| 117 | a.CODA = aRes.CodArt; | 124 | a.CODA = aRes.CodArt; |
| 118 | a.CodArt = aRes.CodArt; | 125 | a.CodArt = aRes.CodArt; |
| 119 | a.SECA = aRes.CodSec; | 126 | a.SECA = aRes.CodSec; |
| 120 | aRes.CodSec = aRes.CodSec; | 127 | aRes.CodSec = aRes.CodSec; |
| 121 | a.PreVen = aRes.PreVen; | 128 | a.PreVen = aRes.PreVen; |
| 122 | a.id = aRes.id; | 129 | a.id = aRes.id; |
| 123 | a.DET_LAR = aRes.DET_LAR; | 130 | a.DET_LAR = aRes.DET_LAR; |
| 124 | a.DetArt = aRes.DetArt; | 131 | a.DetArt = aRes.DetArt; |
| 125 | } | 132 | } |
| 126 | } | 133 | } |
| 127 | } | 134 | } |
| 128 | this.articuloService.setArticulo(articulo); | 135 | this.articuloService.setArticulo(articulo); |
| 129 | }); | 136 | }); |
| 130 | } | 137 | } |
| 131 | 138 | ||
| 132 | mediaPantalla() { | 139 | mediaPantalla() { |
| 133 | if ($('body').hasClass('media-pantalla')) { | 140 | if ($('body').hasClass('media-pantalla')) { |
| 134 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); | 141 | $('#headerPublicidad,#headerPad').addClass('media-pantalla'); |
| 135 | } | 142 | } |
| 136 | } | 143 | } |
| 137 | } | 144 | } |
| 138 | 145 |