diff --git a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html index f93715c5ab8435253d0655ddf1fc205fffa40477..66dad1648d1c6111ff6067d58ff3ff20319e2ead 100644 --- a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html +++ b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html @@ -38,11 +38,11 @@ <mat-header-cell *matHeaderCellDef>Actions</mat-header-cell> <mat-cell *matCellDef="let answer"> <button mat-icon-button - (click)="openAnswerModificationDialog(answer.answerOption.label, answer.answerOption.points, answer.correct)" + (click)="openAnswerModificationDialog($event, answer.answerOption.label, answer.answerOption.points, answer.correct)" color="primary" matTooltip="Edit answer"> <mat-icon>edit</mat-icon> </button> - <button mat-icon-button color="primary" (click)="deleteAnswer(answer.answerOption.label)" matTooltip="Delete answer"> + <button mat-icon-button color="primary" (click)="deleteAnswer($event, answer.answerOption.label)" matTooltip="Delete answer"> <mat-icon>delete</mat-icon> </button> </mat-cell> diff --git a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts index a5fed48f26a0e16925f4aeaa1bcd0f0373af83bf..a54682bb09c021e5098599ba75a825c4e834754e 100644 --- a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts +++ b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.ts @@ -101,7 +101,8 @@ export class ContentChoiceCreatorComponent implements OnInit { this.fillCorrectAnswers(); } - openAnswerModificationDialog(label: string, points: string, correct: boolean) { + openAnswerModificationDialog($event, label: string, points: string, correct: boolean) { + $event.preventDefault(); let index = -1; for (let i = 0; i < this.content.options.length; i++) { if (this.content.options[i].label.valueOf() === label.valueOf()) { @@ -117,13 +118,12 @@ export class ContentChoiceCreatorComponent implements OnInit { dialogRef.afterClosed() .subscribe(result => { if (result === 'edit') { - // this.editCheckChanges(); - this.saveChanges(index, this.editDisplayAnswer); + this.saveChanges(index, this.editDisplayAnswer, true); } }); } - saveChanges(index: number, answer: DisplayAnswer) { + saveChanges(index: number, answer: DisplayAnswer, matDialogOutput: boolean) { this.content.options[index].label = answer.answerOption.label; this.content.options[index].points = answer.answerOption.points; const indexInCorrectOptionIndexes = this.content.correctOptionIndexes.indexOf(index); @@ -139,10 +139,13 @@ export class ContentChoiceCreatorComponent implements OnInit { this.content.correctOptionIndexes.splice(indexInCorrectOptionIndexes, 1); } this.fillCorrectAnswers(); - this.notificationService.show('Update changes.'); + if (matDialogOutput) { + this.notificationService.show('Update changes.'); + } } - deleteAnswer(label: string) { + deleteAnswer($event, label: string) { + $event.preventDefault(); for (let i = 0; i < this.content.options.length; i++) { if (this.content.options[i].label.valueOf() === label.valueOf()) { this.lastDeletedDisplayAnswer = new DisplayAnswer(this.content.options[i], false); @@ -166,7 +169,7 @@ export class ContentChoiceCreatorComponent implements OnInit { $event.preventDefault(); let msgAddon = 'Answer "' + this.lastDeletedDisplayAnswer.answerOption.label + '" successfully recovered.'; if (this.lastDeletedDisplayAnswer === null) { - this.notificationService.show('Nothing to recover'); + this.notificationService.show('Nothing to recover.'); } for (let i = 0; i < this.content.options.length; i++) { if (this.content.options[i].label.valueOf() === this.lastDeletedDisplayAnswer.answerOption.label.valueOf()) { @@ -189,7 +192,6 @@ export class ContentChoiceCreatorComponent implements OnInit { switchValue(label: string) { let index: number; - let isCorrect: boolean; // Get id of answer for (let i = 0; i < this.content.options.length; i++) { @@ -198,25 +200,13 @@ export class ContentChoiceCreatorComponent implements OnInit { break; } } - // Check if answer is marked as correct - isCorrect = !this.displayAnswers[index].correct; - - // Update correct answers - if (isCorrect) { - if (this.content.correctOptionIndexes.indexOf(index) === -1) { - // ToDo: Set back to data model - if (this.multipleChoice) { - this.content.correctOptionIndexes.push(index); - } else { - this.content.correctOptionIndexes = [index]; - } - } - } else { - if (this.content.correctOptionIndexes.indexOf(index) !== -1) { - this.content.correctOptionIndexes.splice(index, 1); - } - } - this.fillCorrectAnswers(); + this.editDisplayAnswer = new DisplayAnswer( + new AnswerOption( + this.displayAnswers[index].answerOption.label, + this.displayAnswers[index].answerOption.points), + !this.displayAnswers[index].correct); + this.saveChanges(index, this.editDisplayAnswer, false); + // return; } reset($event) { @@ -229,6 +219,15 @@ export class ContentChoiceCreatorComponent implements OnInit { this.notificationService.show('Reset all inputs to default.'); } + resetAfterSubmit() { + this.content.subject = ''; + this.content.body = ''; + this.content.options = []; + this.content.correctOptionIndexes = []; + this.fillCorrectAnswers(); + this.notificationService.show('Content submitted. Ready for creation of new content.'); + } + submitContent() { if (this.content.body.valueOf() === '' || this.content.body.valueOf() === '') { this.notificationService.show('No empty fields allowed. Please check subject and body.'); @@ -242,7 +241,7 @@ export class ContentChoiceCreatorComponent implements OnInit { this.notificationService.show('In single choice mode you have to select 1 true answer.'); return; } - if (this.multipleChoice && this.content.correctOptionIndexes.length !== 1) { + if (this.multipleChoice && this.content.correctOptionIndexes.length < 1) { this.notificationService.show('In multiple choice mode you have to select at least 1 true answer.'); return; } @@ -254,8 +253,10 @@ export class ContentChoiceCreatorComponent implements OnInit { this.content.multiple = true; this.content.format = ContentType.CHOICE; } - this.notificationService.show('Content submitted.'); // ToDo: Check api call // this.contentService.addContent(this.content); + // For Testing: + // console.log(this.content); + this.resetAfterSubmit(); } } diff --git a/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts b/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts index 017da8447b9b4fc964ae48e1f8b7f15e553b8189..e8add519e21a70a0064c6129da0fbb41ef24e488 100644 --- a/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts +++ b/src/app/components/fragments/content-likert-creator/content-likert-creator.component.ts @@ -60,7 +60,13 @@ export class ContentLikertCreatorComponent implements OnInit { this.fillCorrectAnswers(); } - // TODO + resetAfterSubmit() { + this.content.subject = ''; + this.content.body = ''; + this.content.correctOptionIndexes = []; + this.fillCorrectAnswers(); + this.notificationService.show('Content submitted. Ready for creation of new content.'); + } submitContent(): void { if (this.content.body.valueOf() === '' || this.content.body.valueOf() === '') { @@ -70,5 +76,8 @@ export class ContentLikertCreatorComponent implements OnInit { this.notificationService.show('Content sumbitted.'); // ToDo: Check api call // this.contentService.addContent(this.content); + // For Testing: + // console.log(this.content); + this.resetAfterSubmit(); } } diff --git a/src/app/components/fragments/content-text-creator/content-text-creator.component.ts b/src/app/components/fragments/content-text-creator/content-text-creator.component.ts index 283003bf662a0e073a424d069358f54a72c51b3f..7bcf89874197446fc2c8094877640e0da485a849 100644 --- a/src/app/components/fragments/content-text-creator/content-text-creator.component.ts +++ b/src/app/components/fragments/content-text-creator/content-text-creator.component.ts @@ -29,13 +29,22 @@ export class ContentTextCreatorComponent implements OnInit { }); } + resetAfterSubmit() { + this.content.subject = ''; + this.content.body = ''; + this.notificationService.show('Content submitted. Ready for creation of new content.'); + } + submitContent() { if (this.content.body.valueOf() === '' || this.content.body.valueOf() === '') { this.notificationService.show('No empty fields allowed. Please check subject and body.'); return; } - this.notificationService.show('Content sumbitted.'); + this.notificationService.show('Content submitted.'); // ToDo: Check api call // this.contentService.addContent(this.content); + // For Testing: + // console.log(this.content); + this.resetAfterSubmit(); } } diff --git a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html index 6b54e029299f0c498e97345d69d7b34525003ef0..fc11e052722c5abc3a8fe9f86a6fff04b6143ef0 100644 --- a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html +++ b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html @@ -13,7 +13,7 @@ <mat-header-cell *matHeaderCellDef>Answer</mat-header-cell> <mat-cell *matCellDef="let answer"> <!-- ToDo: Check ngModel --> - <mat-checkbox (click)="setCorrect(answer.answerOption.label)" color="primary" [(ngModel)]="answer.correct" [checked]="answer.correct" + <mat-checkbox (click)="setCorrect($event ,answer.answerOption.label)" color="primary" [(ngModel)]="answer.correct" [checked]="answer.correct" name="{{ answer.answerOption.label }}">{{ answer.answerOption.label }} </mat-checkbox> </mat-cell> diff --git a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts index bd7dfcc672c9fff5f085c852445d77df7983403a..5008de09bc5b0b3c87a2573cf81c1b3fd4305bce 100644 --- a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts +++ b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.ts @@ -56,7 +56,8 @@ export class ContentYesNoCreatorComponent implements OnInit { } } - setCorrect(label: string) { + setCorrect($event, label: string) { + $event.preventDefault(); if (label === 'yes') { this.content.correctOptionIndexes = [0]; } @@ -70,6 +71,14 @@ export class ContentYesNoCreatorComponent implements OnInit { return (this.content.correctOptionIndexes.length === 1); } + resetAfterSubmit() { + this.content.subject = ''; + this.content.body = ''; + this.content.correctOptionIndexes = []; + this.fillCorrectAnswers(); + this.notificationService.show('Content submitted. Ready for creation of new content.'); + } + submitContent(): void { if (this.content.body.valueOf() === '' || this.content.body.valueOf() === '') { this.notificationService.show('No empty fields allowed. Please check subject and body.'); @@ -81,6 +90,9 @@ export class ContentYesNoCreatorComponent implements OnInit { } this.notificationService.show('Content sumbitted.'); // ToDo: Check api call - // this.contentService.addContent(this.content); + // this.contentService.addContent(this.content); + // For Testing: + // console.log(this.content); + this.resetAfterSubmit(); } }