Discofy/src/app/tab1/tab1.service.ts

93 lines
2.1 KiB
TypeScript

import { Injectable, OnInit } from '@angular/core';
import { stringify } from 'querystring';
import { Tab1Page } from './tab1.page'
import { Discoteca } from '../discoteca'
import { Evento } from '../evento';
import { FormControl, FormGroup } from '@angular/forms';
import { NumericValueAccessor } from '@ionic/angular';
import { DiscotecaI } from '../discoteca-i';
import { ApiService } from '../api.service';
import { Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class Tab1Service implements OnInit{
discoteca: Discoteca;
discotecaI: DiscotecaI;
galeria: string[];
eventos: Evento[];
eventoForms: FormGroup[];
eventoIndex: number;
editarEvento: boolean;
constructor(private apiService: ApiService, private router: Router) {
}
ngOnInit(){
this.initValues();
}
initValues(): void{
this.discoteca = new Discoteca();
this.discoteca.setNombre(this.discotecaI.nombre);
this.discoteca.setTelefono(this.discotecaI.telefono);
this.discoteca.setLocalizacion(this.discotecaI.localizacion);
this.galeria = [];
this.initEventos();
this.editarEvento = false;
}
getNombre(): string{
this.initValues();
return this.discoteca.getNombre();
}
getTelefono(): number{
this.initValues();
return this.discoteca.getTelefono();
}
getLocalizacion(): string{
this.initValues();
return this.discoteca.getLocalizacion();
}
getEventos(): Evento[]{
return this.eventos;
}
getDescripcion(): string{
this.initValues();
return this.discoteca.getDescripcion();
}
initEventos(): void{
this.eventos = [];
}
initEventoForms(): void{
this.eventoForms = [];
}
getEventobyIndex(eventoIndex: number){
return this.eventos[eventoIndex];
}
getDiscoteca(discotecaId: number){
if (discotecaId != 0){
this.apiService.getUserDiscoteca(discotecaId)
.subscribe(discoteca => {
this.discotecaI = discoteca[0];
console.log(this.discotecaI);
this.initValues();
this.router.navigate(['/tabs/tab1/perfil-discoteca']);
})
}
}
}