Commit 189cd83e6c3742152c7eda947e3fe4cb7a519da8
1 parent
b49b5da579
Exists in
develop
Fix
Auto scroll sinonimos
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
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 | articulo: IArticulo; | 19 | articulo: IArticulo; |
20 | 20 | ||
21 | constructor( | 21 | constructor( |
22 | private modalRef: BsModalRef, | 22 | private modalRef: BsModalRef, |
23 | private articuloService: ArticuloService, | 23 | private articuloService: ArticuloService, |
24 | ) { | 24 | ) { |
25 | this.onClose = new Subject(); | 25 | this.onClose = new Subject(); |
26 | this.articulosSelected.length = this.sinonimos.length; | 26 | this.articulosSelected.length = this.sinonimos.length; |
27 | } | 27 | } |
28 | 28 | ||
29 | ngOnInit() { } | 29 | ngOnInit() { } |
30 | 30 | ||
31 | selectSinonimo(index: number, articulo: IArticulo) { | 31 | selectSinonimo(index: number, articulo: IArticulo) { |
32 | for (const a of this.sinonimos[index].productos) { | 32 | for (const a of this.sinonimos[index].productos) { |
33 | a.seleccionado = false; | 33 | a.seleccionado = false; |
34 | } | 34 | } |
35 | articulo.seleccionado = true; | 35 | articulo.seleccionado = true; |
36 | this.articulosSelected[index] = articulo; | 36 | this.articulosSelected[index] = articulo; |
37 | } | 37 | } |
38 | 38 | ||
39 | validate() { | 39 | validate() { |
40 | this.isValid = true; | 40 | this.isValid = true; |
41 | for (const s of this.sinonimos) { | 41 | for (const s of this.sinonimos) { |
42 | for (const a of s.productos) { | 42 | for (const a of s.productos) { |
43 | this.isValid = (!a.seleccionado) ? false : true; | 43 | this.isValid = (!a.seleccionado) ? false : true; |
44 | if (this.isValid) break; | 44 | if (this.isValid) break; |
45 | } | 45 | } |
46 | if (!this.isValid) break; | 46 | if (!this.isValid) break; |
47 | } | 47 | } |
48 | return !this.isValid ? 'disabled' : 'btn-effect'; | 48 | return !this.isValid ? 'disabled' : 'btn-effect'; |
49 | } | 49 | } |
50 | 50 | ||
51 | continue() { | 51 | continue() { |
52 | if (!this.isValid) return; | 52 | if (!this.isValid) return; |
53 | const ID_SINS = []; | 53 | const ID_SINS = []; |
54 | const observables = []; | 54 | const observables = []; |
55 | 55 | ||
56 | for (const articulo of this.articulosSelected) { | 56 | for (const articulo of this.articulosSelected) { |
57 | ID_SINS.push(articulo.ID_SIN); | 57 | ID_SINS.push(articulo.ID_SIN); |
58 | } | 58 | } |
59 | 59 | ||
60 | for (const articulo of this.articulosSelected) { | 60 | for (const articulo of this.articulosSelected) { |
61 | observables.push(this.articuloService.getById(articulo.id)); | 61 | observables.push(this.articuloService.getById(articulo.id)); |
62 | } | 62 | } |
63 | 63 | ||
64 | forkJoin(observables) | 64 | forkJoin(observables) |
65 | .subscribe((res: IArticulo[]) => { | 65 | .subscribe((res: IArticulo[]) => { |
66 | for (const articulo of res) { | 66 | for (const articulo of res) { |
67 | for (const ID_SIN of ID_SINS) { | 67 | for (const ID_SIN of ID_SINS) { |
68 | articulo.ID_SIN = ID_SIN; | 68 | articulo.ID_SIN = ID_SIN; |
69 | } | 69 | } |
70 | } | 70 | } |
71 | this.modalRef.hide(); | 71 | this.modalRef.hide(); |
72 | this.onClose.next({ | 72 | this.onClose.next({ |
73 | articulos: res, | 73 | articulos: res, |
74 | }); | 74 | }); |
75 | }, err => console.error(err)); | 75 | }, err => console.error(err)); |
76 | } | 76 | } |
77 | 77 | ||
78 | scrollTo(index: number) { | 78 | scrollTo(index: number) { |
79 | const el = document.getElementById(index.toString()); | 79 | const el = document.getElementById(index.toString()); |
80 | el.scrollIntoView({ behavior: 'smooth', block: 'center' }); | 80 | el.scrollIntoView({ behavior: 'smooth' }); |
81 | } | 81 | } |
82 | 82 | ||
83 | } | 83 | } |
84 | 84 |