From 048b16f432161cb4c9bba2da54c58d3cede101d6 Mon Sep 17 00:00:00 2001 From: Heinrich Marks <heinrich.marks@mni.thm.de> Date: Tue, 13 Mar 2018 15:42:00 +0100 Subject: [PATCH] Adjust logic to show respective content list items only now --- .../content-list/content-list.component.ts | 23 +++++++++++++++---- src/app/content.service.ts | 5 ++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/content-list/content-list.component.ts b/src/app/content-list/content-list.component.ts index 4fddce67c..0b1443241 100644 --- a/src/app/content-list/content-list.component.ts +++ b/src/app/content-list/content-list.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { ContentService } from '../content.service'; import { Content } from '../content'; +import { ActivatedRoute } from '@angular/router'; +import { RoomService } from '../room.service'; @Component({ selector: 'app-content-list', @@ -10,14 +12,27 @@ import { Content } from '../content'; export class ContentListComponent implements OnInit { contents: Content[]; - constructor(private contentService: ContentService) { } + constructor( + private contentService: ContentService, + private route: ActivatedRoute, + private roomService: RoomService, + ) { } ngOnInit() { - this.getContents(); + this.route.params.subscribe(params => { + this.getRoom(params['roomId']); + }); + } + + getRoom(id: string): void { + this.roomService.getRoom(id).subscribe( + params => { + this.getContents(params['id']); + }); } - getContents(): void { - this.contentService.getContents() + getContents(roomId: string): void { + this.contentService.getContents(roomId) .subscribe(contents => { this.contents = contents; }); diff --git a/src/app/content.service.ts b/src/app/content.service.ts index 4907191b2..75e59adcb 100644 --- a/src/app/content.service.ts +++ b/src/app/content.service.ts @@ -16,8 +16,9 @@ export class ContentService extends ErrorHandlingService { super(); } - getContents(): Observable<Content[]> { - return this.http.get<Content[]>(this.contentUrl).pipe( + getContents(roomId: string): Observable<Content[]> { + const url = `${this.contentUrl}/?roomId=${roomId}`; + return this.http.get<Content[]>(url).pipe( catchError(this.handleError('getContents', [])) ); } -- GitLab