Activities + Schedule Services

This commit is contained in:
Philippe Antunes 2019-06-04 16:05:36 +09:00
parent 22dbc687a5
commit 5d43399085
10 changed files with 155 additions and 1 deletions

View File

@ -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();
});
});

View File

@ -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();
}
}

View File

@ -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();
});
});

View File

@ -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);
}
}

View File

@ -0,0 +1,14 @@
<app-header></app-header>
<h1> List of Activities</h1>
<div *ngFor="let activity of activities">
<h3>{{activity.data.name}}</h3>
<ul>
<li>Country: {{activity.data.country}}</li>
<li>City: {{activity.data.city}}</li>
<li>Description: {{activity.data.description}}</li>
<li>Duration: {{activity.data.duration}} minutes</li>
<li>Id: {{activity.id}}</li>
<button (click)="addActivitiesIntoSchedule(activity.id)">Add</button>
</ul>
</div>

View File

@ -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<ActivitiesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ActivitiesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivitiesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -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) {
}
}

View File

@ -2,11 +2,15 @@ import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './home/home.component'; import { HomeComponent } from './home/home.component';
import { RegisterComponent } from './register/register.component'; import { RegisterComponent } from './register/register.component';
import {ActivitiesComponent} from '@app/activities/activities.component';
import {ScheduleComponent} from '@app/schedule/schedule.component';
const routes: Routes = [ const routes: Routes = [
// No logged pages // No logged pages
{ path: '', component: HomeComponent, }, { path: '', component: HomeComponent, },
{ path: 'register', component: RegisterComponent }, { path: 'register', component: RegisterComponent },
{ path: 'activities', component: ActivitiesComponent },
{ path: 'schedule', component: ScheduleComponent },
// { // {
// path: 'login', // path: 'login',
// component: LoginComponent, // component: LoginComponent,

View File

@ -18,6 +18,11 @@ import { GlobalErrorHandler } from '@app/core/global-error-handler/global-error-
import { environment } from '@env/environment'; import { environment } from '@env/environment';
import { CardDashboardComponent } from './card-dashboard/card-dashboard.component'; 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( { @NgModule( {
declarations: [ declarations: [
@ -26,6 +31,9 @@ import { CardDashboardComponent } from './card-dashboard/card-dashboard.componen
HeaderComponent, HeaderComponent,
RegisterComponent, RegisterComponent,
CardDashboardComponent, CardDashboardComponent,
ActivitiesComponent,
ScheduleComponent,
NewScheduleComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -35,8 +43,10 @@ import { CardDashboardComponent } from './card-dashboard/card-dashboard.componen
AngularFireAuthModule, AngularFireAuthModule,
AngularFireDatabaseModule, AngularFireDatabaseModule,
AppMaterialModule, AppMaterialModule,
MatDialogModule,
], ],
providers: [ providers: [
AngularFirestore,
LogService, LogService,
SEOService, SEOService,
{ {
@ -44,7 +54,8 @@ import { CardDashboardComponent } from './card-dashboard/card-dashboard.componen
useClass: GlobalErrorHandler, useClass: GlobalErrorHandler,
}, },
], ],
bootstrap: [ AppComponent ] bootstrap: [ AppComponent ],
entryComponents: [NewScheduleComponent],
} ) } )
export class AppModule { export class AppModule {
} }