From 9eccb28e13175be08aab71ffe158e19fe3dba98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Mon, 11 Feb 2019 14:10:38 +0100 Subject: [PATCH] Make content-choice-editing work finally --- .../content-edit/content-edit.component.html | 6 +++--- .../_dialogs/content-edit/content-edit.component.ts | 13 ++++++++++++- .../creator/content-list/content-list.component.ts | 2 +- src/app/services/http/content.service.ts | 8 ++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/app/components/creator/_dialogs/content-edit/content-edit.component.html b/src/app/components/creator/_dialogs/content-edit/content-edit.component.html index 4739a783f..00ebbba43 100644 --- a/src/app/components/creator/_dialogs/content-edit/content-edit.component.html +++ b/src/app/components/creator/_dialogs/content-edit/content-edit.component.html @@ -10,14 +10,14 @@ <ng-container matColumnDef="label"> <mat-cell *matCellDef="let answer"> <mat-form-field class="input-block"> - <input matInput [(ngModel)]="answer.answerOption.label" maxlength="20" name="answer"/> + <input matInput [(ngModel)]="answer.answerOption.label" maxlength="20" placeholder="A" name="answer"/> </mat-form-field> </mat-cell> </ng-container> <ng-container matColumnDef="checked"> - <mat-cell *matCellDef="let answer"> + <mat-cell *matCellDef="let answer; let i = index"> <mat-checkbox color="primary" [(ngModel)]="answer.correct" - [checked]="answer.correct"></mat-checkbox> + [checked]="answer.correct" (ngModelChange)="update(i)"></mat-checkbox> </mat-cell> </ng-container> <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row> diff --git a/src/app/components/creator/_dialogs/content-edit/content-edit.component.ts b/src/app/components/creator/_dialogs/content-edit/content-edit.component.ts index 9901c36e5..6aabe0d01 100644 --- a/src/app/components/creator/_dialogs/content-edit/content-edit.component.ts +++ b/src/app/components/creator/_dialogs/content-edit/content-edit.component.ts @@ -22,8 +22,19 @@ export class ContentEditComponent implements OnInit { ngOnInit() { for (let i = 0; i < this.content.options.length; i++) { let correct: boolean; - correct = this.content.options[i].points >= 0; + correct = this.content.options[i].points > 0; this.displayAnswers[i] = new DisplayAnswer(new AnswerOption(this.content.options[i].label, this.content.options[i].points), correct); } } + + update(index: number) { + if (this.displayAnswers[index].correct === true) { + this.content.options[index].points = 10; + } else { + this.content.options[index].points = -10; + // this.content.correctOptionIndexes[index] = -10; + + } + console.log('updated:' + index + this.displayAnswers[index].correct + this.content.options[index].points); + } } diff --git a/src/app/components/creator/content-list/content-list.component.ts b/src/app/components/creator/content-list/content-list.component.ts index 0b3b864af..bc1453e3f 100644 --- a/src/app/components/creator/content-list/content-list.component.ts +++ b/src/app/components/creator/content-list/content-list.component.ts @@ -155,7 +155,7 @@ export class ContentListComponent implements OnInit { break; case 'update': this.contents[index] = this.contentCBackup; - this.contentService.updateContent(this.contentCBackup).subscribe( () => { + this.contentService.updateChoiceContent(this.contentCBackup).subscribe( () => { this.notificationService.show('Content "' + this.contents[index].subject + '" updated.'); }); break; diff --git a/src/app/services/http/content.service.ts b/src/app/services/http/content.service.ts index 04f53433d..a917c39bb 100644 --- a/src/app/services/http/content.service.ts +++ b/src/app/services/http/content.service.ts @@ -75,6 +75,14 @@ export class ContentService extends BaseHttpService { ); } + updateChoiceContent(updatedContent: ContentChoice): Observable<ContentChoice> { + const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/' + updatedContent.id; + return this.http.put(connectionUrl, updatedContent, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<any>('updateContentChoice')) + ); + } + deleteContent(contentId: string): Observable<Content> { const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/' + contentId; return this.http.delete<Content>(connectionUrl, httpOptions).pipe( -- GitLab