Commit 7569cac3604441504fa278021e555d0a93b91f39

Authored by Marcelo Puebla
1 parent 83dfaec486
Exists in develop

Add

Sonido al agregarse una nueva comanda.
src/app/modules/comanda/comanda.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { IComanda, IComandaDetalle, IComponente } from 'src/app/interfaces/IComanda'; 2 import { IComanda, IComandaDetalle, IComponente } from 'src/app/interfaces/IComanda';
3 import { ComandaService } from 'src/app/services/comanda/comanda.service'; 3 import { ComandaService } from 'src/app/services/comanda/comanda.service';
4 import * as _ from 'lodash'; 4 import * as _ from 'lodash';
5 import { SoundManager } from 'src/app/utils/sound-manager';
5 6
6 @Component({ 7 @Component({
7 selector: 'app-comanda', 8 selector: 'app-comanda',
8 templateUrl: './comanda.component.html', 9 templateUrl: './comanda.component.html',
9 styleUrls: ['./comanda.component.scss'] 10 styleUrls: ['./comanda.component.scss']
10 }) 11 })
11 export class ComandaComponent implements OnInit { 12 export class ComandaComponent implements OnInit {
12 comandas: IComanda[] = []; 13 comandas: IComanda[] = [];
13 cicloTime: any; 14 cicloTime: any;
14 15
15 constructor( 16 constructor(
16 private comandaService: ComandaService, 17 private comandaService: ComandaService,
17 ) { } 18 ) { }
18 19
19 ngOnInit() { 20 ngOnInit() {
20 this.getComandas(); 21 this.getComandas();
21 this.timerGetComandas(); 22 this.timerGetComandas();
22 } 23 }
23 24
24 OnDestroy() { 25 OnDestroy() {
25 clearInterval(this.cicloTime); 26 clearInterval(this.cicloTime);
26 } 27 }
27 28
28 timerGetComandas() { 29 timerGetComandas() {
29 this.cicloTime = setInterval(() => { 30 this.cicloTime = setInterval(() => {
30 this.getComandas(); 31 this.getComandas();
31 }, 5000); 32 }, 5000);
32 } 33 }
33 34
34 getComandas() { 35 getComandas() {
35 this.comandaService.getAll() 36 this.comandaService.getAll()
36 .subscribe((resComandas: IComanda[]) => { 37 .subscribe((resComandas: IComanda[]) => {
37 this.addNewComandas(resComandas); 38 this.addNewComandas(resComandas);
38 }, e => console.error(e)); 39 }, e => console.error(e));
39 } 40 }
40 41
41 addNewComandas(resComandas: IComanda[]) { 42 addNewComandas(resComandas: IComanda[]) {
42 for (let j = 0; j < resComandas.length; j++) { 43 for (let j = 0; j < resComandas.length; j++) {
43 for (const comanda of this.comandas) { 44 for (const comanda of this.comandas) {
44 if (comanda.id === resComandas[j].id) { 45 if (comanda.id === resComandas[j].id) {
45 resComandas.splice(j, 1); 46 resComandas.splice(j, 1);
46 } 47 }
47 } 48 }
48 } 49 }
49 if (!resComandas.length) return; 50 if (!resComandas.length) return;
51 SoundManager.playAudio('beep-01a.wav');
50 Array.prototype.push.apply(this.comandas, resComandas); 52 Array.prototype.push.apply(this.comandas, resComandas);
51 this.startTimersPedido(resComandas); 53 this.startTimersPedido(resComandas);
52 } 54 }
53 55
54 updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) { 56 updateComanda(comanda: IComanda, estadoNuevo: number, observacionNueva: string) {
55 const data = { 57 const data = {
56 idComanda: comanda.id, 58 idComanda: comanda.id,
57 estado: estadoNuevo, 59 estado: estadoNuevo,
58 observacion: observacionNueva, 60 observacion: observacionNueva,
59 tiempoEspera: `${comanda.hoursPedido}:${comanda.secondsPedido}:${comanda.secondsPedido}`, 61 tiempoEspera: `${comanda.hoursPedido}:${comanda.secondsPedido}:${comanda.secondsPedido}`,
60 tiempoElaboracion: `${comanda.hoursElaboracion}:${comanda.secondsElaboracion}:${comanda.secondsElaboracion}`, 62 tiempoElaboracion: `${comanda.hoursElaboracion}:${comanda.secondsElaboracion}:${comanda.secondsElaboracion}`,
61 }; 63 };
62 if (data.estado === 3) { 64 if (data.estado === 3) {
63 this.comandaService.imprimirComandaCocina(parseInt(data.idComanda, 10)) 65 this.comandaService.imprimirComandaCocina(parseInt(data.idComanda, 10))
64 .subscribe(res => { }, err => console.error(err) 66 .subscribe(res => { }, err => console.error(err)
65 ); 67 );
66 } 68 }
67 69
68 if (estadoNuevo !== 2) comanda.detalles.forEach(d => d.seeDetalle = false); 70 if (estadoNuevo !== 2) comanda.detalles.forEach(d => d.seeDetalle = false);
69 71
70 this.comandaService.update(data) 72 this.comandaService.update(data)
71 .subscribe((res: any) => { 73 .subscribe((res: any) => {
72 if (res.data) { 74 if (res.data) {
73 comanda.estado = estadoNuevo; 75 comanda.estado = estadoNuevo;
74 comanda.observacion = observacionNueva; 76 comanda.observacion = observacionNueva;
75 if (estadoNuevo === 2) { 77 if (estadoNuevo === 2) {
76 this.startTimerElaboracion(comanda); 78 this.startTimerElaboracion(comanda);
77 } else if (comanda.timerElaboracion) { 79 } else if (comanda.timerElaboracion) {
78 clearInterval(comanda.timerElaboracion); 80 clearInterval(comanda.timerElaboracion);
79 } 81 }
80 } 82 }
81 }, e => console.error(e)); 83 }, e => console.error(e));
82 } 84 }
83 85
84 rellenar(relleno, longitud) { 86 rellenar(relleno, longitud) {
85 relleno = '' + relleno; 87 relleno = '' + relleno;
86 while (relleno.length < longitud) { 88 while (relleno.length < longitud) {
87 relleno = '0' + relleno; 89 relleno = '0' + relleno;
88 } 90 }
89 return relleno; 91 return relleno;
90 } 92 }
91 93
92 toggleVerComponentes(detalle: IComandaDetalle, comanda: IComanda) { 94 toggleVerComponentes(detalle: IComandaDetalle, comanda: IComanda) {
93 detalle.seeDetalle = !detalle.seeDetalle; 95 detalle.seeDetalle = !detalle.seeDetalle;
94 } 96 }
95 97
96 hasTipo(componentes: IComponente[]) { 98 hasTipo(componentes: IComponente[]) {
97 return componentes.some(c => c.tipoArticulo === 6); 99 return componentes.some(c => c.tipoArticulo === 6);
98 } 100 }
99 101
100 //#region TIMERS 102 //#region TIMERS
101 startTimersPedido(comandas) { 103 startTimersPedido(comandas) {
102 comandas.forEach((comanda: IComanda) => { 104 comandas.forEach((comanda: IComanda) => {
103 this.comandaService.startTimerComanda(comanda, 'Pedido'); 105 this.comandaService.startTimerComanda(comanda, 'Pedido');
104 if (comanda.estado === 2) { 106 if (comanda.estado === 2) {
105 this.startTimerElaboracion(comanda); 107 this.startTimerElaboracion(comanda);
106 } 108 }
107 }); 109 });
108 } 110 }
109 111
110 startTimerElaboracion(comanda: IComanda) { 112 startTimerElaboracion(comanda: IComanda) {
111 this.comandaService.startTimerComanda(comanda, 'Elaboracion'); 113 this.comandaService.startTimerComanda(comanda, 'Elaboracion');
112 } 114 }
113 //#endregion 115 //#endregion
114 116
115 } 117 }
116 118
src/app/utils/sound-manager.ts
File was created 1 export class SoundManager {
2 public static playAudio(audioName: string) {
3 let audio = new Audio();
4 audio.src = `assets/sounds/${audioName}`;
5 audio.load();
6 audio.play();
7 }
8 }
src/assets/sounds/beep-01a.wav
No preview for this file type