From ec4f97db5bead9c1cae7724078f4db7f8fcef13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Mon, 8 Oct 2018 15:25:24 +0200 Subject: [PATCH] Give contents of contentCroup to contentList --- src/app/app-routing.module.ts | 2 +- .../content-groups.component.html | 2 +- .../content-groups.component.ts | 22 +++++++++++++++++-- .../content-list/content-list.component.ts | 4 ++-- .../content-carousel-page.component.ts | 9 ++++---- src/app/services/http/content.service.ts | 2 +- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index e146fa219..dc9a91ab6 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -58,7 +58,7 @@ const routes: Routes = [ data: { roles: [UserRole.CREATOR] } }, { - path: 'creator/room/:roomId/content', + path: 'creator/room/:roomId/:contentGroup', component: ContentListComponent, canActivate: [AuthenticationGuard], data: { roles: [UserRole.CREATOR] } diff --git a/src/app/components/fragments/content-groups/content-groups.component.html b/src/app/components/fragments/content-groups/content-groups.component.html index 37abd9e9b..6fc494137 100644 --- a/src/app/components/fragments/content-groups/content-groups.component.html +++ b/src/app/components/fragments/content-groups/content-groups.component.html @@ -1,5 +1,5 @@ - <mat-card *ngFor="let contentGroup of displayedContentGroups"> + <mat-card *ngFor="let contentGroup of displayedContentGroups" (click)="getContents(contentGroup)"> <mat-card-header> <mat-card-title> <h4>{{contentGroup.name}}<mat-icon matBadge="{{contentGroup.contentIds.length}}" matBadgePosition="after"></mat-icon></h4> diff --git a/src/app/components/fragments/content-groups/content-groups.component.ts b/src/app/components/fragments/content-groups/content-groups.component.ts index 483aa103e..b54ef72c3 100644 --- a/src/app/components/fragments/content-groups/content-groups.component.ts +++ b/src/app/components/fragments/content-groups/content-groups.component.ts @@ -1,4 +1,8 @@ -import { Component, Input, OnInit} from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { ContentService } from '../../../services/http/content.service'; +import { Content } from '../../../models/content'; +import { ContentText } from '../../../models/content-text'; class ContentGroup { name: string; @@ -21,11 +25,17 @@ export class ContentGroupsComponent implements OnInit { @Input() public contentGroups: {[key: string]: [string]}; displayedContentGroups: ContentGroup[] = []; + roomShortId: string; + contents: ContentText[]; - constructor () { + constructor (private route: ActivatedRoute, + private router: Router, + private contentService: ContentService + ) { } ngOnInit() { + this.roomShortId = this.route.snapshot.paramMap.get('roomId'); Object.keys(this.contentGroups).forEach(key => { if (key === '') { const cg = new ContentGroup( @@ -42,4 +52,12 @@ export class ContentGroupsComponent implements OnInit { } }); } + + getContents(contentGroup: ContentGroup) { + this.contentService.getContentsByIds(contentGroup.contentIds).subscribe( contents => { + this.contents = contents; + }); + this.router.navigate([`creator/room/${this.roomShortId}/${contentGroup.name}`]); + console.log(contentGroup.contentIds); + } } diff --git a/src/app/components/fragments/content-list/content-list.component.ts b/src/app/components/fragments/content-list/content-list.component.ts index 38cff1335..05c7e4f6e 100644 --- a/src/app/components/fragments/content-list/content-list.component.ts +++ b/src/app/components/fragments/content-list/content-list.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { ContentService } from '../../../services/http/content.service'; import { Content } from '../../../models/content'; import { ActivatedRoute } from '@angular/router'; @@ -19,7 +19,7 @@ import { NotificationService } from '../../../services/util/notification.service }) export class ContentListComponent implements OnInit { - contents = []; + @Input('contents') contents: ContentText[]; contentBackup: Content; diff --git a/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts b/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts index 88ad6abf4..62409b074 100644 --- a/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts +++ b/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts @@ -5,6 +5,7 @@ import { ContentChoice } from '../../../models/content-choice'; import { ContentText } from '../../../models/content-text'; import { ContentService } from '../../../services/http/content.service'; import { ActivatedRoute } from '@angular/router'; +import { Content } from '../../../models/content'; @Component({ selector: 'app-content-carousel-page', @@ -14,8 +15,7 @@ import { ActivatedRoute } from '@angular/router'; export class ContentCarouselPageComponent implements OnInit { ContentType: typeof ContentType = ContentType; -// contents: Content[]; - contents = []; + contents: Content[]; constructor(private contentService: ContentService, private route: ActivatedRoute) { @@ -23,10 +23,9 @@ export class ContentCarouselPageComponent implements OnInit { ngOnInit() { this.route.params.subscribe(params => { - // ToDo: Check api call - /* this.contentService.getContent(params['roomId']).subscribe(result => { + this.contentService.getContents(params['roomId']).subscribe(result => { this.contents = result; - }); */ + }); }); } } diff --git a/src/app/services/http/content.service.ts b/src/app/services/http/content.service.ts index 9cfb93f7a..64d49e0d4 100644 --- a/src/app/services/http/content.service.ts +++ b/src/app/services/http/content.service.ts @@ -33,7 +33,7 @@ export class ContentService extends BaseHttpService { } getContentsByIds(ids: string[]): Observable<Content[]> { - const connectionUrl = this.apiUrl.base + this.apiUrl.content + ids.toString(); + const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/' + ids.toString(); return this.http.get<Content[]>(connectionUrl).pipe( tap(() => ''), catchError(this.handleError('getContentsByIds', [])) -- GitLab