Commit 6d80a4cfb905ff5c44f03c53d899664124c3698d

Authored by Marcelo Puebla
1 parent a12ccbf62d
Exists in develop

Fix

Borrado import sin usoi
src/app/modules/seleccion-articulos/filtro-categorias/filtro-categorias.component.ts
1 import { Component, OnInit, Input, 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 29
30 getCategorias() { 30 getCategorias() {
31 this.categoriaService.getAll() 31 this.categoriaService.getAll()
32 .subscribe((categorias: ICategoria[]) => { 32 .subscribe((categorias: ICategoria[]) => {
33 switch (this.queMostrar) { 33 switch (this.queMostrar) {
34 case 'todos': 34 case 'todos':
35 this.categorias = categorias; 35 this.categorias = categorias;
36 this.categoriaActive = 0; 36 this.categoriaActive = 0;
37 break; 37 break;
38 case 'promociones': 38 case 'promociones':
39 this.categorias = categorias; 39 this.categorias = categorias;
40 this.categoriaActive = 19; 40 this.categoriaActive = 19;
41 break; 41 break;
42 case 'ordenar': 42 case 'ordenar':
43 this.categorias = categorias.filter((categoria: ICategoria) => { 43 this.categorias = categorias.filter((categoria: ICategoria) => {
44 return categoria.ES_PEDIDO; 44 return categoria.ES_PEDIDO;
45 }); 45 });
46 this.categoriaActive = 4; 46 this.categoriaActive = 4;
47 break; 47 break;
48 default: 48 default:
49 this.categorias = categorias; 49 this.categorias = categorias;
50 this.categoriaActive = 0; 50 this.categoriaActive = 0;
51 break; 51 break;
52 } 52 }
53 !localStorage.getItem('articulos') ? 53 !localStorage.getItem('articulos') ?
54 this.getProductos.emit() : 54 this.getProductos.emit() :
55 this.setProductos.emit(); 55 this.setProductos.emit();
56 }); 56 });
57 } 57 }
58 58
59 selectCategoria(index: number, idCategoria?: number) { 59 selectCategoria(index: number, idCategoria?: number) {
60 if (this.categoriaActive === idCategoria) return; 60 if (this.categoriaActive === idCategoria) return;
61 this.categoriaActive = idCategoria; 61 this.categoriaActive = idCategoria;
62 this.allActive = idCategoria === 0 ? true : false; 62 this.allActive = idCategoria === 0 ? true : false;
63 this.categorias.forEach((categoria, i) => { 63 this.categorias.forEach((categoria, i) => {
64 categoria.selected = index === i ? true : false; 64 categoria.selected = index === i ? true : false;
65 }); 65 });
66 this.filterItems.emit(); 66 this.filterItems.emit();
67 } 67 }
68 68
69 @HostListener('scroll', ['$event']) 69 @HostListener('scroll', ['$event'])
70 scrollEvent(event: Event) { 70 scrollEvent(event: Event) {
71 clearTimeout(this.inactiveScreen.timerReposo); 71 clearTimeout(this.inactiveScreen.timerReposo);
72 this.inactiveScreen.startTimeOutInactividad(); 72 this.inactiveScreen.startTimeOutInactividad();
73 } 73 }
74 74
75 mouseup() { 75 mouseup() {
76 if (!this.timeoutHandler) return; 76 if (!this.timeoutHandler) return;
77 clearInterval(this.timeoutHandler); 77 clearInterval(this.timeoutHandler);
78 } 78 }
79 79
80 scrollY(el: HTMLElement, value) { 80 scrollY(el: HTMLElement, value) {
81 el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); 81 el.scroll({ behavior: 'smooth', top: value + el.scrollTop });
82 this.timeoutHandler = setInterval(() => { 82 this.timeoutHandler = setInterval(() => {
83 el.scroll({ behavior: 'smooth', top: value + el.scrollTop }); 83 el.scroll({ behavior: 'smooth', top: value + el.scrollTop });
84 }, 500); 84 }, 500);
85 } 85 }
86 } 86 }
87 87