genera un codigo aleatorio y lo muestra en un prompt

This commit is contained in:
onsaliyo 2021-05-20 19:17:29 +02:00
parent 024f768da9
commit 9817883235
6 changed files with 63 additions and 4 deletions

View File

@ -5,5 +5,5 @@
</ion-header> </ion-header>
<ion-content> <ion-content>
{{codigoReserva}}
</ion-content> </ion-content>

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { NavParams } from '@ionic/angular';
@Component({ @Component({
selector: 'app-reservamodal', selector: 'app-reservamodal',
@ -7,9 +8,11 @@ import { Component, OnInit } from '@angular/core';
}) })
export class ReservamodalPage implements OnInit { export class ReservamodalPage implements OnInit {
constructor() { } codigoReserva: string;
constructor(private navParams: NavParams) { }
ngOnInit() { ngOnInit() {
this.codigoReserva = this.navParams.get('codigo');
} }
} }

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { CodigoreservaService } from './codigoreserva.service';
describe('CodigoreservaService', () => {
let service: CodigoreservaService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CodigoreservaService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class CodigoreservaService {
codigo: string;
length: number;
constructor() {
}
generarAleatorio(){
this.length = 7;
var result = [];
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < this.length; i++ ) {
result.push(characters.charAt(Math.floor(Math.random() *
charactersLength)));
}
return result.join("");
}
}

View File

@ -27,7 +27,7 @@
</div> </div>
</ion-row> </ion-row>
<ion-row> <ion-row>
<ion-button (click)="openReserva()"> <ion-button (click)="generarCodigo(); openReserva()">
Reserva Reserva
</ion-button> </ion-button>
</ion-row> </ion-row>

View File

@ -1,9 +1,11 @@
import { stringify } from '@angular/compiler/src/util';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular'; import { ModalController } from '@ionic/angular';
import { DiscotecaI } from '../interfaces/discoteca-i'; import { DiscotecaI } from '../interfaces/discoteca-i';
import { Eventoi } from '../interfaces/eventoi'; import { Eventoi } from '../interfaces/eventoi';
import { Reservai } from '../interfaces/reservai'; import { Reservai } from '../interfaces/reservai';
import { ReservamodalPage } from '../reservamodal/reservamodal.page'; import { ReservamodalPage } from '../reservamodal/reservamodal.page';
import { CodigoreservaService } from '../services/codigoreserva.service';
import { FeedService } from '../services/feed.service'; import { FeedService } from '../services/feed.service';
@Component({ @Component({
@ -16,16 +18,27 @@ export class ViewEventoClientePage implements OnInit {
evento: Eventoi; evento: Eventoi;
discoteca: DiscotecaI; discoteca: DiscotecaI;
reserva: Reservai; reserva: Reservai;
constructor(private feedService: FeedService, private modalController: ModalController) { } codigoReserva: string;
constructor(private feedService: FeedService, private modalController: ModalController,
private codigoReservaService: CodigoreservaService) { }
ngOnInit() { ngOnInit() {
this.evento = this.feedService.getEventoByIndex(this.feedService.eventoIndex); this.evento = this.feedService.getEventoByIndex(this.feedService.eventoIndex);
this.discoteca = this.feedService.discotecaEvento; this.discoteca = this.feedService.discotecaEvento;
} }
generarCodigo(){
this.codigoReserva = stringify(this.codigoReservaService.generarAleatorio());
console.log(this.codigoReserva);
}
openReserva(){ openReserva(){
this.modalController.create({ this.modalController.create({
component: ReservamodalPage, component: ReservamodalPage,
componentProps : {
codigo: this.codigoReserva
}
}).then(modal => modal.present()); }).then(modal => modal.present());