Commit bb81921ea490cd6a6c3163181756c2fa85aebac7
1 parent
8c519ea534
Exists in
master
Agregada logica para cargar muchas imagenes y para hacer delete
Showing
1 changed file
with
41 additions
and
15 deletions
Show diff stats
src/app/components/amb-imagenes/amb-imagenes.component.ts
... | ... | @@ -27,24 +27,34 @@ export class AmbImagenesComponent implements OnInit { |
27 | 27 | }); |
28 | 28 | } |
29 | 29 | |
30 | - onFileSelected(event, articulo) { | |
30 | + this.articulos = productos; | |
31 | + this.filterItems(); | |
32 | + }, error => console.error(error)); | |
33 | + } | |
31 | 34 | |
32 | - let file: File = event.target.files[0]; | |
35 | + onFileSelected(event, articulo: Producto) { | |
33 | 36 | |
34 | - this.onLoad(file) | |
35 | - .then(result => { | |
37 | + let auxFiles: FileList = event.target.files; | |
38 | + Array.from(auxFiles).forEach(file => { | |
36 | 39 | |
37 | - articulo.imagenes = []; | |
40 | + this.onLoad(file) | |
41 | + .then(result => { | |
38 | 42 | |
39 | - document.getElementById(articulo.CodSec + articulo.CodArt)['src'] = result; | |
43 | + articulo.imagenes.push({ | |
44 | + name: file.name, | |
45 | + fromGallery: true, | |
46 | + imagen: result, | |
47 | + id_articulo: articulo.id | |
48 | + }); | |
40 | 49 | |
41 | - this.saveInBase({ | |
42 | - name: file.name, | |
43 | - base64: result, | |
44 | - codigo: articulo.CodArt, | |
45 | - sector: articulo.CodSec | |
50 | + this.saveInBase({ | |
51 | + name: file.name, | |
52 | + base64: result, | |
53 | + codigo: articulo.CodArt, | |
54 | + sector: articulo.CodSec | |
55 | + }); | |
46 | 56 | }); |
47 | - }); | |
57 | + }) | |
48 | 58 | } |
49 | 59 | |
50 | 60 | filterItems() { |
... | ... | @@ -57,10 +67,10 @@ export class AmbImagenesComponent implements OnInit { |
57 | 67 | |
58 | 68 | saveInBase(img) { |
59 | 69 | |
60 | - this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, img) | |
70 | + this.productoService.saveInBase(img) | |
61 | 71 | .subscribe(data => { |
62 | - console.log(data); | |
63 | - }); | |
72 | + | |
73 | + }, error => console.error(error)); | |
64 | 74 | } |
65 | 75 | |
66 | 76 | onLoad(file) { |
... | ... | @@ -78,4 +88,20 @@ export class AmbImagenesComponent implements OnInit { |
78 | 88 | }); |
79 | 89 | |
80 | 90 | } |
91 | + | |
92 | + deleteImage(imagenes, index: number) { | |
93 | + | |
94 | + if (!imagenes[index].name) { | |
95 | + imagenes[index].name = imagenes[index].imagen; | |
96 | + } | |
97 | + | |
98 | + this.productoService.deleteImage(imagenes[index]) | |
99 | + .subscribe(res => { | |
100 | + | |
101 | + if (res) { | |
102 | + imagenes.splice(index, 1); | |
103 | + } | |
104 | + }, error => console.error(error)); | |
105 | + } | |
106 | + | |
81 | 107 | } |