comanda.component.ts
1.56 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
import { Component, OnInit } from '@angular/core';
import { ComandaService } from 'src/app/services/comanda.service';
import { Comanda } from 'src/app/wrappers/comanda';
import * as _ from 'lodash';
import { Title } from '@angular/platform-browser';
@Component({
selector: 'app-comanda',
templateUrl: './comanda.component.html',
styleUrls: ['./comanda.component.scss']
})
export class ComandaComponent implements OnInit {
private comandas: Comanda[] = [];
private cicloTime;
constructor(
private comandaService: ComandaService,
private titleService: Title
) {
this.titleService.setTitle('Comanda');
}
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))
}
rellenar(relleno, longitud) {
relleno = '' + relleno;
while (relleno.length < longitud) {
relleno = '0' + relleno;
}
return relleno;
}
}