Commit 390d36d7f6f7ec70feb2f1dfaaf5e30e7211a7aa
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master(efernandez) See merge request !30
Showing
4 changed files
Show diff stats
package-lock.json
| ... | ... | @@ -7843,6 +7843,11 @@ |
| 7843 | 7843 | "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", |
| 7844 | 7844 | "dev": true |
| 7845 | 7845 | }, |
| 7846 | + "simple-keyboard": { | |
| 7847 | + "version": "2.25.3", | |
| 7848 | + "resolved": "https://registry.npmjs.org/simple-keyboard/-/simple-keyboard-2.25.3.tgz", | |
| 7849 | + "integrity": "sha512-wEEPPbVUH8C4pzION3ROyJWuf079FtEpYi6VciDgKB77BzKsQsH9sBimCn4b+1Qsk7krYTzNOYUshbWLzSb+6A==" | |
| 7850 | + }, | |
| 7846 | 7851 | "slash": { |
| 7847 | 7852 | "version": "1.0.0", |
| 7848 | 7853 | "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz", |
package.json
src/app/components/inicio/inicio.component.ts
| ... | ... | @@ -6,6 +6,7 @@ import { ProductoService } from 'src/app/services/producto.service'; |
| 6 | 6 | import { Router } from '@angular/router'; |
| 7 | 7 | import { Promocion } from 'src/app/wrappers/promocion'; |
| 8 | 8 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; |
| 9 | +import { HostListener } from '@angular/core'; | |
| 9 | 10 | |
| 10 | 11 | @Component({ |
| 11 | 12 | selector: 'app-inicio', |
| ... | ... | @@ -14,9 +15,24 @@ import { Sinonimo } from 'src/app/wrappers/sinonimo'; |
| 14 | 15 | }) |
| 15 | 16 | export class InicioComponent implements OnInit { |
| 16 | 17 | |
| 18 | + @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { | |
| 19 | + | |
| 20 | + if (e.keyCode == 13) { | |
| 21 | + this.buscarByCodigoBarras(this.busqueda); | |
| 22 | + this.busqueda = ''; | |
| 23 | + } else { | |
| 24 | + this.busqueda += e.key; | |
| 25 | + } | |
| 26 | + | |
| 27 | + }; | |
| 28 | + | |
| 17 | 29 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; |
| 18 | 30 | private productoAcargar: Producto; |
| 31 | + private productos: Producto[]; | |
| 19 | 32 | private promoAcargar: Promocion; |
| 33 | + private tienePromo = false; | |
| 34 | + private productoEsPromo = false; | |
| 35 | + private busqueda: string = ''; | |
| 20 | 36 | private sinonimoAcargar: Sinonimo; |
| 21 | 37 | |
| 22 | 38 | promociones: Promocion[] = []; |
| ... | ... | @@ -31,6 +47,7 @@ export class InicioComponent implements OnInit { |
| 31 | 47 | |
| 32 | 48 | this.productoAcargar = this.productoService.productoAcargar; |
| 33 | 49 | this.getPromociones(); |
| 50 | + this.getProductos(); | |
| 34 | 51 | } |
| 35 | 52 | |
| 36 | 53 | getPromociones() { |
| ... | ... | @@ -60,6 +77,13 @@ export class InicioComponent implements OnInit { |
| 60 | 77 | this.popoverDirective.show(); |
| 61 | 78 | } |
| 62 | 79 | |
| 80 | + getProductos() { | |
| 81 | + this.productoService.getAll() | |
| 82 | + .subscribe((productos: Producto[]) => { | |
| 83 | + this.productos = productos; | |
| 84 | + }); | |
| 85 | + } | |
| 86 | + | |
| 63 | 87 | private goPage(pageUrl) { |
| 64 | 88 | |
| 65 | 89 | this.router.navigate([pageUrl]); |
| ... | ... | @@ -114,4 +138,21 @@ export class InicioComponent implements OnInit { |
| 114 | 138 | this.sinonimoAcargar = $event; |
| 115 | 139 | } |
| 116 | 140 | |
| 141 | + buscarByCodigoBarras(busqueda) { | |
| 142 | + | |
| 143 | + let producto = this.productos.filter(producto => { | |
| 144 | + return producto.codigoBarra == busqueda; | |
| 145 | + }); | |
| 146 | + | |
| 147 | + if (producto.length) { | |
| 148 | + | |
| 149 | + this.productoAcargar = producto[0]; | |
| 150 | + this.getPromociones(); | |
| 151 | + | |
| 152 | + } else { | |
| 153 | + alert('No se encuentra el producto'); | |
| 154 | + } | |
| 155 | + | |
| 156 | + } | |
| 157 | + | |
| 117 | 158 | } |