Commit f0394b94c4919dc06dfde0b93ca272b3adc9b497

Authored by Marcelo Puebla
Exists in develop

Merge branch 'develop' into 'develop'

Develop

See merge request !135
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 7
8 @Component({ 8 @Component({
9 selector: 'app-sinonimo', 9 selector: 'app-sinonimo',
10 templateUrl: './sinonimo.component.html', 10 templateUrl: './sinonimo.component.html',
11 styleUrls: ['./sinonimo.component.scss'] 11 styleUrls: ['./sinonimo.component.scss']
12 }) 12 })
13 export class SinonimoComponent implements OnInit { 13 export class SinonimoComponent implements OnInit {
14 sinonimos: ISinonimo[] = []; 14 sinonimos: ISinonimo[] = [];
15 isValid: boolean; 15 isValid: boolean;
16 onClose: Subject<any>; 16 onClose: Subject<any>;
17 articulo: IArticulo; 17 articulo: IArticulo;
18 isSinonimoSelected = false; 18 isSinonimoSelected = false;
19 currentIndex = 0; 19 currentIndex = 0;
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 } 26 }
27 27
28 ngOnInit() { 28 ngOnInit() {
29 for (const s of this.sinonimos) { 29 for (const s of this.sinonimos) {
30 for (const a of s.productos) { 30 for (const a of s.productos) {
31 a.cantidad = 0; 31 a.cantidad = 0;
32 } 32 }
33 } 33 }
34 } 34 }
35 35
36 validate() { 36 validate() {
37 this.isValid = true; 37 this.isValid = true;
38 for (const s of this.sinonimos) { 38 for (const s of this.sinonimos) {
39 if (s.cantidadRestante > 0) { 39 if (s.cantidadRestante > 0) {
40 this.isValid = false; 40 this.isValid = false;
41 break; 41 break;
42 } 42 }
43 } 43 }
44 return !this.isValid ? 'disabled' : 'btn-effect'; 44 return !this.isValid ? 'disabled' : 'btn-effect';
45 } 45 }
46 46
47 validateNext() { 47 validateNext() {
48 const sinonimo = this.sinonimos[this.currentIndex] 48 const sinonimo = this.sinonimos[this.currentIndex];
49 sinonimo.selected = (sinonimo.cantidadRestante > 0) ? false : true; 49 sinonimo.selected = (sinonimo.cantidadRestante > 0) ? false : true;
50 return !sinonimo.selected ? 'disabled' : 'btn-effect'; 50 return !sinonimo.selected ? 'disabled' : 'btn-effect';
51 } 51 }
52 52
53 goNext() { 53 goNext() {
54 if (!this.sinonimos[this.currentIndex].selected) return; 54 if (!this.sinonimos[this.currentIndex].selected) return;
55 this.currentIndex++; 55 this.currentIndex++;
56 } 56 }
57 57
58 continue() { 58 continue() {
59 if (!this.isValid) return; 59 if (!this.isValid) return;
60 if (this.isSinonimoSelected) return; 60 if (this.isSinonimoSelected) return;
61 this.isSinonimoSelected = true; 61 this.isSinonimoSelected = true;
62 const observables = []; 62 const observables = [];
63 const cantidades = []; 63 const cantidades = [];
64 64
65 for (const s of this.sinonimos) { 65 for (const s of this.sinonimos) {
66 for (const articulo of s.productos) { 66 for (const articulo of s.productos) {
67 if (articulo.cantidad === 0) continue; 67 if (articulo.cantidad === 0) continue;
68 cantidades.push(articulo.cantidad); 68 cantidades.push(articulo.cantidad);
69 observables.push(this.articuloService.getById(articulo.id)); 69 observables.push(this.articuloService.getById(articulo.id));
70 } 70 }
71 } 71 }
72 forkJoin(observables) 72 forkJoin(observables)
73 .subscribe((res: IArticulo[]) => { 73 .subscribe((res: IArticulo[]) => {
74 res.forEach((articulo, i) => { 74 res.forEach((articulo, i) => {
75 articulo.cantidad = cantidades[i]; 75 articulo.cantidad = cantidades[i];
76 }); 76 });
77 this.modalRef.hide(); 77 this.modalRef.hide();
78 this.onClose.next({ 78 this.onClose.next({
79 articulos: res, 79 articulos: res,
80 }); 80 });
81 }, err => console.error(err)); 81 }, err => console.error(err));
82 } 82 }
83 83
84 sumarCantidadSinonimo(articulo: IArticulo, i: number) { 84 sumarCantidadSinonimo(articulo: IArticulo, i: number) {
85 if (this.sinonimos[i].cantidadRestante === 0) return; 85 if (this.sinonimos[i].cantidadRestante === 0) return;
86 articulo.cantidad++; 86 articulo.cantidad++;
87 this.sinonimos[i].cantidadRestante--; 87 this.sinonimos[i].cantidadRestante--;
88 } 88 }
89 89
90 restarCantidadSinonimo(articulo: IArticulo, i: number) { 90 restarCantidadSinonimo(articulo: IArticulo, i: number) {
91 if (this.sinonimos[i].cantidadRestante === this.sinonimos[i].cantidad) return; 91 if (this.sinonimos[i].cantidadRestante === this.sinonimos[i].cantidad) return;
92 if (articulo.cantidad === 0) return; 92 if (articulo.cantidad === 0) return;
93 articulo.cantidad--; 93 articulo.cantidad--;
94 this.sinonimos[i].cantidadRestante++; 94 this.sinonimos[i].cantidadRestante++;
95 } 95 }
96 96
97 scrollTo(index: number) { 97 scrollTo(index: number) {
98 const el = document.getElementById(index.toString()); 98 const el = document.getElementById(index.toString());
99 el.scrollIntoView({ behavior: 'smooth' }); 99 el.scrollIntoView({ behavior: 'smooth' });
100 } 100 }
101 101
102 close() { 102 close() {
103 this.modalRef.hide(); 103 this.modalRef.hide();
104 this.onClose.next(); 104 this.onClose.next();
105 } 105 }
106 106
107 } 107 }
108 108
src/app/utils/sound-manager.ts
1 export class SoundManager { 1 export class SoundManager {
2 public static playAudio(audioName: string) { 2 public static playAudio(audioName: string) {
3 let audio = new Audio(); 3 const audio = new Audio();
4 audio.src = `assets/sounds/${audioName}`; 4 audio.src = `assets/sounds/${audioName}`;
5 audio.load(); 5 audio.load();
6 audio.play(); 6 audio.play();
7 } 7 }
8 } 8 }
9 9