comanda.component.ts
1.36 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
import { Component, OnInit } from '@angular/core';
import { appSettings } from 'src/etc/AppSettings';
import { ComandaService } from 'src/app/services/comanda.service';
import { Comanda } from 'src/app/wrappers/comanda';
import * as _ from 'lodash';
@Component({
selector: 'app-comanda',
templateUrl: './comanda.component.html',
styleUrls: ['./comanda.component.scss']
})
export class ComandaComponent implements OnInit {
private apiImagenes = appSettings.apiImagenes;
private comandas: Comanda[] = [];
private cicloTime;
constructor(
private comandaService: ComandaService
) { }
ngOnInit() {
this.buscar();
this.ciclo();
}
ngOnDestroy() {
clearTimeout(this.cicloTime);
}
buscar() {
this.comandaService.getAll()
.subscribe((res: Comanda[]) => {
if (!_.isEqual(res, this.comandas)) {
this.comandas = res;
}
}, e => console.error(e))
}
ciclo() {
this.cicloTime = setTimeout(() => {
this.buscar();
this.ciclo();
}, 5000);
}
updateComanda(comanda: Comanda, estadoNuevo: number, observacionNueva: string) {
this.comandaService.updateComanda(comanda.id, estadoNuevo, observacionNueva)
.subscribe(res => {
if (res.data) {
comanda.estado = estadoNuevo;
comanda.observacion = observacionNueva;
}
}, e => console.error(e))
}
}