pedidos-salientes.component.ts 1.01 KB
import { Component, OnInit } from '@angular/core';
import { ComandaService } from 'src/app/services/comanda/comanda.service';

@Component({
  selector: 'app-pedidos-salientes',
  templateUrl: './pedidos-salientes.component.html',
  styleUrls: ['./pedidos-salientes.component.scss']
})
export class PedidosSalientesComponent implements OnInit {
  pedidosPendientes = [];
  cicloTime;

  constructor(
    private comandaServices: ComandaService
  ) { }

  ngOnInit() {
    this.buscarPedidosPendientes();
    this.ciclo()
  }

  ngOnDestroy() {
    clearTimeout(this.cicloTime);
  }

  buscarPedidosPendientes() {
    this.comandaServices.getPendientesEntrega()
    .subscribe((pedidos: []) => {
      this.pedidosPendientes = pedidos
    })
  }

  ciclo() {
    this.cicloTime = setTimeout(() => {
      this.buscarPedidosPendientes();
      this.ciclo();
    }, 5000)
  }

  rellenar(relleno, longitud) {
    relleno = '' + relleno;
    while (relleno.length < longitud) {
      relleno = '0' + relleno;
    }
    return relleno;
  }

}