From 9ecdb50db73731442d43259ef22c5d39adbafe56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Thu, 8 Nov 2018 13:47:26 +0100 Subject: [PATCH] Remove useless code --- .../content-create-page.component.html | 8 +++--- .../content-create-page.component.ts | 21 +++++++++++++++- .../content-creator.component.ts | 25 +++---------------- .../room-creator-page.component.ts | 4 ++- src/app/services/http/room.service.ts | 8 ------ 5 files changed, 30 insertions(+), 36 deletions(-) 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 3156bc0f4..b1456b8d9 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 291fea722..efe964a5d 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 e5ae626c5..715584dbf 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 9086a41ff..6738943e0 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 09d0d3174..3f8b676d6 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( -- GitLab