Commit 2cf61e38e642da4d99a38996e60caa81868a7a9b
1 parent
a3885a7334
Exists in
master
busqueda de artículos
Showing
4 changed files
with
38 additions
and
21 deletions
Show diff stats
src/app/components/abm-imagenes/abm-imagenes.component.html
1 | <app-header></app-header> | 1 | <app-header></app-header> |
2 | 2 | ||
3 | <div class="container-fluid"> | 3 | <div class="container-fluid"> |
4 | <div class="row m-3"> | 4 | <div class="row m-3"> |
5 | <div class="col"> | 5 | <div class="col"> |
6 | <p class="h2">Configuración de imágenes</p> | 6 | <p class="h2">Configuración de imágenes</p> |
7 | </div> | 7 | </div> |
8 | </div> | 8 | </div> |
9 | 9 | ||
10 | <div class="row mx-3 search"> | 10 | <div class="row mx-3 search"> |
11 | <div class="col"> | 11 | <div class="col"> |
12 | <span class="fa fa-search form-control-lg form-control-search pl-3"></span> | 12 | <span |
13 | title="Buscar" | ||
14 | class="fa fa-search form-control-lg form-control-search pl-3" | ||
15 | (click)="search()"></span> | ||
13 | <input | 16 | <input |
14 | type="text" | 17 | type="text" |
15 | class="form-control form-control-lg shadow-sm rounded-pill px-5" | 18 | class="form-control form-control-lg shadow-sm rounded-pill px-5" |
16 | placeholder="Búsqueda productos" | 19 | placeholder="Búsqueda productos" |
17 | [(ngModel)]="searchTerm" | 20 | [(ngModel)]="searchTerm" |
18 | (ngModelChange)="filterItems()"> | 21 | [disabled]="buscando" |
22 | (keyup.enter)="search()"> | ||
19 | </div> | 23 | </div> |
20 | </div> | 24 | </div> |
21 | 25 | ||
22 | <div class="row m-3 vh-60 overflow-scroll"> | 26 | <div class="row m-3 vh-60 overflow-scroll"> |
23 | <div class="col"> | 27 | <div class="col"> |
24 | <h5>Productos</h5> | 28 | <h5>Productos</h5> |
25 | <table class="table table-striped table-hover table-borderless shadow"> | 29 | <table class="table table-striped table-hover table-borderless shadow"> |
26 | <thead> | 30 | <thead> |
27 | <tr class="bg-primary text-center text-white shadow-sm"> | 31 | <tr class="bg-primary text-center text-white shadow-sm"> |
28 | <th>Nombre</th> | 32 | <th>Nombre</th> |
29 | <th colspan="2">Imagen</th> | 33 | <th colspan="2">Imagen</th> |
30 | </tr> | 34 | </tr> |
31 | </thead> | 35 | </thead> |
32 | <tbody> | 36 | <tbody> |
33 | <tr class="shadow-sm" *ngFor="let articulo of auxProductos"> | 37 | <tr class="shadow-sm" *ngFor="let articulo of articulos"> |
34 | <td class="align-middle"> | 38 | <td class="align-middle"> |
35 | <p class="m-0">{{articulo.DET_LAR}}</p> | 39 | <p class="m-0">{{articulo.DET_LAR}}</p> |
36 | <p class="m-0"><small>Descripción: {{articulo.DET_LAR}}</small></p> | 40 | <p class="m-0"><small>Descripción: {{articulo.DET_LAR}}</small></p> |
37 | <p class="m-0"><small>Sector: {{articulo.CodSec}}</small></p> | 41 | <p class="m-0"><small>Sector: {{articulo.CodSec}}</small></p> |
38 | <p class="m-0"><small>Código: {{articulo.CodArt}}</small></p> | 42 | <p class="m-0"><small>Código: {{articulo.CodArt}}</small></p> |
39 | </td> | 43 | </td> |
40 | <td> | 44 | <td> |
41 | <img | 45 | <img |
42 | *ngIf="articulo.imagenes.length == 0" | 46 | *ngIf="articulo.imagenes.length == 0" |
43 | class="fade-in w-100 mx-auto img-fluid" | 47 | class="fade-in w-100 mx-auto img-fluid" |
44 | src="{{apiImagenes}}/imagenes/noImage.jpg"> | 48 | src="{{apiImagenes}}/imagenes/noImage.jpg"> |
45 | <carousel [interval]="false"> | 49 | <carousel [interval]="false"> |
46 | <slide *ngFor="let item of articulo.imagenes; let index = index"> | 50 | <slide *ngFor="let item of articulo.imagenes; let index = index"> |
47 | <img | 51 | <img |
48 | *ngIf="!item.fromGallery" | 52 | *ngIf="!item.fromGallery" |
49 | class="fade-in img-fluid w-100" | 53 | class="fade-in img-fluid w-100" |
50 | src="{{apiImagenes}}/imagenes/{{item.imagen}}"> | 54 | src="{{apiImagenes}}/imagenes/{{item.imagen}}"> |
51 | <img | 55 | <img |
52 | *ngIf="item.fromGallery" | 56 | *ngIf="item.fromGallery" |
53 | class="fade-in img-fluid w-100" | 57 | class="fade-in img-fluid w-100" |
54 | src="{{item.base64}}"> | 58 | src="{{item.base64}}"> |
55 | <button | 59 | <button |
56 | (click)="deleteImage(articulo.imagenes, index)" | 60 | (click)="deleteImage(articulo.imagenes, index)" |
57 | type="button" | 61 | type="button" |
58 | class="btn btn-lg btn-delete-image position-absolute"> | 62 | class="btn btn-lg btn-delete-image position-absolute"> |
59 | <i class="fa fa-trash text-dark" aria-hidden="true"></i> | 63 | <i class="fa fa-trash text-dark" aria-hidden="true"></i> |
60 | </button> | 64 | </button> |
61 | </slide> | 65 | </slide> |
62 | </carousel> | 66 | </carousel> |
63 | </td> | 67 | </td> |
64 | <td class="align-middle text-center"> | 68 | <td class="align-middle text-center"> |
65 | <div class="custom-file"> | 69 | <div class="custom-file"> |
66 | <input | 70 | <input |
67 | type="file" | 71 | type="file" |
68 | class="custom-file-input" | 72 | class="custom-file-input" |
69 | id="customFileLang" | 73 | id="customFileLang" |
70 | accept="image/*" | 74 | accept="image/*" |
71 | (change)="onFileSelected($event, articulo)" | 75 | (change)="onFileSelected($event, articulo)" |
72 | lang="es" | 76 | lang="es" |
73 | multiple> | 77 | multiple> |
74 | <label class="custom-file-label text-left pr-5" for="customFileLang"> | 78 | <label class="custom-file-label text-left pr-5" for="customFileLang"> |
75 | <small>Seleccionar archivo</small> | 79 | <small>Seleccionar archivo</small> |
76 | </label> | 80 | </label> |
77 | </div> | 81 | </div> |
78 | </td> | 82 | </td> |
79 | </tr> | 83 | </tr> |
80 | </tbody> | 84 | </tbody> |
81 | </table> | 85 | </table> |
82 | </div> | 86 | </div> |
83 | </div> | 87 | </div> |
84 | 88 | ||
85 | <div class="row" *ngIf="paginationData"> | 89 | <div class="row" *ngIf="paginationData"> |
86 | <div class="col"> | 90 | <div class="col"> |
87 | <pagination | 91 | <pagination |
88 | [rotate]="false" | 92 | [rotate]="false" |
89 | [(ngModel)]="paginationData.page" | 93 | [(ngModel)]="paginationData.page" |
90 | [totalItems]="paginationData.rowCount" | 94 | [totalItems]="paginationData.rowCount" |
91 | [maxSize]="paginationData.pageCount" | 95 | [maxSize]="10" |
92 | [itemsPerPage]="paginationData.pageSize" | 96 | [itemsPerPage]="paginationData.pageSize" |
93 | (pageChanged)="pageChanged($event)" | 97 | (pageChanged)="pageChanged($event)" |
94 | [boundaryLinks]="true" | 98 | [boundaryLinks]="true" |
95 | [disabled]="disabledPaginador" | 99 | [disabled]="disabledPaginador" |
96 | previousText="‹" | 100 | previousText="‹" |
97 | nextText="›" | 101 | nextText="›" |
98 | firstText="«" | 102 | firstText="«" |
99 | lastText="»" | 103 | lastText="»" |
100 | ></pagination> | 104 | ></pagination> |
101 | </div> | 105 | </div> |
102 | </div> | 106 | </div> |
103 | 107 | ||
104 | </div> | 108 | </div> |
105 | 109 |
src/app/components/abm-imagenes/abm-imagenes.component.scss
1 | .search .form-control-search { | 1 | .search .form-control-search { |
2 | position: absolute; | 2 | position: absolute; |
3 | z-index: 2; | 3 | z-index: 2; |
4 | display: block; | 4 | display: block; |
5 | text-align: center; | 5 | text-align: center; |
6 | pointer-events: none; | ||
7 | color: #aaa; | ||
8 | line-height: inherit; | 6 | line-height: inherit; |
7 | &:hover{ | ||
8 | cursor: pointer; | ||
9 | } | ||
9 | } | 10 | } |
10 | 11 | ||
11 | .custom-file-input:lang(es) ~ .custom-file-label::after { | 12 | .custom-file-input:lang(es) ~ .custom-file-label::after { |
12 | content: "Elegir"; | 13 | content: "Elegir"; |
13 | } | 14 | } |
14 | 15 | ||
15 | .btn-delete-image { | 16 | .btn-delete-image { |
16 | top: 0; | 17 | top: 0; |
17 | left: 88%; | 18 | left: 88%; |
18 | z-index: 1000; | 19 | z-index: 1000; |
19 | outline: none; | 20 | outline: none; |
20 | } | 21 | } |
21 | 22 | ||
22 | .btn:focus { | 23 | .btn:focus { |
23 | color: gray; | 24 | color: gray; |
24 | outline: 0; | 25 | outline: 0; |
25 | box-shadow: none; | 26 | box-shadow: none; |
src/app/components/abm-imagenes/abm-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 { ImagenesService } from 'src/app/services/imagenes.service'; | 3 | import { ImagenesService } from 'src/app/services/imagenes.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: './abm-imagenes.component.html', | 9 | templateUrl: './abm-imagenes.component.html', |
10 | styleUrls: ['./abm-imagenes.component.scss'] | 10 | styleUrls: ['./abm-imagenes.component.scss'] |
11 | }) | 11 | }) |
12 | 12 | ||
13 | export class AbmImagenesComponent implements OnInit { | 13 | export class AbmImagenesComponent implements OnInit { |
14 | 14 | ||
15 | apiImagenes = appSettings.apiImagenes; | 15 | apiImagenes = appSettings.apiImagenes; |
16 | articulos: Producto[] = []; | 16 | articulos: Producto[] = []; |
17 | private auxProductos: Producto[] = []; | 17 | private auxProductos: Producto[] = []; |
18 | private searchTerm: string = ''; | 18 | private searchTerm: string = ''; |
19 | private paginationData: any; | 19 | private paginationData: any; |
20 | private disabledPaginador: boolean = false; | 20 | private disabledPaginador: boolean = false; |
21 | private buscando: boolean = false; | ||
21 | 22 | ||
22 | constructor(private imagenService: ImagenesService, private http: HttpClient) { } | 23 | constructor(private imagenService: ImagenesService, private http: HttpClient) { } |
23 | 24 | ||
24 | ngOnInit() { | 25 | ngOnInit() { |
25 | 26 | ||
26 | this.imagenService.getAllWithPaginator() | 27 | this.search(); |
28 | } | ||
29 | |||
30 | search() { | ||
31 | |||
32 | this.buscando = true; | ||
33 | |||
34 | this.imagenService.getAllWithPaginator(this.searchTerm) | ||
27 | .subscribe((res) => { | 35 | .subscribe((res) => { |
28 | 36 | ||
29 | this.articulos = res.data; | 37 | this.articulos = res.data; |
30 | this.paginationData = res.pagination; | 38 | this.paginationData = res.pagination; |
31 | this.filterItems(); | 39 | this.buscando = false; |
32 | }, error => console.error(error)); | 40 | }, error => console.error(error)); |
41 | |||
33 | } | 42 | } |
34 | 43 | ||
35 | onFileSelected(event, articulo: Producto) { | 44 | onFileSelected(event, articulo: Producto) { |
36 | 45 | ||
37 | let auxFiles: FileList = event.target.files; | 46 | let auxFiles: FileList = event.target.files; |
38 | Array.from(auxFiles).forEach(file => { | 47 | Array.from(auxFiles).forEach(file => { |
39 | 48 | ||
40 | this.onLoad(file) | 49 | this.onLoad(file) |
41 | .then(result => { | 50 | .then(result => { |
42 | // articulo.imagenes.push({ | 51 | // articulo.imagenes.push({ |
43 | // name: file.name + articulo.CodArt + articulo.CodSec, | 52 | // name: file.name + articulo.CodArt + articulo.CodSec, |
44 | // fromGallery: true, | 53 | // fromGallery: true, |
45 | // imagen: result, | 54 | // imagen: result, |
46 | // id_articulo: articulo.id | 55 | // id_articulo: articulo.id |
47 | // }); | 56 | // }); |
48 | let imagenAguardar = { | 57 | let imagenAguardar = { |
49 | imagen: { | 58 | imagen: { |
50 | name: `${articulo.CodSec}${articulo.CodArt}${file.name}`, | 59 | name: `${articulo.CodSec}${articulo.CodArt}${file.name}`, |
51 | base64: result, | 60 | base64: result, |
52 | codigo: articulo.CodArt, | 61 | codigo: articulo.CodArt, |
53 | sector: articulo.CodSec, | 62 | sector: articulo.CodSec, |
54 | id_articulo: articulo.id | 63 | id_articulo: articulo.id |
55 | }, | 64 | }, |
56 | articulo: articulo | 65 | articulo: articulo |
57 | }; | 66 | }; |
58 | this.saveInBase(imagenAguardar); | 67 | this.saveInBase(imagenAguardar); |
59 | }); | 68 | }); |
60 | }) | 69 | }) |
61 | } | 70 | } |
62 | 71 | ||
63 | filterItems() { | 72 | // filterItems() { |
64 | 73 | ||
65 | this.auxProductos = this.articulos.filter(x => { | 74 | // this.auxProductos = this.articulos.filter(x => { |
66 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) || | 75 | // return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) || |
67 | x.CodArt.toString().includes(this.searchTerm.toLowerCase()) || | 76 | // x.CodArt.toString().includes(this.searchTerm.toLowerCase()) || |
68 | x.CodSec.toString().includes(this.searchTerm.toLowerCase()); | 77 | // x.CodSec.toString().includes(this.searchTerm.toLowerCase()); |
69 | }); | 78 | // }); |
70 | } | 79 | // } |
71 | 80 | ||
72 | saveInBase(imagenAguardar) { | 81 | saveInBase(imagenAguardar) { |
73 | 82 | ||
74 | this.imagenService.saveInBase(imagenAguardar.imagen) | 83 | this.imagenService.saveInBase(imagenAguardar.imagen) |
75 | .subscribe(res => { | 84 | .subscribe(res => { |
76 | imagenAguardar.imagen['id'] = res[0]; | 85 | imagenAguardar.imagen['id'] = res[0]; |
77 | imagenAguardar.imagen['fromGallery'] = true; | 86 | imagenAguardar.imagen['fromGallery'] = true; |
78 | imagenAguardar.articulo.imagenes.push(imagenAguardar.imagen); | 87 | imagenAguardar.articulo.imagenes.push(imagenAguardar.imagen); |
79 | }, error => console.error(error)); | 88 | }, error => console.error(error)); |
80 | } | 89 | } |
81 | 90 | ||
82 | onLoad(file) { | 91 | onLoad(file) { |
83 | 92 | ||
84 | return new Promise((resolve, reject) => { | 93 | return new Promise((resolve, reject) => { |
85 | 94 | ||
86 | var fr = new FileReader(); | 95 | var fr = new FileReader(); |
87 | 96 | ||
88 | fr.onload = function () { | 97 | fr.onload = function () { |
89 | 98 | ||
90 | resolve(fr.result); | 99 | resolve(fr.result); |
91 | }; | 100 | }; |
92 | 101 | ||
93 | fr.readAsDataURL(file); | 102 | fr.readAsDataURL(file); |
94 | }); | 103 | }); |
95 | 104 | ||
96 | } | 105 | } |
97 | 106 | ||
98 | deleteImage(imagenes, index: number) { | 107 | deleteImage(imagenes, index: number) { |
99 | 108 | ||
100 | if (!imagenes[index].name) { | 109 | if (!imagenes[index].name) { |
101 | imagenes[index].name = imagenes[index].imagen; | 110 | imagenes[index].name = imagenes[index].imagen; |
102 | } | 111 | } |
103 | 112 | ||
104 | this.imagenService.deleteImage(imagenes[index]) | 113 | this.imagenService.deleteImage(imagenes[index]) |
105 | .subscribe(res => { | 114 | .subscribe(res => { |
106 | 115 | ||
107 | if (res) { | 116 | if (res) { |
108 | imagenes.splice(index, 1); | 117 | imagenes.splice(index, 1); |
109 | } | 118 | } |
110 | }, error => console.error(error)); | 119 | }, error => console.error(error)); |
111 | } | 120 | } |
112 | 121 | ||
113 | pageChanged(event: any): void { | 122 | pageChanged(event: any): void { |
114 | this.disabledPaginador = true; | 123 | this.disabledPaginador = true; |
115 | this.imagenService.getAllWithPaginator(event.page) | 124 | this.imagenService.getAllWithPaginator('', event.page) |
116 | .subscribe((res) => { | 125 | .subscribe((res) => { |
117 | this.disabledPaginador = false; | 126 | this.disabledPaginador = false; |
118 | this.articulos = res.data; | 127 | this.articulos = res.data; |
119 | this.paginationData = res.pagination; | 128 | this.paginationData = res.pagination; |
120 | this.filterItems(); | 129 | // this.filterItems(); |
121 | }, error => console.error(error)); | 130 | }, error => console.error(error)); |
122 | } | 131 | } |
123 | 132 | ||
124 | } | 133 | } |
125 | 134 |
src/app/services/imagenes.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { Observable } from 'rxjs'; | 3 | import { Observable } from 'rxjs'; |
4 | import { appSettings } from 'src/etc/AppSettings'; | 4 | import { appSettings } from 'src/etc/AppSettings'; |
5 | 5 | ||
6 | @Injectable({ | 6 | @Injectable({ |
7 | providedIn: 'root' | 7 | providedIn: 'root' |
8 | }) | 8 | }) |
9 | export class ImagenesService { | 9 | export class ImagenesService { |
10 | 10 | ||
11 | constructor(private http: HttpClient) { } | 11 | constructor(private http: HttpClient) { } |
12 | 12 | ||
13 | getAllWithPaginator(page: number = 1): Observable<any> { | 13 | getAllWithPaginator(search: string = '', page: number = 1): Observable<any> { |
14 | 14 | ||
15 | return this.http.get(`${appSettings.apiImagenes}/articulos/${page}`); | 15 | return this.http.post(`${appSettings.apiImagenes}/articulos`, { |
16 | page: page, | ||
17 | search: search | ||
18 | }); | ||
16 | } | 19 | } |
17 | 20 | ||
18 | saveInBase(body): Observable<any> { | 21 | saveInBase(body): Observable<any> { |
19 | 22 | ||
20 | return this.http.post(`${appSettings.apiImagenes}/imagenes/guardar`, body); | 23 | return this.http.post(`${appSettings.apiImagenes}/imagenes/guardar`, body); |
21 | } | 24 | } |
22 | 25 | ||
23 | deleteImage(body): Observable<any> { | 26 | deleteImage(body): Observable<any> { |
24 | 27 | ||
25 | return this.http.post(`${appSettings.apiImagenes}/imagen/borrar`, body); | 28 | return this.http.post(`${appSettings.apiImagenes}/imagen/borrar`, body); |
26 | } | 29 | } |
27 | 30 | ||
28 | } | 31 | } |
29 | 32 |