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