diff --git a/src/app/answer-option.ts b/src/app/answer-option.ts index b8a1fefbf0122e24133737acb971b8af425cc817..576982bce9c8b7cc5c443a01aeb53a03f8b3f424 100644 --- a/src/app/answer-option.ts +++ b/src/app/answer-option.ts @@ -1,8 +1,9 @@ export class AnswerOption { - constructor(label: string, points: string) { - this.label = label; - this.points = points; - } label: string; points: string; + + constructor(label: string, points: string) { + this.label = label; + this.points = points; + } } diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 1364c4b066fb22ad795087d85b0652a6f4a4ea2f..50cfded9ff08fa2256b5e71e8fc02eab3f8059f0 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/:id', + path: 'creator/room/:roomId/:contentId', component: ContentDetailComponent, canActivate: [AuthenticationGuard], data: { roles: [UserRole.CREATOR] } diff --git a/src/app/choice-content.ts b/src/app/choice-content.ts index 27a4580fe77ab5c57a411c4d75d885cb6f51cc93..a6b26d79d99ff4d25e6b13a4de704991bf420f73 100644 --- a/src/app/choice-content.ts +++ b/src/app/choice-content.ts @@ -1,20 +1,31 @@ import { AnswerOption } from './answer-option'; -import { Content, Format } from './content'; +import { Content } from './content'; +import { ContentType } from './content-type'; export class ChoiceContent extends Content { - constructor(roomId: string, subject: string, body: string, options: AnswerOption[], correctOptionIndexes: number[], multiple: boolean) { - super(); - this.revision = '1'; - this.roomId = roomId; - this.subject = subject; - this.body = body; - this.round = 1; - this.format = Format.CHOICE; - this.options = options; - this.correctOptionIndexes = correctOptionIndexes; - this.multiple = multiple; - } options: AnswerOption[]; correctOptionIndexes: number[]; multiple: boolean; -} + + constructor(contentId: string, + revision: string, + roomId: string, + subject: string, + body: string, + round: number, + options: AnswerOption[], + correctOptionIndexes: number[], + multiple: boolean) { + super(contentId, + revision, + roomId, + subject, + body, + round, + ContentType.CHOICE, + new Map()); + this.options = options; + this.correctOptionIndexes = correctOptionIndexes; + this.multiple = multiple; + } + } diff --git a/src/app/content-answers-list/content-answers-list.component.ts b/src/app/content-answers-list/content-answers-list.component.ts index ef2df1a523d50da21a770714a985b066b40072dc..e621957abe7729e7daa6f83b54e9526869db4636 100644 --- a/src/app/content-answers-list/content-answers-list.component.ts +++ b/src/app/content-answers-list/content-answers-list.component.ts @@ -20,18 +20,12 @@ export class ContentAnswersListComponent implements OnInit { ngOnInit() { this.route.params.subscribe(params => { - this.getContent(params['id']); + this.getAnswerTexts(params['contentId']); }); } - getContent(id: string): void { - this.contentService.getContent(id).subscribe(params => { - this.getAnswerTexts(params['id']); - }) - } - - getAnswerTexts(id: string): void { - this.contentAnswerService.getAnswerTexts(id) + getAnswerTexts(contentId: string): void { + this.contentAnswerService.getAnswerTexts(contentId) .subscribe(textAnswers => { this.textAnswers = textAnswers; }); diff --git a/src/app/content-creation/content-creation.component.ts b/src/app/content-creation/content-creation.component.ts index 86d7ac2246f687b4b7068b403c94e5f8737e16d5..ccef4b7837311782b85e9b9a9f90150945fdf12c 100644 --- a/src/app/content-creation/content-creation.component.ts +++ b/src/app/content-creation/content-creation.component.ts @@ -45,7 +45,7 @@ export class ContentCreationComponent implements OnInit { this.contentService.addContent({ subject: subject, body: body, roomId: this.roomId } as Content) .subscribe(content => { this.notification.show(`Content '${content.subject}' successfully created.`); - this.router.navigate([`/creator/room/${content.roomId}/${content.id}`]); + this.router.navigate([`/creator/room/${content.roomId}/${content.contentId}`]); this.dialogRef.close(); }); } diff --git a/src/app/content-detail/content-detail.component.html b/src/app/content-detail/content-detail.component.html index 404cab88379b788d3324fb00252102317dca68d7..4e68b015b3d96654881ca18de04b262e651ba43d 100644 --- a/src/app/content-detail/content-detail.component.html +++ b/src/app/content-detail/content-detail.component.html @@ -5,7 +5,7 @@ <mat-card-title> <h3 class="subheading-2">{{content.subject}}</h3> </mat-card-title> - <mat-card-subtitle>ID: {{ content.id }} + <mat-card-subtitle>ID: {{ content.contentId }} <br> Round: {{ content.round }}</mat-card-subtitle> </mat-card-header> <mat-divider></mat-divider> @@ -21,7 +21,7 @@ <mat-divider></mat-divider> <!-- answes list here --> <mat-card-actions> - <button mat-button color="primary" matTooltip="Create new content" routerLink="/creator/room/{{content.id}}/content-creation"> + <button mat-button color="primary" matTooltip="Create new content" routerLink="/creator/room/{{content.contentId}}/content-creation"> Create answer </button> <button mat-button color="warn" matTooltip="Delete selected answer"> diff --git a/src/app/content-detail/content-detail.component.ts b/src/app/content-detail/content-detail.component.ts index 6787bcc6d6e8794926fd2a8c29de65e214f418d2..288ec68f4f635bbca9e41e9aa3e077f84afab172 100644 --- a/src/app/content-detail/content-detail.component.ts +++ b/src/app/content-detail/content-detail.component.ts @@ -18,12 +18,12 @@ export class ContentDetailComponent implements OnInit { ngOnInit() { this.route.params.subscribe(params => { - this.getContent(params['id']); + this.getContent(params['contentId']); }); } - getContent(id: string): void { - this.contentService.getContent(id) - .subscribe(content => this.content = content); + getContent(contentId: string): void { + this.contentService.getContent(contentId) + .subscribe(content => this.content = content[0]); } } diff --git a/src/app/content-list/content-list.component.html b/src/app/content-list/content-list.component.html index 4bca2af658745f293e2c9df890fdd22b381b1d4f..ad9cab2ee24959e0d8cd3792b6ca193614cedbb9 100644 --- a/src/app/content-list/content-list.component.html +++ b/src/app/content-list/content-list.component.html @@ -1,7 +1,7 @@ <mat-list> <mat-list-item *ngFor="let content of contents"> - <button mat-button routerLink="{{content.id}}"> - Content {{content.id}}: {{content.subject}} + <button mat-button routerLink="{{content.contentId}}"> + Content {{content.contentId}}: {{content.subject}} </button> </mat-list-item> </mat-list> diff --git a/src/app/content-list/content-list.component.ts b/src/app/content-list/content-list.component.ts index 0b1443241334733b717711254b97dd93fe6bcb6f..2db858053d2f69965c8fbfefb89ca66150da4f7f 100644 --- a/src/app/content-list/content-list.component.ts +++ b/src/app/content-list/content-list.component.ts @@ -2,7 +2,6 @@ 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', @@ -12,29 +11,20 @@ import { RoomService } from '../room.service'; export class ContentListComponent implements OnInit { contents: Content[]; - constructor( - private contentService: ContentService, - private route: ActivatedRoute, - private roomService: RoomService, - ) { } + constructor(private contentService: ContentService, + private route: ActivatedRoute) { + } ngOnInit() { this.route.params.subscribe(params => { - this.getRoom(params['roomId']); + this.getContents(params['roomId']); }); } - getRoom(id: string): void { - this.roomService.getRoom(id).subscribe( - params => { - this.getContents(params['id']); - }); - } - getContents(roomId: string): void { this.contentService.getContents(roomId) - .subscribe(contents => { - this.contents = contents; - }); + .subscribe(contents => { + this.contents = contents; + }); } } diff --git a/src/app/content-type.ts b/src/app/content-type.ts new file mode 100644 index 0000000000000000000000000000000000000000..227ba9a4bf76f5d8582ca103f59674e81c590f84 --- /dev/null +++ b/src/app/content-type.ts @@ -0,0 +1,8 @@ +export enum ContentType { + CHOICE, + BINARY, + SCALE, + NUMBER, + TEXT, + GRID +} diff --git a/src/app/content.service.ts b/src/app/content.service.ts index 75e59adcbdb432d00bdc831cfb030021842c0b75..07e9f22624249ba02643555bd02d0302524cf4c3 100644 --- a/src/app/content.service.ts +++ b/src/app/content.service.ts @@ -29,10 +29,10 @@ export class ContentService extends ErrorHandlingService { ); } - getContent(id: string): Observable<Content> { - const url = `${this.contentUrl}/${id}`; + getContent(contentId: string): Observable<Content> { + const url = `${this.contentUrl}/?contentId=${contentId}`; return this.http.get<Content>(url).pipe( - catchError(this.handleError<Content>(`getContent id=${id}`)) + catchError(this.handleError<Content>(`getContent id=${contentId}`)) ); } } diff --git a/src/app/content.ts b/src/app/content.ts index f8069e8117c8840f9fe5a0ac8b7fc9363f5b3b9e..bcb3b4084cf020253cb527577c37bdee0380b55e 100644 --- a/src/app/content.ts +++ b/src/app/content.ts @@ -1,19 +1,30 @@ -export enum Format { - CHOICE, - BINARY, - SCALE, - NUMBER, - TEXT, - GRID -} +import { ContentType } from './content-type'; export class Content { - id: string; + contentId: string; revision: string; roomId: string; subject: string; body: string; round: number; - format: Format; + format: ContentType; formatAttributes: Map<string, string>; + + constructor(contentId: string, + revision: string, + roomId: string, + subject: string, + body: string, + round: number, + format: ContentType, + formatAttributes: Map<string, string>) { + this.contentId = contentId; + this.revision = revision; + this.roomId = roomId; + this.subject = subject; + this.body = body; + this.round = round; + this.format = format; + this.formatAttributes = formatAttributes; + } } diff --git a/src/app/in-memory-data.service.ts b/src/app/in-memory-data.service.ts index f490085a6c4b7c91f4d5f3da26553eb21b901678..30b63b24bcfadbc08770d00e0054e30f03ac6c8f 100644 --- a/src/app/in-memory-data.service.ts +++ b/src/app/in-memory-data.service.ts @@ -1,5 +1,5 @@ import { InMemoryDbService } from 'angular-in-memory-web-api'; -import { Format } from './content'; +import { ContentType } from './content-type'; export class InMemoryDataService implements InMemoryDbService { /** @@ -87,22 +87,22 @@ export class InMemoryDataService implements InMemoryDbService { const contents = [ { - id: '1', + contentId: '1', revision: '1', roomId: '1', - subject: 'Textaufgabe 1', - body: 'testcontent alpha beta', + subject: 'Text Content 1', + body: 'This is a body of a text content.', round: 1, - format: Format.TEXT + format: ContentType.TEXT }, { - id: '2', + contentId: '2', revision: '2', roomId: '3', - subject: 'Textaufgabe 2', - body: 'Ein Mann kauft 20 Melonen. Eine Melone wiegt jeweils 5kg. Berechnen Sie das Gesamtgewicht.', - round: 5, - format: Format.TEXT + subject: 'Text Content 2', + body: 'This is yet another body of a text content.', + round: 2, + format: ContentType.TEXT } ]; diff --git a/src/app/text-content.ts b/src/app/text-content.ts index 363d19ea678f122e817f7e380c84dadfd91d43f9..02b7081d50bf41bdcf3a96d8f65b52a714654b90 100644 --- a/src/app/text-content.ts +++ b/src/app/text-content.ts @@ -1,15 +1,21 @@ -import { Content, Format } from './content'; +import { Content } from './content'; +import { ContentType } from './content-type'; export class TextContent extends Content { - constructor(roomId: string, subject: string, body: string) { - super(); - this.revision = '1'; - this.roomId = roomId; - this.subject = subject; - this.body = body; - this.round = 1; - this.format = Format.TEXT; - this.formatAttributes.clear(); // API: formatAttributes = Map.empty(); + constructor(contentId: string, + revision: string, + roomId: string, + subject: string, + body: string, + round: number) { + super(contentId, + revision, + roomId, + subject, + body, + round, + ContentType.TEXT, + new Map()); } }