Se suben eventos a la BD, asociados a la discoteca del usuario

This commit is contained in:
2021-03-20 13:21:50 +01:00
parent f6756c25a8
commit 4b2d8cf7b6
8 changed files with 102 additions and 19 deletions

View File

@@ -21,7 +21,7 @@
<ion-item>
<label>
Fecha:
<ion-datetime displayFormat="DD/MM, HH:mm"placeholder="Elegir Fecha" formControlName="fecha"></ion-datetime>
<ion-datetime displayFormat="YYYY/DD/MM"placeholder="Elegir Fecha" formControlName="fecha"></ion-datetime>
</label>
<span
*ngIf="fecha.errors.required && submitted">
@@ -29,6 +29,17 @@
</span>
</ion-item>
<ion-item>
<label>
Hora
<ion-datetime displayFormat="HH:MM"placeholder="Elegir Hora" formControlName="hora"></ion-datetime>
</label>
<span
*ngIf="hora.errors.required && submitted">
Tu evento necesita una hora
</span>
</ion-item>
<ion-item>
<label>

View File

@@ -3,6 +3,9 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Tab1Service } from '../tab1/tab1.service';
import { Evento } from '../evento';
import { Router } from '@angular/router';
import { Eventoi } from '../interfaces/eventoi';
import { DatePipe } from '@angular/common'
import { ViewEventoPageRoutingModule } from '../view-evento/view-evento-routing.module';
@Component({
selector: 'app-prompt-evento',
@@ -10,17 +13,17 @@ import { Router } from '@angular/router';
styleUrls: ['./prompt-evento.page.scss'],
})
export class PromptEventoPage implements OnInit{
submitted = false;
eventoForm = new FormGroup({
nombre: new FormControl('', Validators.required),
fecha: new FormControl('', Validators.required),
precio1: new FormControl('', Validators.required),
precio2: new FormControl('', Validators.required),
descripcion: new FormControl('', Validators.required),
nombre: new FormControl(null, Validators.required),
fecha: new FormControl(null, Validators.required),
hora: new FormControl(null, Validators.required),
precio1: new FormControl(null, Validators.required),
precio2: new FormControl(null, Validators.required),
descripcion: new FormControl(null, Validators.required),
});
eventos: Evento[];
eventos: Eventoi[];
constructor(private tab1Service: Tab1Service, private router: Router) {
@@ -36,28 +39,38 @@ export class PromptEventoPage implements OnInit{
if (this.eventoForm.valid){
let evento = new Evento();
this.asignarEvento(evento);
this.router.navigate(['/tabs']);
}
}
asignarEvento(evento: Evento){
evento.setNombre(this.eventoForm.get('nombre').value);
evento.setDesc(this.eventoForm.get('descripcion').value);
evento.setFecha(this.eventoForm.get('fecha').value);
var fecha = this.eventoForm.get('fecha').value;
fecha = fecha.split("T")[0];
evento.setFecha(fecha);
var hora = this.eventoForm.get('hora').value;
hora = hora.split("T")[1];
hora = hora.split(":")[0]+(":")+hora.split(":")[1];
evento.setHora(hora);
evento.setPrecio1(this.eventoForm.get('precio1').value);
evento.setPrecio2(this.eventoForm.get('precio2').value);
//evento.setDia(evento.getFecha()); el datetime de Ion devuelve un String, no se puede
//evento.setHora(evento.getFecha()); transformar en dia y hora
if (!this.tab1Service.eventos){
this.tab1Service.initEventos();}
if(!this.tab1Service.eventoForms){
this.tab1Service.initEventoForms();}
let eventoInterface = this.interfaceEvento(evento);
if(this.tab1Service.editarEvento==true){
this.tab1Service.eventos[this.tab1Service.eventoIndex] = evento;
this.tab1Service.eventoForms[this.tab1Service.eventoIndex] = this.eventoForm;
this.tab1Service.updateEvento(eventoInterface);
//this.tab1Service.eventos[this.tab1Service.eventoIndex] = evento;
//this.tab1Service.eventoForms[this.tab1Service.eventoIndex] = this.eventoForm;
}
else{
this.tab1Service.eventos.push(evento);
this.tab1Service.eventoForms.push(this.eventoForm);}
this.tab1Service.postEvento(eventoInterface);
//this.tab1Service.eventos.push(evento);
//this.tab1Service.eventoForms.push(this.eventoForm);
}
}
@@ -84,6 +97,23 @@ export class PromptEventoPage implements OnInit{
get descripcion(){
return this.eventoForm.get('descripcion');
}
interfaceEvento(evento: Evento): Eventoi{
let eventoInterface: Eventoi;
eventoInterface = {
discotecaID: this.tab1Service.discotecaI.discotecaID,
nombre: evento.nombre,
localizacion: this.tab1Service.discotecaI.localizacion,
fecha: evento.fecha,
hora: evento.hora,
descripcion: evento.descripcion,
precio1: evento.precio1,
precio2: evento.precio2,
}
return eventoInterface;
}
}