From 5d43399085fd6204792c4d3751587d34fb530b36 Mon Sep 17 00:00:00 2001 From: Philippe Antunes Date: Tue, 4 Jun 2019 16:05:36 +0900 Subject: [PATCH] Activities + Schedule Services --- src/app/Services/activities.service.spec.ts | 12 ++++++ src/app/Services/activities.service.ts | 17 ++++++++ src/app/Services/schedule.service.spec.ts | 12 ++++++ src/app/Services/schedule.service.ts | 18 ++++++++ src/app/activities/activities.component.css | 0 src/app/activities/activities.component.html | 14 +++++++ .../activities/activities.component.spec.ts | 25 +++++++++++ src/app/activities/activities.component.ts | 41 +++++++++++++++++++ src/app/app-routing.module.ts | 4 ++ src/app/app.module.ts | 13 +++++- 10 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/app/Services/activities.service.spec.ts create mode 100644 src/app/Services/activities.service.ts create mode 100644 src/app/Services/schedule.service.spec.ts create mode 100644 src/app/Services/schedule.service.ts create mode 100644 src/app/activities/activities.component.css create mode 100644 src/app/activities/activities.component.html create mode 100644 src/app/activities/activities.component.spec.ts create mode 100644 src/app/activities/activities.component.ts diff --git a/src/app/Services/activities.service.spec.ts b/src/app/Services/activities.service.spec.ts new file mode 100644 index 0000000..790e972 --- /dev/null +++ b/src/app/Services/activities.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { ActivitiesService } from './activities.service'; + +describe('ActivitiesService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: ActivitiesService = TestBed.get(ActivitiesService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/Services/activities.service.ts b/src/app/Services/activities.service.ts new file mode 100644 index 0000000..381b88e --- /dev/null +++ b/src/app/Services/activities.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; +import {AngularFirestore} from '@angular/fire/firestore'; +import {AngularFireDatabase} from '@angular/fire/database'; + +@Injectable({ + providedIn: 'root' +}) +export class ActivitiesService { + + constructor(private afs: AngularFirestore, + private db: AngularFireDatabase) { + } + + getActivities() { + return this.afs.collection('Activities').snapshotChanges(); + } +} diff --git a/src/app/Services/schedule.service.spec.ts b/src/app/Services/schedule.service.spec.ts new file mode 100644 index 0000000..2d6747d --- /dev/null +++ b/src/app/Services/schedule.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { ScheduleService } from './schedule.service'; + +describe('ScheduleService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: ScheduleService = TestBed.get(ScheduleService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/Services/schedule.service.ts b/src/app/Services/schedule.service.ts new file mode 100644 index 0000000..9b5402c --- /dev/null +++ b/src/app/Services/schedule.service.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@angular/core'; +import {AngularFirestore} from '@angular/fire/firestore'; + +@Injectable({ + providedIn: 'root' +}) +export class ScheduleService { + + constructor(private afs: AngularFirestore) { } + + getSchedule() { + return this.afs.collection('Schedule').snapshotChanges(); + } + + createSchedule(schedule) { + return this.afs.collection('Schedule').add(schedule); + } +} diff --git a/src/app/activities/activities.component.css b/src/app/activities/activities.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/activities/activities.component.html b/src/app/activities/activities.component.html new file mode 100644 index 0000000..da8c17c --- /dev/null +++ b/src/app/activities/activities.component.html @@ -0,0 +1,14 @@ + + +

List of Activities

+
+

{{activity.data.name}}

+ +
diff --git a/src/app/activities/activities.component.spec.ts b/src/app/activities/activities.component.spec.ts new file mode 100644 index 0000000..328d93a --- /dev/null +++ b/src/app/activities/activities.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ActivitiesComponent } from './activities.component'; + +describe('ActivitiesComponent', () => { + let component: ActivitiesComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ActivitiesComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ActivitiesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/activities/activities.component.ts b/src/app/activities/activities.component.ts new file mode 100644 index 0000000..949774f --- /dev/null +++ b/src/app/activities/activities.component.ts @@ -0,0 +1,41 @@ +import { Component, OnInit } from '@angular/core'; +import {ActivitiesService} from '@app/Services/activities.service'; +import {ScheduleService} from '@app/Services/schedule.service'; +import {ScheduleComponent} from '@app/schedule/schedule.component'; +import {MatDialog} from '@angular/material'; +import {NewScheduleComponent} from '@app/new-schedule/new-schedule.component'; + +@Component({ + selector: 'app-activities', + templateUrl: './activities.component.html', + styleUrls: ['./activities.component.css'] +}) +export class ActivitiesComponent implements OnInit { + + activities: any[]; + schedule = { + activitiesId: '', + }; + + animal: string; + name: string; + + constructor(private activitiesService: ActivitiesService, + private scheduleService: ScheduleService, + public dialog: MatDialog) { + } + + ngOnInit() { + this.activitiesService.getActivities().subscribe(data => { + this.activities = data.map(e => { + return { + id: e.payload.doc.id, + data: e.payload.doc.data() + } as any; + }); + }); + } + + addActivitiesIntoSchedule(id) { + } +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 0c989e6..b708085 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -2,11 +2,15 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { HomeComponent } from './home/home.component'; import { RegisterComponent } from './register/register.component'; +import {ActivitiesComponent} from '@app/activities/activities.component'; +import {ScheduleComponent} from '@app/schedule/schedule.component'; const routes: Routes = [ // No logged pages { path: '', component: HomeComponent, }, { path: 'register', component: RegisterComponent }, + { path: 'activities', component: ActivitiesComponent }, + { path: 'schedule', component: ScheduleComponent }, // { // path: 'login', // component: LoginComponent, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index cdcfcec..668a91c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,6 +18,11 @@ import { GlobalErrorHandler } from '@app/core/global-error-handler/global-error- import { environment } from '@env/environment'; import { CardDashboardComponent } from './card-dashboard/card-dashboard.component'; +import { ActivitiesComponent } from './activities/activities.component'; +import {AngularFirestore} from '@angular/fire/firestore'; +import { ScheduleComponent } from './schedule/schedule.component'; +import {MatDialogModule} from '@angular/material'; +import { NewScheduleComponent } from './new-schedule/new-schedule.component'; @NgModule( { declarations: [ @@ -26,6 +31,9 @@ import { CardDashboardComponent } from './card-dashboard/card-dashboard.componen HeaderComponent, RegisterComponent, CardDashboardComponent, + ActivitiesComponent, + ScheduleComponent, + NewScheduleComponent, ], imports: [ BrowserModule, @@ -35,8 +43,10 @@ import { CardDashboardComponent } from './card-dashboard/card-dashboard.componen AngularFireAuthModule, AngularFireDatabaseModule, AppMaterialModule, + MatDialogModule, ], providers: [ + AngularFirestore, LogService, SEOService, { @@ -44,7 +54,8 @@ import { CardDashboardComponent } from './card-dashboard/card-dashboard.componen useClass: GlobalErrorHandler, }, ], - bootstrap: [ AppComponent ] + bootstrap: [ AppComponent ], + entryComponents: [NewScheduleComponent], } ) export class AppModule { }