From bb81921ea490cd6a6c3163181756c2fa85aebac7 Mon Sep 17 00:00:00 2001 From: mpuebla Date: Fri, 30 Aug 2019 15:12:29 -0300 Subject: [PATCH] Agregada logica para cargar muchas imagenes y para hacer delete --- .../amb-imagenes/amb-imagenes.component.ts | 56 ++++++++++++++++------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/app/components/amb-imagenes/amb-imagenes.component.ts b/src/app/components/amb-imagenes/amb-imagenes.component.ts index fbe86a7..7d1830b 100644 --- a/src/app/components/amb-imagenes/amb-imagenes.component.ts +++ b/src/app/components/amb-imagenes/amb-imagenes.component.ts @@ -27,24 +27,34 @@ export class AmbImagenesComponent implements OnInit { }); } - onFileSelected(event, articulo) { + this.articulos = productos; + this.filterItems(); + }, error => console.error(error)); + } - let file: File = event.target.files[0]; + onFileSelected(event, articulo: Producto) { - this.onLoad(file) - .then(result => { + let auxFiles: FileList = event.target.files; + Array.from(auxFiles).forEach(file => { - articulo.imagenes = []; + this.onLoad(file) + .then(result => { - document.getElementById(articulo.CodSec + articulo.CodArt)['src'] = result; + articulo.imagenes.push({ + name: file.name, + fromGallery: true, + imagen: result, + id_articulo: articulo.id + }); - this.saveInBase({ - name: file.name, - base64: result, - codigo: articulo.CodArt, - sector: articulo.CodSec + this.saveInBase({ + name: file.name, + base64: result, + codigo: articulo.CodArt, + sector: articulo.CodSec + }); }); - }); + }) } filterItems() { @@ -57,10 +67,10 @@ export class AmbImagenesComponent implements OnInit { saveInBase(img) { - this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, img) + this.productoService.saveInBase(img) .subscribe(data => { - console.log(data); - }); + + }, error => console.error(error)); } onLoad(file) { @@ -78,4 +88,20 @@ export class AmbImagenesComponent implements OnInit { }); } + + deleteImage(imagenes, index: number) { + + if (!imagenes[index].name) { + imagenes[index].name = imagenes[index].imagen; + } + + this.productoService.deleteImage(imagenes[index]) + .subscribe(res => { + + if (res) { + imagenes.splice(index, 1); + } + }, error => console.error(error)); + } + } -- 1.9.1