From aefffbc780f571903ab18e48f9ed56b044630afe Mon Sep 17 00:00:00 2001 From: mpuebla Date: Wed, 4 Sep 2019 11:47:03 -0300 Subject: [PATCH] Cambio en logica para personalizar un producto. --- src/app/components/inicio/inicio.component.ts | 2 ++ .../popover-sinonimos.component.html | 13 +++++++++--- .../popover-sinonimos.component.ts | 24 +++++++++------------- src/app/components/sidebar/sidebar.component.ts | 1 + src/app/services/producto.service.ts | 1 + 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/app/components/inicio/inicio.component.ts b/src/app/components/inicio/inicio.component.ts index b4a6f00..44190de 100644 --- a/src/app/components/inicio/inicio.component.ts +++ b/src/app/components/inicio/inicio.component.ts @@ -96,6 +96,7 @@ export class InicioComponent implements OnInit, AfterViewInit { producto.cantidad = 1; this.productoService.setProductos(producto); this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; + this.productoService.esPromoPersonalizada = false; this.promociones = []; this.popoverDirective.hide(); } @@ -184,6 +185,7 @@ export class InicioComponent implements OnInit, AfterViewInit { if (this.sinonimos.length > 0) { this.sinonimos = []; + this.productoService.esPromoPersonalizada = false; this.popoverDirective.hide(); } diff --git a/src/app/components/popover-sinonimos/popover-sinonimos.component.html b/src/app/components/popover-sinonimos/popover-sinonimos.component.html index 3ee3f79..f88cdb8 100644 --- a/src/app/components/popover-sinonimos/popover-sinonimos.component.html +++ b/src/app/components/popover-sinonimos/popover-sinonimos.component.html @@ -13,10 +13,17 @@
-
+
-

- Elija opción - Cantidad Restante {{cantidadRestanteSinonimos[i]}} +

+ Elija opción - + + Cantidad Restante {{cantidadRestanteSinonimos}} +

diff --git a/src/app/components/popover-sinonimos/popover-sinonimos.component.ts b/src/app/components/popover-sinonimos/popover-sinonimos.component.ts index 8eb0036..8178ba8 100644 --- a/src/app/components/popover-sinonimos/popover-sinonimos.component.ts +++ b/src/app/components/popover-sinonimos/popover-sinonimos.component.ts @@ -17,7 +17,7 @@ export class PopoverSinonimosComponent implements OnInit { @Output() productosPersonalizados = new EventEmitter(); // sinonimo: Sinonimo; - private cantidadRestanteSinonimos: number[] = []; + private cantidadRestanteSinonimos: number = 0; constructor(private productoService: ProductoService) { } @@ -25,14 +25,13 @@ export class PopoverSinonimosComponent implements OnInit { this.popoverContent.forEach(sinonimo => { - this.cantidadRestanteSinonimos.push(0); - sinonimo.productos.forEach((producto, index) => { - if (producto.cantidad) { - sinonimo.productos.splice(index, 1); - sinonimo.productos.splice(0, 0, producto); + if (this.productoService.esPromoPersonalizada) { + producto.cantidad = producto.cantidad ? producto.cantidad : 0; + this.cantidadRestanteSinonimos = 0; } else { + this.cantidadRestanteSinonimos += producto.cantidad ? producto.cantidad : 0; producto.cantidad = 0; } @@ -43,10 +42,7 @@ export class PopoverSinonimosComponent implements OnInit { continuar() { //Si aún quedan articulos que agregar no deja continuar. - for (let i = 0; i < this.cantidadRestanteSinonimos.length; i++) { - - if (this.cantidadRestanteSinonimos[i] > 0) return; - } + if (this.cantidadRestanteSinonimos > 0) return; var productosAenviar: Producto[] = []; @@ -68,17 +64,17 @@ export class PopoverSinonimosComponent implements OnInit { sumarCantidad(producto: Producto, i: number) { - if (this.cantidadRestanteSinonimos[i] === 0) return; + if (this.cantidadRestanteSinonimos === 0) return; producto.cantidad++; - this.cantidadRestanteSinonimos[i]--; + this.cantidadRestanteSinonimos--; } restarCantidad(producto: Producto, i: number) { - if (this.cantidadRestanteSinonimos[i] === this.popoverContent[i].cantidad) return; + if (this.cantidadRestanteSinonimos === this.popoverContent[i].cantidad) return; if (producto.cantidad === 0) return; producto.cantidad--; - this.cantidadRestanteSinonimos[i]++; + this.cantidadRestanteSinonimos++; } } diff --git a/src/app/components/sidebar/sidebar.component.ts b/src/app/components/sidebar/sidebar.component.ts index 01c739a..12066bd 100644 --- a/src/app/components/sidebar/sidebar.component.ts +++ b/src/app/components/sidebar/sidebar.component.ts @@ -80,6 +80,7 @@ export class SidebarComponent implements OnInit { personalizarPromo(producto: Producto, index) { this.productoService.productoAcargar = producto; + this.productoService.esPromoPersonalizada = true; this.deleteProducto(producto, index); this.router.navigate(['inicio']); } diff --git a/src/app/services/producto.service.ts b/src/app/services/producto.service.ts index ef9f3d8..506562d 100644 --- a/src/app/services/producto.service.ts +++ b/src/app/services/producto.service.ts @@ -13,6 +13,7 @@ export class ProductoService { productoAcargar: Producto; promoAcargar: Producto; mostrar: string; + esPromoPersonalizada: boolean = false; constructor(private http: HttpClient) { } -- 1.9.1