diff --git a/src/app/components/creator/content-create-page/content-create-page.component.html b/src/app/components/creator/content-create-page/content-create-page.component.html index 3156bc0f45ad0f731dace27f7fe689eabdc6388a..b1456b8d995fdfb7215cffd4a68fd5270b8fd10e 100644 --- a/src/app/components/creator/content-create-page/content-create-page.component.html +++ b/src/app/components/creator/content-create-page/content-create-page.component.html @@ -3,22 +3,22 @@ <mat-tab-group> <mat-tab label="Text"> <div class="tab-container"> - <app-content-creator [format]="'text'"></app-content-creator> + <app-content-creator [format]="'text'" [contentGroups]="contentGroups"></app-content-creator> </div> </mat-tab> <mat-tab label="Single / Multiple Choice"> <div class="tab-container"> - <app-content-creator [format]="'choice'"></app-content-creator> + <app-content-creator [format]="'choice'" [contentGroups]="contentGroups"></app-content-creator> </div> </mat-tab> <mat-tab label="Likert"> <div class="tab-container"> - <app-content-creator [format]="'likert'"></app-content-creator> + <app-content-creator [format]="'likert'" [contentGroups]="contentGroups"></app-content-creator> </div> </mat-tab> <mat-tab label="{{ 'content.yes' | translate }} / {{ 'content.no' | translate }}"> <div class="tab-container"> - <app-content-creator [format]="'yesno'"></app-content-creator> + <app-content-creator [format]="'yesno'" [contentGroups]="contentGroups"></app-content-creator> </div> </mat-tab> </mat-tab-group> diff --git a/src/app/components/creator/content-create-page/content-create-page.component.ts b/src/app/components/creator/content-create-page/content-create-page.component.ts index 291fea722c732bac2314e6e7c3688891bc61aa86..efe964a5d1bd5e71022e4e46e8c2d1c3a98b825e 100644 --- a/src/app/components/creator/content-create-page/content-create-page.component.ts +++ b/src/app/components/creator/content-create-page/content-create-page.component.ts @@ -1,6 +1,9 @@ import { Component, OnInit } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from '../../../services/util/language.service'; +import { RoomService } from '../../../services/http/room.service'; +import { ActivatedRoute } from '@angular/router'; +import { ContentGroup } from '../../../models/content-group'; @Component({ selector: 'app-content-create-page', @@ -9,12 +12,28 @@ import { LanguageService } from '../../../services/util/language.service'; }) export class ContentCreatePageComponent implements OnInit { + contentGroups: ContentGroup[]; + lastCollection: string; + constructor(private translateService: TranslateService, - protected langService: LanguageService) { + protected langService: LanguageService, + protected roomService: RoomService, + protected route: ActivatedRoute) { langService.langEmitter.subscribe(lang => translateService.use(lang)); } + + ngOnInit() { this.translateService.use(sessionStorage.getItem('currentLang')); + this.route.params.subscribe(params => { + this.getGroups(params['roomId']); + }); + this.lastCollection = sessionStorage.getItem('collection'); } + + getGroups(id: string): void { + this.roomService.getRoomByShortId(id).subscribe(room => { + this.contentGroups = room.contentGroups; + }); } diff --git a/src/app/components/creator/content-creator/content-creator.component.ts b/src/app/components/creator/content-creator/content-creator.component.ts index e5ae626c5b0fab005d5efd6d334406823b5496ba..715584dbf49e412664e26703ffb6d46563fc31ed 100644 --- a/src/app/components/creator/content-creator/content-creator.component.ts +++ b/src/app/components/creator/content-creator/content-creator.component.ts @@ -4,19 +4,15 @@ import { FormControl } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; import { ContentListComponent } from '../../shared/content-list/content-list.component'; import { Room } from '../../../models/room'; -import { RoomService } from '../../../services/http/room.service'; -import { ActivatedRoute } from '@angular/router'; -import { ContentGroup } from '../../../models/content-group'; -import { RoomPageComponent } from '../../shared/room-page/room-page.component'; -import { Location } from '@angular/common'; @Component({ selector: 'app-content-creator', templateUrl: './content-creator.component.html', styleUrls: ['./content-creator.component.scss'] }) -export class ContentCreatorComponent extends RoomPageComponent implements OnInit { +export class ContentCreatorComponent implements OnInit { @Input() format; + @Input() contentGroups; room: Room; content: ContentText = new ContentText( @@ -28,7 +24,7 @@ export class ContentCreatorComponent extends RoomPageComponent implements OnInit 1, [], ); - contentGroups: ContentGroup[]; + lastCollection: string; myControl = new FormControl(); @@ -36,25 +32,10 @@ export class ContentCreatorComponent extends RoomPageComponent implements OnInit constructor(public dialog: MatDialog, public dialogRef: MatDialogRef<ContentListComponent>, - protected roomService: RoomService, - protected route: ActivatedRoute, - protected location: Location, @Inject(MAT_DIALOG_DATA) public data: any) { - super(roomService, route, location); } ngOnInit() { - this.route.params.subscribe(params => { - this.getRoom(params['roomId']); - }); - this.lastCollection = sessionStorage.getItem('collection'); - } - - getRoom(id: string): void { - this.roomService.getRoomByShortId(id).subscribe(room => { - this.contentGroups = room.contentGroups; - }); - } resetInputs() { diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index 9086a41ff732682f79d0be46d79c6111b6f6bbf7..6738943e05270526a429d668cdcde9cae5c55d19 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -35,7 +35,9 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni this.translateService.use(sessionStorage.getItem('currentLang')); this.route.params.subscribe(params => { this.getRoom(params['roomId']); - console.log(this.room.name); + if (this.room) { + console.log('room exists'); + } }); } diff --git a/src/app/services/http/room.service.ts b/src/app/services/http/room.service.ts index 09d0d31747f0cf27791db7ab81a5163f45bbf7fd..3f8b676d6e795b48074ddc3e503a21b4f92e16d6 100644 --- a/src/app/services/http/room.service.ts +++ b/src/app/services/http/room.service.ts @@ -65,14 +65,6 @@ export class RoomService extends BaseHttpService { ); } - getContentGroups(id: string): Observable<ContentGroup[]> { - const connectionUrl = `${ this.apiUrl.base + this.apiUrl.rooms }/${ id }`; - return this.http.get<ContentGroup[]>(connectionUrl).pipe( - tap(() => ''), - catchError(this.handleError<ContentGroup[]>(`getContentGroup keyword=${ id }`)) - ); - } - getRoomByShortId(shortId: string): Observable<Room> { const connectionUrl = `${ this.apiUrl.base + this.apiUrl.rooms }/~${ shortId }`; return this.http.get<Room>(connectionUrl).pipe(