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