Commit 85c5e3d70b5341ec4e542e3f67403f9d01d601e2

Authored by Eric Fernandez
1 parent 2910dc012a
Exists in master and in 1 other branch validar_pve

pedidos salientes

src/app/components/pedidos-salientes/pedidos-salientes.component.html
1 <div class="bg-primary-gradient"> 1 <div class="bg-primary-gradient vh-100">
2 <div class="row"> 2 <div class="d-flex justify-content-center">
3 <div class="mx-auto my-5"> 3 <div class="row my-5 text-white text-center">
4 <h1>Su pedido ya esta listo.</h1> 4 <h1 class="col-12">Su pedido ya esta listo.</h1>
5 <h2 class="col-12 mt-3">Nº de Pedido</h2>
6
7 <h1 *ngIf="pedidosRecientes.length" class="col-12 border rounded">
8 {{rellenar(pedidosRecientes[0].id, 2)}}
9 </h1>
10
11 <h2 *ngFor="let pedido of pedidosRecientes; let i = index" [hidden]="i == 0" class="col-4 border rounded mx-1">
12 {{rellenar(pedido.id, 2)}}
13 </h2>
5 </div> 14 </div>
6 </div> 15 </div>
7 </div> 16 </div>
8 17
src/app/components/pedidos-salientes/pedidos-salientes.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { ComandaService } from 'src/app/services/comanda.service';
2 3
3 @Component({ 4 @Component({
4 selector: 'app-pedidos-salientes', 5 selector: 'app-pedidos-salientes',
5 templateUrl: './pedidos-salientes.component.html', 6 templateUrl: './pedidos-salientes.component.html',
6 styleUrls: ['./pedidos-salientes.component.scss'] 7 styleUrls: ['./pedidos-salientes.component.scss']
7 }) 8 })
8 export class PedidosSalientesComponent implements OnInit { 9 export class PedidosSalientesComponent implements OnInit {
9 10
10 constructor() { } 11 private pedidosRecientes = [];
12 private ciclo;
13
14 constructor(private comandaService: ComandaService) { }
11 15
12 ngOnInit() { 16 ngOnInit() {
17 this.buscar();
18
19 this.ciclo = setTimeout(() => {
20 this.buscar();
21 }, 5000)
22 }
23
24 ngOnDestroy() {
25
26 clearTimeout(this.ciclo);
13 } 27 }
14 28
29 buscar() {
30
31 this.comandaService
32 .getPendientesEntrega()
33 .subscribe((pedidos: []) => {
34
35 this.pedidosRecientes = pedidos;
36 }, console.log);
37 }
38
39 rellenar(relleno, longitud) {
40 relleno = '' + relleno;
41 while (relleno.length < longitud) {
42 relleno = '0' + relleno;
43 }
44 return relleno;
45 }
15 } 46 }
16 47
src/app/services/comanda.service.ts
1 import { Injectable } from "@angular/core"; 1 import { Injectable } from "@angular/core";
2 import { HttpClient } from "@angular/common/http"; 2 import { HttpClient } from "@angular/common/http";
3 import { appSettings } from "src/etc/AppSettings"; 3 import { appSettings } from "src/etc/AppSettings";
4 import { Observable } from "rxjs"; 4 import { Observable } from "rxjs";
5 import { Comanda } from '../wrappers/comanda'; 5 import { Comanda } from '../wrappers/comanda';
6 6
7 @Injectable({ 7 @Injectable({
8 providedIn: "root" 8 providedIn: "root"
9 }) 9 })
10 export class ComandaService { 10 export class ComandaService {
11 private apiUrl: string = appSettings.apiUrl; 11 private apiUrl: string = appSettings.apiUrl;
12 12
13 constructor(private http: HttpClient) { } 13 constructor(private http: HttpClient) { }
14 14
15 getAll(): Observable<any> { 15 getAll(): Observable<any> {
16 16
17 return this.http.get(`${this.apiUrl}/comandas`); 17 return this.http.get(`${this.apiUrl}/comandas`);
18 } 18 }
19 19
20 updateComanda(id: number, estado: number, observacion: string): Observable<any> { 20 updateComanda(id: number, estado: number, observacion: string): Observable<any> {
21 21
22 return this.http.get(`${this.apiUrl}/comandas/update/${id}/${estado}/${observacion}`); 22 return this.http.get(`${this.apiUrl}/comandas/update/${id}/${estado}/${observacion}`);
23 } 23 }
24
25 getPendientesEntrega() {
26 return this.http.get(`${this.apiUrl}/comandas/pendientes-entrega`);
27 }
24 } 28 }
25 29