From 57ce386197479e20007a25c5b7dd9c434b2f0202 Mon Sep 17 00:00:00 2001 From: mpuebla Date: Fri, 11 Oct 2019 17:23:29 -0300 Subject: [PATCH] Creado componente de configuracion --- src/app/app.module.ts | 6 +- .../configuracion/configuracion.component.html | 75 +++++++++++++++++++++ .../configuracion/configuracion.component.scss | 4 ++ .../configuracion/configuracion.component.spec.ts | 25 +++++++ .../configuracion/configuracion.component.ts | 78 ++++++++++++++++++++++ 5 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 src/app/components/configuracion/configuracion.component.html create mode 100644 src/app/components/configuracion/configuracion.component.scss create mode 100644 src/app/components/configuracion/configuracion.component.spec.ts create mode 100644 src/app/components/configuracion/configuracion.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index a457512..2eced1c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -33,6 +33,7 @@ import { MensajeFinalComponent } from './components/mensaje-final/mensaje-final. import { ComandaComponent } from './components/comanda/comanda.component'; import { PedidosSalientesComponent } from './components/pedidos-salientes/pedidos-salientes.component'; import { PagoConTarjetaComponent } from './components/pago-con-tarjeta/pago-con-tarjeta.component'; +import { ConfiguracionComponent } from './components/configuracion/configuracion.component'; //#endregion @NgModule({ @@ -51,7 +52,8 @@ import { PagoConTarjetaComponent } from './components/pago-con-tarjeta/pago-con- MensajeFinalComponent, ComandaComponent, PedidosSalientesComponent, - PagoConTarjetaComponent + PagoConTarjetaComponent, + ConfiguracionComponent ], imports: [ BrowserModule, @@ -71,6 +73,6 @@ import { PagoConTarjetaComponent } from './components/pago-con-tarjeta/pago-con- ], providers: [], bootstrap: [AppComponent], - entryComponents: [PagoConTarjetaComponent] + entryComponents: [PagoConTarjetaComponent, ConfiguracionComponent] }) export class AppModule { } diff --git a/src/app/components/configuracion/configuracion.component.html b/src/app/components/configuracion/configuracion.component.html new file mode 100644 index 0000000..2eae692 --- /dev/null +++ b/src/app/components/configuracion/configuracion.component.html @@ -0,0 +1,75 @@ + + + diff --git a/src/app/components/configuracion/configuracion.component.scss b/src/app/components/configuracion/configuracion.component.scss new file mode 100644 index 0000000..11f8414 --- /dev/null +++ b/src/app/components/configuracion/configuracion.component.scss @@ -0,0 +1,4 @@ +.disabled { + pointer-events: none; + opacity: 0.5; +} diff --git a/src/app/components/configuracion/configuracion.component.spec.ts b/src/app/components/configuracion/configuracion.component.spec.ts new file mode 100644 index 0000000..dad3f86 --- /dev/null +++ b/src/app/components/configuracion/configuracion.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ConfiguracionComponent } from './configuracion.component'; + +describe('ConfiguracionComponent', () => { + let component: ConfiguracionComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ConfiguracionComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ConfiguracionComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/configuracion/configuracion.component.ts b/src/app/components/configuracion/configuracion.component.ts new file mode 100644 index 0000000..39ee282 --- /dev/null +++ b/src/app/components/configuracion/configuracion.component.ts @@ -0,0 +1,78 @@ +import { Component, OnInit } from '@angular/core'; +import { BsModalRef } from 'ngx-bootstrap'; +import { PuntoVentaService } from 'src/app/services/punto-venta.service'; +import { PuntoVenta } from 'src/app/wrappers/puntoVenta'; +import { ImpresoraService } from 'src/app/services/impresora.service'; +import { Impresora } from 'src/app/wrappers/impresora'; +import { FormGroup, FormControl } from '@angular/forms'; + +@Component({ + selector: 'app-configuracion', + templateUrl: './configuracion.component.html', + styleUrls: ['./configuracion.component.scss'] +}) +export class ConfiguracionComponent implements OnInit { + + puntosVenta: PuntoVenta[] = []; + impresoras: Impresora[] = []; + form: FormGroup; + + constructor( + private activeModal: BsModalRef, + private puntoVentaService: PuntoVentaService, + private impresoraService: ImpresoraService, + ) { } + + ngOnInit() { + + this.form = new FormGroup({ + usePlanillaPropia: new FormControl(false, []), + puntoVenta: new FormControl(null, []), + impresora: new FormControl(null, []), + }) + + this.puntoVentaService.getAll() + .subscribe((res: PuntoVenta[]) => { + + this.puntosVenta = res; + this.setPuntoVenta(); + }, console.error); + + this.impresoraService.getAll() + .subscribe((res: Impresora[]) => { + + this.impresoras = res; + this.setImpresora(); + }, console.error); + + } + + close() { + + this.activeModal.hide(); + } + + acept() { + + let auxPuntoVenta = this.puntosVenta.find(p => p.ID === this.form.get('puntoVenta').value); + let auxImpresora = this.impresoras.find(p => p.PVE === this.form.get('impresora').value); + localStorage.setItem('pve', auxPuntoVenta ? auxPuntoVenta.ID.toString() : null); + localStorage.setItem('impresoraPVE', auxImpresora ? auxImpresora.PVE.toString() : null); + this.close(); + } + + setPuntoVenta() { + + let pve = parseInt(localStorage.getItem('pve')); + let auxPuntoVenta = this.puntosVenta.find(x => x.ID === pve); + this.form.get('puntoVenta').setValue(auxPuntoVenta ? auxPuntoVenta.ID : null); + } + + setImpresora() { + + let impresoraPVE = parseInt(localStorage.getItem('impresoraPVE')); + let auxImpresora = this.impresoras.find(x => x.PVE === impresoraPVE); + this.form.get('impresora').setValue(auxImpresora ? auxImpresora.PVE : null); + } + +} -- 1.9.1