diff --git a/src/app/scheduling/display-session/display-session.component.html b/src/app/scheduling/display-session/display-session.component.html index 929f197..5fd2eae 100644 --- a/src/app/scheduling/display-session/display-session.component.html +++ b/src/app/scheduling/display-session/display-session.component.html @@ -1,3 +1,13 @@ -

- display-session works! -

+
+
+ + +
+
+
+
+

{{ session.title }}

+

{{ session.desc }}

+ +
+
diff --git a/src/app/scheduling/display-session/display-session.component.scss b/src/app/scheduling/display-session/display-session.component.scss index e69de29..b57ade6 100644 --- a/src/app/scheduling/display-session/display-session.component.scss +++ b/src/app/scheduling/display-session/display-session.component.scss @@ -0,0 +1,5 @@ +.card { + img { + height: 300px + } +} \ No newline at end of file diff --git a/src/app/scheduling/display-session/display-session.component.ts b/src/app/scheduling/display-session/display-session.component.ts index 7c4878c..319737d 100644 --- a/src/app/scheduling/display-session/display-session.component.ts +++ b/src/app/scheduling/display-session/display-session.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit, Input } from '@angular/core'; +import { Router } from '@angular/router'; import { Session } from '../../shared/model/session' @Component({ @@ -11,9 +12,12 @@ export class DisplaySessionComponent implements OnInit { @Input() session: Session - constructor() { } + constructor(private router: Router) { } ngOnInit() { } + joinSession() { + this.router.navigate(['session', this.session.$key]); + } } diff --git a/src/app/scheduling/scheduling.component.html b/src/app/scheduling/scheduling.component.html index 7aed741..de2b1ba 100644 --- a/src/app/scheduling/scheduling.component.html +++ b/src/app/scheduling/scheduling.component.html @@ -1,22 +1,32 @@

Sessions I'm tutoring

-
-
{{session | json}}
+
+
+ +

Sessions I'm in

-
-
{{session | json}}
+
+
+ +

Public Sessions

-
-
{{session | json}}
+
+
+ +

Session By tag

- {{ sessionsByTags | json }} +
+
+ +
+


diff --git a/src/app/scheduling/scheduling.component.scss b/src/app/scheduling/scheduling.component.scss index e69de29..757a109 100644 --- a/src/app/scheduling/scheduling.component.scss +++ b/src/app/scheduling/scheduling.component.scss @@ -0,0 +1,9 @@ +.session-display { + display: flex; + justify-content: flex-start; + flex-wrap: wrap; + padding: 15px; + div { + margin: 15px; + } +} \ No newline at end of file diff --git a/src/app/shared/model/session.service.ts b/src/app/shared/model/session.service.ts index 755a0d3..fe4227b 100644 --- a/src/app/shared/model/session.service.ts +++ b/src/app/shared/model/session.service.ts @@ -1,6 +1,6 @@ import { Injectable, Inject } from '@angular/core'; -import { Observable, Subject, Observer } from 'rxjs/Rx'; -import { AngularFireDatabase, FirebaseRef} from 'angularfire2'; +import { Observable, Subject } from 'rxjs/Rx'; +import { AngularFireDatabase, FirebaseRef } from 'angularfire2'; import { Session } from './session'; import { User } from './user'; import { AuthService } from '../security/auth.service'; @@ -38,12 +38,34 @@ export class SessionService { return subject.asObservable(); } - findSession(id: string): Observable { + combineWithUser(sessionQuery: Observable): Observable { let sessionWithUser; - return this.db.object('/sessions/' + id) - .flatMap(val => val.$exists() ? Observable.of(val) : Observable.throw(`Session ${val.$key} does not exist`)) - .switchMap((val, index) => {sessionWithUser = val; return this.db.object('users/' + val.tutor)}) - .map(val => {sessionWithUser.tutor = val; return sessionWithUser}); + return sessionQuery.switchMap(val => { + sessionWithUser = val; + return this.db.object('users/' + val.tutor) + }).map(val => { + sessionWithUser.tutor = val; + return sessionWithUser; + }); + } + + combineArrWithUser(sessionQuery: Observable): Observable { + let sessionWithUser; + return sessionQuery.switchMap((val: any[]) => { + sessionWithUser = val; + return Observable.combineLatest( + val.map((session) => this.db.object('users/' + session.tutor)) + ); + }).map((val: any[]) => { + sessionWithUser.map((session, index) => session.tutor = val[index]); + return sessionWithUser; + }); + } + + findSession(id: string, query?: {}): Observable { + return this.combineWithUser( + this.db.object('/sessions/' + id) + .flatMap(val => val.$exists() ? Observable.of(val) : Observable.throw(`Session ${val.$key} does not exist`))); } findMySessions(): {tutorSessions: Observable, tuteeSessions: Observable} { @@ -61,12 +83,14 @@ export class SessionService { } findPublicSessions(): Observable { - return this.db.list('sessions', { - query: { - orderByChild: 'listed', - equalTo: true - } - }); + return this.combineArrWithUser( + this.db.list('sessions', { + query: { + orderByChild: 'listed', + equalTo: true + } + }) + ); } findSessionsByTags(tags: string[]): Observable {