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-content>
{{codigoReserva}}
</ion-content>

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { NavParams } from '@ionic/angular';
@Component({
selector: 'app-reservamodal',
@ -7,9 +8,11 @@ import { Component, OnInit } from '@angular/core';
})
export class ReservamodalPage implements OnInit {
constructor() { }
codigoReserva: string;
constructor(private navParams: NavParams) { }
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>
</ion-row>
<ion-row>
<ion-button (click)="openReserva()">
<ion-button (click)="generarCodigo(); openReserva()">
Reserva
</ion-button>
</ion-row>

View File

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