Skip to content
Snippets Groups Projects
Commit 7f6f4ead authored by Lukas Maximilian Kimpel's avatar Lukas Maximilian Kimpel
Browse files

Merge branch '109-content-types-classes' into 'master'

Resolve "content types (classes)"

Closes #109

See merge request swtp-block-ws17/arsnova-angular-frontend!86
parents 85d4ac24 a69f1be7
No related merge requests found
Showing
with 108 additions and 87 deletions
export class AnswerOption { export class AnswerOption {
constructor(label: string, points: string) {
this.label = label;
this.points = points;
}
label: string; label: string;
points: string; points: string;
constructor(label: string, points: string) {
this.label = label;
this.points = points;
}
} }
...@@ -58,7 +58,7 @@ const routes: Routes = [ ...@@ -58,7 +58,7 @@ const routes: Routes = [
data: { roles: [UserRole.CREATOR] } data: { roles: [UserRole.CREATOR] }
}, },
{ {
path: 'creator/room/:roomId/:id', path: 'creator/room/:roomId/:contentId',
component: ContentDetailComponent, component: ContentDetailComponent,
canActivate: [AuthenticationGuard], canActivate: [AuthenticationGuard],
data: { roles: [UserRole.CREATOR] } data: { roles: [UserRole.CREATOR] }
......
import { AnswerOption } from './answer-option'; import { AnswerOption } from './answer-option';
import { Content, Format } from './content'; import { Content } from './content';
import { ContentType } from './content-type';
export class ChoiceContent extends Content { 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[]; options: AnswerOption[];
correctOptionIndexes: number[]; correctOptionIndexes: number[];
multiple: boolean; 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;
}
}
...@@ -20,18 +20,12 @@ export class ContentAnswersListComponent implements OnInit { ...@@ -20,18 +20,12 @@ export class ContentAnswersListComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.getContent(params['id']); this.getAnswerTexts(params['contentId']);
}); });
} }
getContent(id: string): void { getAnswerTexts(contentId: string): void {
this.contentService.getContent(id).subscribe(params => { this.contentAnswerService.getAnswerTexts(contentId)
this.getAnswerTexts(params['id']);
})
}
getAnswerTexts(id: string): void {
this.contentAnswerService.getAnswerTexts(id)
.subscribe(textAnswers => { .subscribe(textAnswers => {
this.textAnswers = textAnswers; this.textAnswers = textAnswers;
}); });
......
...@@ -45,7 +45,7 @@ export class ContentCreationComponent implements OnInit { ...@@ -45,7 +45,7 @@ export class ContentCreationComponent implements OnInit {
this.contentService.addContent({ subject: subject, body: body, roomId: this.roomId } as Content) this.contentService.addContent({ subject: subject, body: body, roomId: this.roomId } as Content)
.subscribe(content => { .subscribe(content => {
this.notification.show(`Content '${content.subject}' successfully created.`); 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(); this.dialogRef.close();
}); });
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<mat-card-title> <mat-card-title>
<h3 class="subheading-2">{{content.subject}}</h3> <h3 class="subheading-2">{{content.subject}}</h3>
</mat-card-title> </mat-card-title>
<mat-card-subtitle>ID: {{ content.id }} <mat-card-subtitle>ID: {{ content.contentId }}
<br> Round: {{ content.round }}</mat-card-subtitle> <br> Round: {{ content.round }}</mat-card-subtitle>
</mat-card-header> </mat-card-header>
<mat-divider></mat-divider> <mat-divider></mat-divider>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<mat-divider></mat-divider> <mat-divider></mat-divider>
<!-- answes list here --> <!-- answes list here -->
<mat-card-actions> <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 Create answer
</button> </button>
<button mat-button color="warn" matTooltip="Delete selected answer"> <button mat-button color="warn" matTooltip="Delete selected answer">
......
...@@ -18,12 +18,12 @@ export class ContentDetailComponent implements OnInit { ...@@ -18,12 +18,12 @@ export class ContentDetailComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.getContent(params['id']); this.getContent(params['contentId']);
}); });
} }
getContent(id: string): void { getContent(contentId: string): void {
this.contentService.getContent(id) this.contentService.getContent(contentId)
.subscribe(content => this.content = content); .subscribe(content => this.content = content[0]);
} }
} }
<mat-list> <mat-list>
<mat-list-item *ngFor="let content of contents"> <mat-list-item *ngFor="let content of contents">
<button mat-button routerLink="{{content.id}}"> <button mat-button routerLink="{{content.contentId}}">
Content {{content.id}}: {{content.subject}} Content {{content.contentId}}: {{content.subject}}
</button> </button>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
...@@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core'; ...@@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
import { ContentService } from '../content.service'; import { ContentService } from '../content.service';
import { Content } from '../content'; import { Content } from '../content';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { RoomService } from '../room.service';
@Component({ @Component({
selector: 'app-content-list', selector: 'app-content-list',
...@@ -12,29 +11,20 @@ import { RoomService } from '../room.service'; ...@@ -12,29 +11,20 @@ import { RoomService } from '../room.service';
export class ContentListComponent implements OnInit { export class ContentListComponent implements OnInit {
contents: Content[]; contents: Content[];
constructor( constructor(private contentService: ContentService,
private contentService: ContentService, private route: ActivatedRoute) {
private route: ActivatedRoute, }
private roomService: RoomService,
) { }
ngOnInit() { ngOnInit() {
this.route.params.subscribe(params => { 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 { getContents(roomId: string): void {
this.contentService.getContents(roomId) this.contentService.getContents(roomId)
.subscribe(contents => { .subscribe(contents => {
this.contents = contents; this.contents = contents;
}); });
} }
} }
export enum ContentType {
CHOICE,
BINARY,
SCALE,
NUMBER,
TEXT,
GRID
}
...@@ -29,10 +29,10 @@ export class ContentService extends ErrorHandlingService { ...@@ -29,10 +29,10 @@ export class ContentService extends ErrorHandlingService {
); );
} }
getContent(id: string): Observable<Content> { getContent(contentId: string): Observable<Content> {
const url = `${this.contentUrl}/${id}`; const url = `${this.contentUrl}/?contentId=${contentId}`;
return this.http.get<Content>(url).pipe( return this.http.get<Content>(url).pipe(
catchError(this.handleError<Content>(`getContent id=${id}`)) catchError(this.handleError<Content>(`getContent id=${contentId}`))
); );
} }
} }
export enum Format { import { ContentType } from './content-type';
CHOICE,
BINARY,
SCALE,
NUMBER,
TEXT,
GRID
}
export class Content { export class Content {
id: string; contentId: string;
revision: string; revision: string;
roomId: string; roomId: string;
subject: string; subject: string;
body: string; body: string;
round: number; round: number;
format: Format; format: ContentType;
formatAttributes: Map<string, string>; 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;
}
} }
import { InMemoryDbService } from 'angular-in-memory-web-api'; import { InMemoryDbService } from 'angular-in-memory-web-api';
import { Format } from './content'; import { ContentType } from './content-type';
export class InMemoryDataService implements InMemoryDbService { export class InMemoryDataService implements InMemoryDbService {
/** /**
...@@ -87,22 +87,22 @@ export class InMemoryDataService implements InMemoryDbService { ...@@ -87,22 +87,22 @@ export class InMemoryDataService implements InMemoryDbService {
const contents = [ const contents = [
{ {
id: '1', contentId: '1',
revision: '1', revision: '1',
roomId: '1', roomId: '1',
subject: 'Textaufgabe 1', subject: 'Text Content 1',
body: 'testcontent alpha beta', body: 'This is a body of a text content.',
round: 1, round: 1,
format: Format.TEXT format: ContentType.TEXT
}, },
{ {
id: '2', contentId: '2',
revision: '2', revision: '2',
roomId: '3', roomId: '3',
subject: 'Textaufgabe 2', subject: 'Text Content 2',
body: 'Ein Mann kauft 20 Melonen. Eine Melone wiegt jeweils 5kg. Berechnen Sie das Gesamtgewicht.', body: 'This is yet another body of a text content.',
round: 5, round: 2,
format: Format.TEXT format: ContentType.TEXT
} }
]; ];
......
import { Content, Format } from './content'; import { Content } from './content';
import { ContentType } from './content-type';
export class TextContent extends Content { export class TextContent extends Content {
constructor(roomId: string, subject: string, body: string) { constructor(contentId: string,
super(); revision: string,
this.revision = '1'; roomId: string,
this.roomId = roomId; subject: string,
this.subject = subject; body: string,
this.body = body; round: number) {
this.round = 1; super(contentId,
this.format = Format.TEXT; revision,
this.formatAttributes.clear(); // API: formatAttributes = Map.empty(); roomId,
subject,
body,
round,
ContentType.TEXT,
new Map());
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment