Commit 03a726ea545fc1e9d9f9c876c41ffa4d4532542b

Authored by Marcelo Puebla
1 parent 3e9c0c2a3f
Exists in master

Usada detalle larga en filtro.

src/app/components/amb-imagenes/amb-imagenes.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { appSettings } from 'src/etc/AppSettings'; 2 import { appSettings } from 'src/etc/AppSettings';
3 import { ProductoService } from 'src/app/services/producto.service'; 3 import { ProductoService } from 'src/app/services/producto.service';
4 import { Producto } from 'src/app/wrappers/producto'; 4 import { Producto } from 'src/app/wrappers/producto';
5 import { HttpClient } from '@angular/common/http'; 5 import { HttpClient } from '@angular/common/http';
6 6
7 @Component({ 7 @Component({
8 selector: 'app-amb-imagenes', 8 selector: 'app-amb-imagenes',
9 templateUrl: './amb-imagenes.component.html', 9 templateUrl: './amb-imagenes.component.html',
10 styleUrls: ['./amb-imagenes.component.scss'] 10 styleUrls: ['./amb-imagenes.component.scss']
11 }) 11 })
12 12
13 export class AmbImagenesComponent implements OnInit { 13 export class AmbImagenesComponent implements OnInit {
14 14
15 apiUrl = appSettings.apiUrl; 15 apiUrl = appSettings.apiUrl;
16 articulos: Producto[] = []; 16 articulos: Producto[] = [];
17 private auxProductos: Producto[] = []; 17 private auxProductos: Producto[] = [];
18 private searchTerm: string = ''; 18 private searchTerm: string = '';
19 19
20 constructor(private productoService: ProductoService, private http: HttpClient) {} 20 constructor(private productoService: ProductoService, private http: HttpClient) {}
21 21
22 ngOnInit() { 22 ngOnInit() {
23 23
24 this.productoService.getAll().subscribe((productos: Producto[]) => { 24 this.productoService.getAll().subscribe((productos: Producto[]) => {
25 this.articulos = productos; 25 this.articulos = productos;
26 this.filterItems(); 26 this.filterItems();
27 }); 27 });
28 } 28 }
29 29
30 onFileSelected(event, articulo) { 30 onFileSelected(event, articulo) {
31 31
32 let file: File = event.target.files[0]; 32 let file: File = event.target.files[0];
33 33
34 this.onLoad(file) 34 this.onLoad(file)
35 .then(result => { 35 .then(result => {
36 36
37 articulo.imagenes = []; 37 articulo.imagenes = [];
38 38
39 document.getElementById(articulo.CodSec + articulo.CodArt)['src'] = result; 39 document.getElementById(articulo.CodSec + articulo.CodArt)['src'] = result;
40 40
41 this.saveInBase({ 41 this.saveInBase({
42 name: file.name, 42 name: file.name,
43 base64: result, 43 base64: result,
44 codigo: articulo.CodArt, 44 codigo: articulo.CodArt,
45 sector: articulo.CodSec 45 sector: articulo.CodSec
46 }); 46 });
47 }); 47 });
48 } 48 }
49 49
50 filterItems() { 50 filterItems() {
51 51
52 this.auxProductos = this.articulos.filter(x => { 52 this.auxProductos = this.articulos.filter(x => {
53 return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) 53 return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase())
54 }); 54 });
55 } 55 }
56 56
57 57
58 saveInBase(img) { 58 saveInBase(img) {
59 59
60 this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, img) 60 this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, img)
61 .subscribe(data => { 61 .subscribe(data => {
62 console.log(data); 62 console.log(data);
63 }); 63 });
64 } 64 }
65 65
66 onLoad(file) { 66 onLoad(file) {
67 67
68 return new Promise((resolve, reject) => { 68 return new Promise((resolve, reject) => {
69 69
70 var fr = new FileReader(); 70 var fr = new FileReader();
71 71
72 fr.onload = function() { 72 fr.onload = function() {
73 73
74 resolve(fr.result); 74 resolve(fr.result);
75 }; 75 };
76 76
77 fr.readAsDataURL(file); 77 fr.readAsDataURL(file);
78 }); 78 });
79 79
80 } 80 }
81 } 81 }
82 82