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 21cb0b58ef26a338b84a3dc60aad716c78b46844..1de7a83ea50ea3f535ea42aa23dc7e9b807a86f0 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 @@ -17,7 +17,7 @@ <ng-container matColumnDef="checked"> <mat-cell *matCellDef="let answer; let i = index"> <mat-checkbox color="primary" [(ngModel)]="answer.correct" - [checked]="answer.correct" (ngModelChange)="update(i)"></mat-checkbox> + [checked]="answer.correct" (ngModelChange)="updateAnswer(i)"></mat-checkbox> </mat-cell> </ng-container> <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row> @@ -26,7 +26,7 @@ <button (click)="dialogRef.close('abort')" mat-button color="primary"> {{ 'room-page.abort' | translate }} </button> - <button (click)="dialogRef.close('update')" mat-raised-button color="primary"> + <button (click)="updateContent()" mat-raised-button color="primary"> {{ 'room-page.update' | translate }} </button> </div> 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 25c5c307ee8aab80b4c99b570b2812952203b82d..fb663831fa598be5d2b5f0d1fccf5226f3b11ab5 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 @@ -4,6 +4,8 @@ import { ContentListComponent } from '../../content-list/content-list.component' import { DisplayAnswer } from '../../content-choice-creator/content-choice-creator.component'; import { ContentChoice } from '../../../../models/content-choice'; import { AnswerOption } from '../../../../models/answer-option'; +import { TranslateService } from '@ngx-translate/core'; +import { NotificationService } from '../../../../services/util/notification.service'; @Component({ selector: 'app-content-edit', @@ -15,7 +17,9 @@ export class ContentEditComponent implements OnInit { displayAnswers: DisplayAnswer[] = []; displayedColumns = ['label', 'checked']; - constructor(public dialogRef: MatDialogRef<ContentListComponent>, + constructor(private translateService: TranslateService, + private notificationService: NotificationService, + public dialogRef: MatDialogRef<ContentListComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { } @@ -27,11 +31,42 @@ export class ContentEditComponent implements OnInit { } } - update(index: number) { + updateAnswer(index: number) { if (this.displayAnswers[index].correct === true) { this.content.options[index].points = 10; } else { this.content.options[index].points = -10; } } + + updateContent() { + if (this.content.subject === '' || this.content.body === '') { + this.translateService.get('content.no-empty').subscribe(message => { + this.notificationService.show(message); + }); + return; + } + if (this.content.options.length === 0) { + this.translateService.get('content.need-answers').subscribe(message => { + this.notificationService.show(message); + }); + return; + } + for (let i = 0; i < this.content.options.length; i++) { + if (this.content.options[i].label === '') { + this.translateService.get('content.no-empty2').subscribe(message => { + this.notificationService.show(message); + }); + return; + } + if (this.content.options[i].points > 0 && this.content.multiple) { + this.dialogRef.close('update'); + } else { + this.translateService.get('content.at-least-one').subscribe(message => { + this.notificationService.show(message); + }); + return; + } + } + } }