Commit 2727ac7f authored by Raul Granados's avatar Raul Granados

connect firebase

parent 71cfafd6
This diff is collapsed.
......@@ -20,7 +20,9 @@
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"angularfire2": "^5.1.0",
"core-js": "^2.5.4",
"firebase": "^5.5.9",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
......
<form [formGroup]="emailForm" (ngSubmit)="onSubmit()">
<label for="email">Tu correo</label>
<input type="email" formControlName="email" />
<label for="phone">Celular</label>
<input type="phone" formControlName="phone" />
<label for="password">Clave de acceso</label>
<input type="password" formControlName="password" />
<div class="form-group">
<button [disabled]="loading" class="btn btn-primary">Get paper</button>
</div>
</form>
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FirestoreService } from './services/firestore/firestore.service';
@Component({
selector: 'app-root',
......@@ -9,43 +10,55 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
export class AppComponent implements OnInit {
emailForm: FormGroup;
submitted = false;
people = [
{email: 'raul@tingsystems.com', password: 'fenix', name: 'Raul Granados'},
{email: 'pedro@tingsystems.com', password: 'ana', name: 'Pedro Lopez'},
{email: 'sandra@tingsystems.com', password: 'pollitux', name: 'Sandra Valencia'},
{email: 'ignacio@tingsystems.com', password: 'frida', name: 'Ignacio Marin'},
{email: 'dante@tingsystems.com', password: 'birrieria', name: 'Dante Arciga'},
{email: 'jaime@tingsystems.com', password: 'bibi', name: 'Jaime Horta'},
];
people = [];
papers = []
extraPapers = []
papers = [
{name: 'Invitas un six (no tecate)', kind: 1},
{name: 'Cantas el villancico El burrito sabanero', kind: 1},
{name: 'Invitas un six (no tecate)', kind: 1},
{name: 'Cantas el villancico El tamborilero', kind: 1},
{name: 'Invitas un six (no tecate)', kind: 1},
{name: 'Cantas el villancico Los peces en el río', kind: 1},
{name: 'Pedro Lopez', kind: 0},
{name: 'Sandra Valencia', kind: 0},
{name: 'Jaime Horta', kind: 0},
{name: 'Ignacio Marin', kind: 0},
{name: 'Dante Arciga', kind: 0},
{name: 'Raul Granados', kind: 0},
]
extraPapers = [
{name: 'Invitas un six (no tecate)', kind: 1},
{name: 'Lleva botanas', kind: 1},
{name: 'Lleva chescos', kind: 1}
]
constructor(private formBuilder: FormBuilder) {
constructor(private formBuilder: FormBuilder, private firestoreService: FirestoreService) {
}
ngOnInit() {
this.firestoreService.getPapers().subscribe((papersSnapshot) => {
this.papers = [];
papersSnapshot.forEach((paperData: any) => {
const data = paperData.payload.doc.data();
this.papers.push({
id: paperData.payload.doc.id,
name: data.name,
kind: data.kind
});
})
});
this.firestoreService.getPeoples().subscribe((peopleSnapshot) => {
this.people = [];
peopleSnapshot.forEach((peopleData: any) => {
const data = peopleData.payload.doc.data();
this.people.push({
id: peopleData.payload.doc.id,
phone: data.phone,
password: data.password,
name: data.name
});
})
});
this.firestoreService.getExtraPapers().subscribe((extraPapersSnapshot) => {
this.extraPapers = [];
extraPapersSnapshot.forEach((paperData: any) => {
const data = paperData.payload.doc.data();
this.extraPapers.push({
id: paperData.payload.doc.id,
name: data.name,
kind: data.kind
});
})
});
this.emailForm = this.formBuilder.group({
email: ['', Validators.required],
phone: ['', Validators.required],
password: ['', Validators.required],
});
}
......@@ -59,7 +72,7 @@ export class AppComponent implements OnInit {
if (this.emailForm.invalid) {
return;
}
const people = this.people.find( people => people.email === this.emailForm.value.email)
const people = this.people.find( people => people.phone === this.emailForm.value.phone)
if (people === undefined) {
alert('Alejate grinch!');
return;
......@@ -82,4 +95,5 @@ export class AppComponent implements OnInit {
return paper.name;
}
}
}
......@@ -2,6 +2,10 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { AngularFireModule } from 'angularfire2';
import { AngularFirestore } from 'angularfire2/firestore';
import { environment } from '../environments/environment';
import { AppComponent } from './app.component';
@NgModule({
......@@ -10,9 +14,10 @@ import { AppComponent } from './app.component';
],
imports: [
BrowserModule,
ReactiveFormsModule
ReactiveFormsModule,
AngularFireModule.initializeApp(environment.firebase)
],
providers: [],
providers: [AngularFirestore],
bootstrap: [AppComponent]
})
export class AppModule { }
import { TestBed, inject } from '@angular/core/testing';
import { FirestoreService } from './firestore.service';
describe('FirestoreService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [FirestoreService]
});
});
it('should be created', inject([FirestoreService], (service: FirestoreService) => {
expect(service).toBeTruthy();
}));
});
import { Injectable } from '@angular/core';
import { AngularFirestore, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class FirestoreService {
constructor(private firestore: AngularFirestore) { }
public getPerson(documentId: string) {
return this.firestore.collection('people').doc(documentId).snapshotChanges();
}
public getPeoples() {
return this.firestore.collection('people').snapshotChanges();
}
public getPapers() {
return this.firestore.collection('papers').snapshotChanges();
}
public getExtraPapers() {
return this.firestore.collection('extraPapers').snapshotChanges();
}
}
......@@ -3,9 +3,19 @@
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
production: false,
firebase: {
apiKey: "AIzaSyCXpcSp9izscGo682bm5-sd7wKYYM_vaKQ",
authDomain: "ha-app-8ca87.firebaseapp.com",
databaseURL: "https://ha-app-8ca87.firebaseio.com",
projectId: "ha-app-8ca87",
storageBucket: "ha-app-8ca87.appspot.com",
messagingSenderId: "241395814973"
}
};
/*
* In development mode, to ignore zone related error stack frames such as
* `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment