Commit 086d324dc3aff3017b631689b056d056c7ffb8ba
1 parent
de017db211
Exists in
develop
Fix
Lint rules
Showing
2 changed files
with
3 additions
and
3 deletions
Show diff stats
src/app/modules/seleccion-articulos/filtro-categorias/filtro-categorias.component.ts
1 | import { Component, OnInit, HostListener, Output, EventEmitter } from '@angular/core'; | 1 | import { Component, OnInit, HostListener, Output, EventEmitter } from '@angular/core'; |
2 | import { ICategoria } from 'src/app/interfaces/ICategoria'; | 2 | import { ICategoria } from 'src/app/interfaces/ICategoria'; |
3 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 3 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
4 | import { CategoriaService } from 'src/app/services/categoria/categoria.service'; | 4 | import { CategoriaService } from 'src/app/services/categoria/categoria.service'; |
5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
6 | 6 | ||
7 | @Component({ | 7 | @Component({ |
8 | selector: 'app-filtro-categorias', | 8 | selector: 'app-filtro-categorias', |
9 | templateUrl: './filtro-categorias.component.html', | 9 | templateUrl: './filtro-categorias.component.html', |
10 | styleUrls: ['./filtro-categorias.component.scss'] | 10 | styleUrls: ['./filtro-categorias.component.scss'] |
11 | }) | 11 | }) |
12 | export class FiltroCategoriasComponent implements OnInit { | 12 | export class FiltroCategoriasComponent implements OnInit { |
13 | @Output() getProductos = new EventEmitter<any>(); | 13 | @Output() getProductos = new EventEmitter<any>(); |
14 | @Output() setProductos = new EventEmitter<any>(); | 14 | @Output() setProductos = new EventEmitter<any>(); |
15 | @Output() filterItems = new EventEmitter<any>(); | 15 | @Output() filterItems = new EventEmitter<any>(); |
16 | categorias: ICategoria[] = []; | 16 | categorias: ICategoria[] = []; |
17 | timeoutHandler: any; | 17 | timeoutHandler: any; |
18 | categoriaActive = null; | 18 | categoriaActive = null; |
19 | allActive = true; | 19 | allActive = true; |
20 | queMostrar = 'todos'; | 20 | queMostrar = 'todos'; |
21 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; | 21 | urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`; |
22 | 22 | ||
23 | constructor( | 23 | constructor( |
24 | private categoriaService: CategoriaService, | 24 | private categoriaService: CategoriaService, |
25 | private inactiveScreen: InactiveScreenService, | 25 | private inactiveScreen: InactiveScreenService, |
26 | ) { } | 26 | ) { } |
27 | 27 | ||
28 | ngOnInit() { | 28 | ngOnInit() { |
29 | this.mediaPantalla(); | 29 | this.mediaPantalla(); |
30 | } | 30 | } |
31 | 31 | ||
32 | getCategorias() { | 32 | getCategorias() { |
33 | this.categoriaService.getAll() | 33 | this.categoriaService.getAll() |
34 | .subscribe((categorias: ICategoria[]) => { | 34 | .subscribe((categorias: ICategoria[]) => { |
35 | switch (this.queMostrar) { | 35 | switch (this.queMostrar) { |
36 | case 'todos': | 36 | case 'todos': |
37 | this.categorias = categorias; | 37 | this.categorias = categorias; |
38 | this.categoriaActive = 0; | 38 | this.categoriaActive = 0; |
39 | break; | 39 | break; |
40 | case 'promociones': | 40 | case 'promociones': |
41 | this.categorias = categorias; | 41 | this.categorias = categorias; |
42 | this.categoriaActive = 19; | 42 | this.categoriaActive = 19; |
43 | break; | 43 | break; |
44 | case 'ordenar': | 44 | case 'ordenar': |
45 | this.categorias = categorias.filter((categoria: ICategoria) => { | 45 | this.categorias = categorias.filter((categoria: ICategoria) => { |
46 | return categoria.ES_PEDIDO; | 46 | return categoria.ES_PEDIDO; |
47 | }); | 47 | }); |
48 | this.categoriaActive = 4; | 48 | this.categoriaActive = 4; |
49 | break; | 49 | break; |
50 | default: | 50 | default: |
51 | this.categorias = categorias; | 51 | this.categorias = categorias; |
52 | this.categoriaActive = 0; | 52 | this.categoriaActive = 0; |
53 | break; | 53 | break; |
54 | } | 54 | } |
55 | !localStorage.getItem('articulos') ? | 55 | !localStorage.getItem('articulos') ? |
56 | this.getProductos.emit() : | 56 | this.getProductos.emit() : |
57 | this.setProductos.emit(); | 57 | this.setProductos.emit(); |
58 | }); | 58 | }); |
59 | this.mediaPantalla(); | 59 | this.mediaPantalla(); |
60 | } | 60 | } |
61 | 61 | ||
62 | selectCategoria(index: number, idCategoria?: number) { | 62 | selectCategoria(index: number, idCategoria?: number) { |
63 | if (this.categoriaActive === idCategoria) return; | 63 | if (this.categoriaActive === idCategoria) return; |
64 | this.categoriaActive = idCategoria; | 64 | this.categoriaActive = idCategoria; |
65 | this.allActive = idCategoria === 0 ? true : false; | 65 | this.allActive = idCategoria === 0 ? true : false; |
66 | this.categorias.forEach((categoria, i) => { | 66 | this.categorias.forEach((categoria, i) => { |
67 | categoria.selected = index === i ? true : false; | 67 | categoria.selected = index === i ? true : false; |
68 | }); | 68 | }); |
69 | this.filterItems.emit(); | 69 | this.filterItems.emit(); |
70 | } | 70 | } |
71 | 71 | ||
72 | @HostListener('scroll', ['$event']) | 72 | @HostListener('scroll', ['$event']) |
73 | scrollEvent(event: Event) { | 73 | scrollEvent(event: Event) { |
74 | clearTimeout(this.inactiveScreen.timerReposo); | 74 | clearTimeout(this.inactiveScreen.timerReposo); |
75 | this.inactiveScreen.startTimeOutInactividad(); | 75 | this.inactiveScreen.startTimeOutInactividad(); |
76 | } | 76 | } |
77 | 77 | ||
78 | mouseup() { | 78 | mouseup() { |
79 | if (!this.timeoutHandler) return; | 79 | if (!this.timeoutHandler) return; |
80 | clearInterval(this.timeoutHandler); | 80 | clearInterval(this.timeoutHandler); |
81 | } | 81 | } |
82 | 82 | ||
83 | scrollY(el: HTMLElement, value) { | 83 | scrollY(el: HTMLElement, value) { |
84 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 84 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
85 | this.timeoutHandler = setInterval(() => { | 85 | this.timeoutHandler = setInterval(() => { |
86 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); | 86 | el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); |
87 | }, 500); | 87 | }, 500); |
88 | } | 88 | } |
89 | 89 | ||
90 | mediaPantalla() { | 90 | mediaPantalla() { |
91 | if ($('body').hasClass('media-pantalla')) { | 91 | if ($('body').hasClass('media-pantalla')) { |
92 | $('.cat-content,#cat-content') | 92 | $('.cat-content,#cat-content') |
93 | .addClass('media-pantalla') | 93 | .addClass('media-pantalla') |
94 | .addBack('media-pantalla'); | 94 | .addBack('media-pantalla'); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 |
src/app/shared/sinonimo/sinonimo.component.ts
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; |
3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
4 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 4 | import { BsModalRef } from 'ngx-bootstrap/modal'; |
5 | import { Subject, forkJoin } from 'rxjs'; | 5 | import { Subject, forkJoin } from 'rxjs'; |
6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
7 | import { element } from 'protractor'; | 7 | import { element } from 'protractor'; |
8 | 8 | ||
9 | @Component({ | 9 | @Component({ |
10 | selector: 'app-sinonimo', | 10 | selector: 'app-sinonimo', |
11 | templateUrl: './sinonimo.component.html', | 11 | templateUrl: './sinonimo.component.html', |
12 | styleUrls: ['./sinonimo.component.scss'] | 12 | styleUrls: ['./sinonimo.component.scss'] |
13 | }) | 13 | }) |
14 | export class SinonimoComponent implements OnInit { | 14 | export class SinonimoComponent implements OnInit { |
15 | sinonimos: ISinonimo[] = []; | 15 | sinonimos: ISinonimo[] = []; |
16 | isValid: boolean; | 16 | isValid: boolean; |
17 | onClose: Subject<any>; | 17 | onClose: Subject<any>; |
18 | articulosSelected: IArticulo[] = []; | 18 | articulosSelected: IArticulo[] = []; |
19 | 19 | ||
20 | constructor( | 20 | constructor( |
21 | private modalRef: BsModalRef, | 21 | private modalRef: BsModalRef, |
22 | private articuloService: ArticuloService, | 22 | private articuloService: ArticuloService, |
23 | ) { | 23 | ) { |
24 | this.onClose = new Subject(); | 24 | this.onClose = new Subject(); |
25 | this.articulosSelected.length = this.sinonimos.length; | 25 | this.articulosSelected.length = this.sinonimos.length; |
26 | } | 26 | } |
27 | 27 | ||
28 | ngOnInit() { } | 28 | ngOnInit() { } |
29 | 29 | ||
30 | selectSinonimo(index: number, articulo: IArticulo) { | 30 | selectSinonimo(index: number, articulo: IArticulo) { |
31 | for (const a of this.sinonimos[index].productos) { | 31 | for (const a of this.sinonimos[index].productos) { |
32 | a.seleccionado = false; | 32 | a.seleccionado = false; |
33 | } | 33 | } |
34 | articulo.seleccionado = true; | 34 | articulo.seleccionado = true; |
35 | this.articulosSelected[index] = articulo; | 35 | this.articulosSelected[index] = articulo; |
36 | } | 36 | } |
37 | 37 | ||
38 | validate() { | 38 | validate() { |
39 | this.isValid = true; | 39 | this.isValid = true; |
40 | for (const s of this.sinonimos) { | 40 | for (const s of this.sinonimos) { |
41 | for (const a of s.productos) { | 41 | for (const a of s.productos) { |
42 | this.isValid = (!a.seleccionado) ? false : true; | 42 | this.isValid = (!a.seleccionado) ? false : true; |
43 | if (this.isValid) break; | 43 | if (this.isValid) break; |
44 | } | 44 | } |
45 | if (!this.isValid) break; | 45 | if (!this.isValid) break; |
46 | } | 46 | } |
47 | return !this.isValid ? 'disabled' : 'btn-effect'; | 47 | return !this.isValid ? 'disabled' : 'btn-effect'; |
48 | } | 48 | } |
49 | 49 | ||
50 | continue() { | 50 | continue() { |
51 | if (!this.isValid) return; | 51 | if (!this.isValid) return; |
52 | const ID_SINS = []; | 52 | const ID_SINS = []; |
53 | const observables = []; | 53 | const observables = []; |
54 | 54 | ||
55 | for (const articulo of this.articulosSelected) { | 55 | for (const articulo of this.articulosSelected) { |
56 | ID_SINS.push(articulo.ID_SIN); | 56 | ID_SINS.push(articulo.ID_SIN); |
57 | } | 57 | } |
58 | 58 | ||
59 | for (const articulo of this.articulosSelected) { | 59 | for (const articulo of this.articulosSelected) { |
60 | observables.push(this.articuloService.getById(articulo.id)); | 60 | observables.push(this.articuloService.getById(articulo.id)); |
61 | } | 61 | } |
62 | 62 | ||
63 | forkJoin(observables) | 63 | forkJoin(observables) |
64 | .subscribe((res: IArticulo[]) => { | 64 | .subscribe((res: IArticulo[]) => { |
65 | for (const articulo of res) { | 65 | for (const articulo of res) { |
66 | for (const ID_SIN of ID_SINS) { | 66 | for (const ID_SIN of ID_SINS) { |
67 | articulo.ID_SIN = ID_SIN; | 67 | articulo.ID_SIN = ID_SIN; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | this.modalRef.hide(); | 70 | this.modalRef.hide(); |
71 | this.onClose.next({ | 71 | this.onClose.next({ |
72 | articulos: res, | 72 | articulos: res, |
73 | }); | 73 | }); |
74 | }, err => console.error(err)); | 74 | }, err => console.error(err)); |
75 | } | 75 | } |
76 | 76 | ||
77 | scrollTo(index: number) { | 77 | scrollTo(index: number) { |
78 | const element = document.getElementById(index.toString()); | 78 | const el = document.getElementById(index.toString()); |
79 | element.scrollIntoView({ behavior: 'smooth', block: 'center' }); | 79 | el.scrollIntoView({ behavior: 'smooth', block: 'center' }); |
80 | } | 80 | } |
81 | 81 | ||
82 | } | 82 | } |
83 | 83 |