sinonimo.component.ts
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Component, OnInit } from '@angular/core';
import { ISinonimo } from 'src/app/interfaces/ISinonimo';
import { IArticulo } from 'src/app/interfaces/IArticulo';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { Subject, forkJoin } from 'rxjs';
import { ArticuloService } from 'src/app/services/articulo/articulo.service';
import { element } from 'protractor';
@Component({
selector: 'app-sinonimo',
templateUrl: './sinonimo.component.html',
styleUrls: ['./sinonimo.component.scss']
})
export class SinonimoComponent implements OnInit {
sinonimos: ISinonimo[] = [];
isValid: boolean;
onClose: Subject<any>;
articulosSelected: IArticulo[] = [];
constructor(
private modalRef: BsModalRef,
private articuloService: ArticuloService,
) {
this.onClose = new Subject();
this.articulosSelected.length = this.sinonimos.length;
}
ngOnInit() { }
selectSinonimo(index: number, articulo: IArticulo) {
for (const a of this.sinonimos[index].productos) {
a.seleccionado = false;
}
articulo.seleccionado = true;
this.articulosSelected[index] = articulo;
}
validate() {
this.isValid = true;
for (const s of this.sinonimos) {
for (const a of s.productos) {
this.isValid = (!a.seleccionado) ? false : true;
if (this.isValid) break;
}
if (!this.isValid) break;
}
return !this.isValid ? 'disabled' : 'btn-effect';
}
continue() {
if (!this.isValid) return;
const ID_SINS = [];
const observables = [];
for (const articulo of this.articulosSelected) {
ID_SINS.push(articulo.ID_SIN);
}
for (const articulo of this.articulosSelected) {
observables.push(this.articuloService.getById(articulo.id));
}
forkJoin(observables)
.subscribe((res: IArticulo[]) => {
for (const articulo of res) {
for (const ID_SIN of ID_SINS) {
articulo.ID_SIN = ID_SIN;
}
}
this.modalRef.hide();
this.onClose.next({
articulos: res,
});
}, err => console.error(err));
}
scrollTo(index: number) {
const element = document.getElementById(index.toString());
element.scrollIntoView({ behavior: "smooth", block: "center" });
}
}