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 bbc6e69e52b5326a4c1fecc29d371e0f7a1069c2..ed5cd73558a75b0686d35f9a5601bf974f7215b5 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 @@ -1,3 +1,11 @@ +<form (ngSubmit)="submitContent(subject.value, body.value)"> + <mat-form-field class="input-block"> + <input matInput #subject [(ngModel)]="content.subject" placeholder="Subject" name="subject"> + </mat-form-field> + <mat-form-field class="input-block"> + <textarea matInput #body [(ngModel)]="content.body" placeholder="Body" name="body"></textarea> + </mat-form-field> + <mat-divider></mat-divider> <form (ngSubmit)="submitContent()"> <section class="choice-seformn" fxLayout="row" fxLayoutAlign="center" fxLayoutGap="20px"> <mat-checkbox (click)="singleChoice = true; multipleChoice = false;" 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 0b81440c4ea1f444a03aee7e9da1a258c3a27395..2807e4513b0c5132b50f7bf7721a71b3fc6f5b05 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 @@ -2,11 +2,11 @@ import { Component, Inject, OnInit } from '@angular/core'; import { AnswerOption } from '../../../models/answer-option'; import { ContentChoice } from '../../../models/content-choice'; import { ContentService } from '../../../services/http/content.service'; +import { ActivatedRoute } from '@angular/router'; import { NotificationService } from '../../../services/util/notification.service'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; import { AnswerEditComponent } from '../../dialogs/answer-edit/answer-edit.component'; import { ContentType } from '../../../models/content-type.enum'; -import { ActivatedRoute } from '@angular/router'; import { ContentListComponent } from '../content-list/content-list.component'; import { ContentDeleteComponent } from '../../dialogs/content-delete/content-delete.component'; @@ -54,6 +54,8 @@ export class ContentChoiceCreatorComponent implements OnInit { editDialogMode = false; changesAllowed = false; + roomId: string; + constructor(private contentService: ContentService, private notificationService: NotificationService, private route: ActivatedRoute, @@ -63,9 +65,7 @@ export class ContentChoiceCreatorComponent implements OnInit { } ngOnInit() { - this.route.params.subscribe(params => { - this.content.roomId = params['roomId']; - }); + this.roomId = this.route.snapshot.paramMap.get('roomId'); this.fillCorrectAnswers(); } @@ -229,7 +229,7 @@ export class ContentChoiceCreatorComponent implements OnInit { this.notificationService.show('Content submitted. Ready for creation of new content.'); } - submitContent() { + submitContent(subject: string, body: string) { if (this.content.body.valueOf() === '' || this.content.body.valueOf() === '') { this.notificationService.show('No empty fields allowed. Please check subject and body.'); return; @@ -258,17 +258,23 @@ export class ContentChoiceCreatorComponent implements OnInit { this.changesAllowed = true; return; } - // ToDo: Check api call - // this.contentService.addContent(this.content); - // For Testing: - // console.log(this.content); + this.contentService.addContent(new ContentChoice('', + '1', + this.roomId, + subject, + body, + 1, + [], + [], + true, + ContentType.CHOICE)).subscribe(); this.resetAfterSubmit(); } editDialogClose($event, action: string) { $event.preventDefault(); if (action.valueOf() === 'edit') { - this.submitContent(); + this.submitContent(this.content.subject, this.content.body); } if (action.valueOf() === 'abort') { this.dialogRef.close(action); 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 45a20bb9a55d8d10c044585ef8fda7e2f88d8186..3d3ee0cb4f9c7f4ab507364eb8eab72904eec784 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 @@ -43,6 +43,9 @@ export class ContentTextCreatorComponent implements OnInit { } submitContent(subject: string, body: string) { + this.contentService.addContent(new ContentText( + '1', '1', this.roomId, subject, body, 1 + )).subscribe(); if (this.content.body.valueOf() === '' || this.content.body.valueOf() === '') { this.notificationService.show('No empty fields allowed. Please check subject and body.'); return;