Skip to content
Snippets Groups Projects
Commit d78b9218 authored by Tom Käsler's avatar Tom Käsler
Browse files

fix add content

remove points for answer options from the ui and use defaults
parent 07647c02
No related merge requests found
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<markdown [data]="content.body"></markdown> <markdown [data]="content.body"></markdown>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<mat-radio-group [(ngModel)]="singleChoice" fxLayout="row" fxLayoutAlign="center" fxLayoutGap="20px"> <mat-radio-group [(ngModel)]="singleChoice" [ngModelOptions]="{standalone: true}" fxLayout="row" fxLayoutAlign="center" fxLayoutGap="20px">
<mat-radio-button [value]=true [checked]=true> <mat-radio-button [value]=true [checked]=true>
Single Choice Single Choice
</mat-radio-button> </mat-radio-button>
...@@ -32,16 +32,11 @@ ...@@ -32,16 +32,11 @@
</mat-cell> </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="points">
<mat-header-cell *matHeaderCellDef>Points</mat-header-cell>
<mat-cell *matCellDef="let answer">{{ answer.answerOption.points }}</mat-cell>
</ng-container>
<ng-container matColumnDef="actions"> <ng-container matColumnDef="actions">
<mat-header-cell *matHeaderCellDef>Actions</mat-header-cell> <mat-header-cell *matHeaderCellDef>Actions</mat-header-cell>
<mat-cell *matCellDef="let answer"> <mat-cell *matCellDef="let answer">
<button mat-icon-button <button mat-icon-button
(click)="openAnswerModificationDialog($event, answer.answerOption.label, answer.answerOption.points, answer.correct)" (click)="openAnswerModificationDialog($event, answer.answerOption.label, answer.correct)"
color="primary" matTooltip="Edit answer"> color="primary" matTooltip="Edit answer">
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
</button> </button>
...@@ -60,11 +55,7 @@ ...@@ -60,11 +55,7 @@
<mat-form-field class="input-block"> <mat-form-field class="input-block">
<input matInput #answerLabel [(ngModel)]="newAnswerOptionLabel" placeholder="Answer" name="answer"> <input matInput #answerLabel [(ngModel)]="newAnswerOptionLabel" placeholder="Answer" name="answer">
</mat-form-field> </mat-form-field>
<mat-form-field class="input-block"> <button mat-button type="button" (click)="addAnswer($event); answerLabel.value = '';">
<input matInput #answerPoints [(ngModel)]="newAnswerOptionPoints" placeholder="Points" name="points">
</mat-form-field>
<button mat-button type="button"
(click)="addAnswer($event); answerLabel.value = ''; answerPoints.value = ''">
Add Answer Add Answer
</button> </button>
</div> </div>
......
...@@ -41,14 +41,13 @@ export class ContentChoiceCreatorComponent implements OnInit { ...@@ -41,14 +41,13 @@ export class ContentChoiceCreatorComponent implements OnInit {
ContentType.CHOICE ContentType.CHOICE
); );
displayedColumns = ['label', 'points', 'actions']; displayedColumns = ['label', 'actions'];
displayAnswers: DisplayAnswer[] = []; displayAnswers: DisplayAnswer[] = [];
lastDeletedDisplayAnswer: DisplayAnswer; lastDeletedDisplayAnswer: DisplayAnswer;
newAnswerOptionChecked = false; newAnswerOptionChecked = false;
newAnswerOptionLabel = ''; newAnswerOptionLabel = '';
newAnswerOptionPoints = '';
editDisplayAnswer: DisplayAnswer; editDisplayAnswer: DisplayAnswer;
originalDisplayAnswer: DisplayAnswer; originalDisplayAnswer: DisplayAnswer;
...@@ -97,14 +96,12 @@ export class ContentChoiceCreatorComponent implements OnInit { ...@@ -97,14 +96,12 @@ export class ContentChoiceCreatorComponent implements OnInit {
this.notificationService.show('No empty answers allowed.'); this.notificationService.show('No empty answers allowed.');
this.newAnswerOptionChecked = false; this.newAnswerOptionChecked = false;
this.newAnswerOptionLabel = ''; this.newAnswerOptionLabel = '';
this.newAnswerOptionPoints = '';
return; return;
} }
if (this.singleChoice && this.content.correctOptionIndexes.length > 0 && this.newAnswerOptionChecked) { if (this.singleChoice && this.content.correctOptionIndexes.length > 0 && this.newAnswerOptionChecked) {
this.notificationService.show('In single choice mode is only 1 true answer allowed.'); this.notificationService.show('In single choice mode is only 1 true answer allowed.');
this.newAnswerOptionChecked = false; this.newAnswerOptionChecked = false;
this.newAnswerOptionLabel = ''; this.newAnswerOptionLabel = '';
this.newAnswerOptionPoints = '';
return; return;
} }
for (let i = 0; i < this.content.options.length; i++) { for (let i = 0; i < this.content.options.length; i++) {
...@@ -113,10 +110,10 @@ export class ContentChoiceCreatorComponent implements OnInit { ...@@ -113,10 +110,10 @@ export class ContentChoiceCreatorComponent implements OnInit {
return; return;
} }
} }
this.content.options.push(new AnswerOption(this.newAnswerOptionLabel, this.newAnswerOptionPoints)); let points = (this.newAnswerOptionChecked) ? '10' : '-10';
this.content.options.push(new AnswerOption(this.newAnswerOptionLabel, points));
this.newAnswerOptionChecked = false; this.newAnswerOptionChecked = false;
this.newAnswerOptionLabel = ''; this.newAnswerOptionLabel = '';
this.newAnswerOptionPoints = '';
this.fillCorrectAnswers(); this.fillCorrectAnswers();
} }
...@@ -139,7 +136,7 @@ export class ContentChoiceCreatorComponent implements OnInit { ...@@ -139,7 +136,7 @@ export class ContentChoiceCreatorComponent implements OnInit {
saveChanges(index: number, answer: DisplayAnswer, matDialogOutput: boolean) { saveChanges(index: number, answer: DisplayAnswer, matDialogOutput: boolean) {
this.content.options[index].label = answer.answerOption.label; this.content.options[index].label = answer.answerOption.label;
this.content.options[index].points = answer.answerOption.points; this.content.options[index].points = (answer.correct) ? '10' : '-10';
const indexInCorrectOptionIndexes = this.content.correctOptionIndexes.indexOf(index); const indexInCorrectOptionIndexes = this.content.correctOptionIndexes.indexOf(index);
if (indexInCorrectOptionIndexes === -1 && answer.correct) { if (indexInCorrectOptionIndexes === -1 && answer.correct) {
if (this.singleChoice) { if (this.singleChoice) {
......
...@@ -33,6 +33,8 @@ export class ContentService extends BaseHttpService { ...@@ -33,6 +33,8 @@ export class ContentService extends BaseHttpService {
} }
addContent(content: Content): Observable<Content> { addContent(content: Content): Observable<Content> {
delete content.id;
delete content.revision;
const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/'; const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/';
return this.http.post<Content>(connectionUrl, return this.http.post<Content>(connectionUrl,
content, content,
......
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