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 4739a783fe6e2c7533ec6fcd0e62c16d9be89fcc..00ebbba4376c90b929f16242e83860c7ba881d56 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 9901c36e59597c57374052563294551d1ed5f446..6aabe0d0163728e99dbd49fa0c26c21d5a6ecc38 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 0b3b864af6712a79839e8c3f86db0b1e456145f6..bc1453e3fbe0b9100f71e5c8c1d95aa545052849 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 04f53433dd08456cc50f2c6612dfd78288878db3..a917c39bbfda89347d31a738c6b7220f0071ec74 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(