diff --git a/src/app/app.module.ts b/src/app/app.module.ts index f1834cbec00849ab5f244cd3421e2f644678a9f2..b0a0ab0d0418e769134d52282aefc8c09a154b5f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -124,7 +124,11 @@ import { AnswerEditComponent } from './components/dialogs/answer-edit/answer-edi RoomCreateComponent, RoomDeleteComponent, RoomEditComponent, - AnswerEditComponent + AnswerEditComponent, + ContentChoiceCreatorComponent, + ContentLikertCreatorComponent, + ContentTextCreatorComponent, + ContentYesNoCreatorComponent ], imports: [ AppRoutingModule, 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 e2daa460765765587ae8cc31b05391b01e926004..95825f915b98055cebbd207608ecb260c4886efd 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 @@ -1,12 +1,13 @@ -import { Component, OnInit } from '@angular/core'; +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 { NotificationService } from '../../../services/util/notification.service'; -import { MatDialog } from '@angular/material'; +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'; export class DisplayAnswer { answerOption: AnswerOption; @@ -49,10 +50,14 @@ export class ContentChoiceCreatorComponent implements OnInit { editDisplayAnswer: DisplayAnswer; originalDisplayAnswer: DisplayAnswer; + editDialogMode = false; + constructor(private contentService: ContentService, private notificationService: NotificationService, private route: ActivatedRoute, - public dialog: MatDialog) { + public dialog: MatDialog, + public dialogRef: MatDialogRef<ContentListComponent>, + @Inject(MAT_DIALOG_DATA) public data: any) { } ngOnInit() { 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 e8add519e21a70a0064c6129da0fbb41ef24e488..4c103a98c6cb5f84366669c694dde3d2c45648ee 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 @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Inject, OnInit } from '@angular/core'; import { DisplayAnswer } from '../content-choice-creator/content-choice-creator.component'; import { ContentChoice } from '../../../models/content-choice'; import { AnswerOption } from '../../../models/answer-option'; @@ -6,6 +6,8 @@ import { ContentType } from '../../../models/content-type.enum'; import { ContentService } from '../../../services/http/content.service'; import { NotificationService } from '../../../services/util/notification.service'; import { ActivatedRoute } from '@angular/router'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; +import { ContentListComponent } from '../content-list/content-list.component'; @Component({ selector: 'app-content-likert-creator', @@ -37,9 +39,13 @@ export class ContentLikertCreatorComponent implements OnInit { displayAnswers: DisplayAnswer[] = []; newAnswerOptionPoints = '0'; + editDialogMode = false; + constructor(private contentService: ContentService, private notificationService: NotificationService, - private route: ActivatedRoute) { + private route: ActivatedRoute, + public dialogRef: MatDialogRef<ContentListComponent>, + @Inject(MAT_DIALOG_DATA) public data: any) { } fillCorrectAnswers() { diff --git a/src/app/components/fragments/content-list/content-list.component.html b/src/app/components/fragments/content-list/content-list.component.html index fd966e2ad255f8af5c2cb07e0415cd9ea36a7aa7..9bb3fda15edcd84f54d010f7dbfaf204452a86be 100644 --- a/src/app/components/fragments/content-list/content-list.component.html +++ b/src/app/components/fragments/content-list/content-list.component.html @@ -1,7 +1,10 @@ <mat-list> <mat-list-item *ngFor="let content of contents"> - <button mat-button routerLink="content/{{content.contentId}}"> - Content {{content.contentId}}: {{content.subject}} +<!-- <button mat-button routerLink="content/{{content.contentId}}"> + Content {{content.contentId}}: {{content.subject}} Type: {{content.format}} + </button> --> + <button mat-button (click)="editContent(content.subject)"> + {{content.subject}} </button> </mat-list-item> </mat-list> diff --git a/src/app/components/fragments/content-list/content-list.component.ts b/src/app/components/fragments/content-list/content-list.component.ts index 929dbe0dacdd257ae8119516788cf445f92f3bc0..0239b29069f6d4d2892b6a24f034f21cb4650f8b 100644 --- a/src/app/components/fragments/content-list/content-list.component.ts +++ b/src/app/components/fragments/content-list/content-list.component.ts @@ -6,6 +6,10 @@ import { ContentChoice } from '../../../models/content-choice'; import { ContentText } from '../../../models/content-text'; import { AnswerOption } from '../../../models/answer-option'; import { ContentType } from '../../../models/content-type.enum'; +import { MatDialog } from '@angular/material'; +import { ContentChoiceCreatorComponent } from '../content-choice-creator/content-choice-creator.component'; +import { ContentLikertCreatorComponent } from '../content-likert-creator/content-likert-creator.component'; +import { ContentTextCreatorComponent } from '../content-text-creator/content-text-creator.component'; @Component({ selector: 'app-content-list', @@ -51,15 +55,18 @@ export class ContentListComponent implements OnInit { new AnswerOption('Strongly agree', '0'), new AnswerOption('Agree', '0'), new AnswerOption('Neither agree nor disagree', '0'), - new AnswerOption('Disagree', '0' ), - new AnswerOption('Strongly disagree', '0') ], + new AnswerOption('Disagree', '0'), + new AnswerOption('Strongly disagree', '0')], [], false, ContentType.SCALE) ]; + ContentType: typeof ContentType = ContentType; + constructor(private contentService: ContentService, - private route: ActivatedRoute) { + private route: ActivatedRoute, + public dialog: MatDialog) { } ngOnInit() { @@ -74,4 +81,95 @@ export class ContentListComponent implements OnInit { this.contents = contents; }); } + + findIndexOfSubject(subject: string): number { + let index = -1; + for (let i = 0; i < this.contents.length; i++) { + if (this.contents[i].subject.valueOf() === subject.valueOf()) { + index = i; + break; + } + } + return index; + } + + editContent(subject: string) { + const index = this.findIndexOfSubject(subject); + const format = this.contents[index].format; + + switch (format) { + case this.ContentType.CHOICE: + this.editChoiceContentDialog(index, this.contents[index] as ContentChoice); + break; + case this.ContentType.BINARY: + this.editBinaryContentDialog(index, this.contents[index] as ContentChoice); + break; + case this.ContentType.SCALE: + this.editLikertContentDialog(index, this.contents[index] as ContentChoice); + break; + case this.ContentType.TEXT: + this.editTextContentDialog(index, this.contents[index] as ContentText); + break; + default: + return; + } + } + + editChoiceContentDialog(index: number, content: ContentChoice) { + const dialogRef = this.dialog.open(ContentChoiceCreatorComponent, { + width: '400px' + }); + // TODO unterscheidung zwischen single / multiple + if (content.multiple) { + dialogRef.componentInstance.singleChoice = false; + dialogRef.componentInstance.multipleChoice = true; + } else { + dialogRef.componentInstance.multipleChoice = false; + dialogRef.componentInstance.singleChoice = true; + } + dialogRef.componentInstance.editDialogMode = true; + dialogRef.componentInstance.content = content; + dialogRef.afterClosed() + .subscribe(result => { + console.log(result); + }); + } + + editBinaryContentDialog(index: number, content: ContentChoice) { + const dialogRef = this.dialog.open(ContentChoiceCreatorComponent, { + width: '400px' + }); + dialogRef.componentInstance.editDialogMode = true; + dialogRef.componentInstance.multipleChoice = false; + dialogRef.componentInstance.singleChoice = true; + dialogRef.componentInstance.content = content; + dialogRef.afterClosed() + .subscribe(result => { + console.log(result); + }); + } + + editLikertContentDialog(index: number, content: ContentChoice) { + const dialogRef = this.dialog.open(ContentLikertCreatorComponent, { + width: '400px' + }); + dialogRef.componentInstance.editDialogMode = true; + dialogRef.componentInstance.content = content; + dialogRef.afterClosed() + .subscribe(result => { + console.log(result); + }); + } + + editTextContentDialog(index: number, content: ContentText) { + const dialogRef = this.dialog.open(ContentTextCreatorComponent, { + width: '400px' + }); + dialogRef.componentInstance.editDialogMode = true; + dialogRef.componentInstance.content = content; + dialogRef.afterClosed() + .subscribe(result => { + console.log(result); + }); + } } 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 7bcf89874197446fc2c8094877640e0da485a849..7d3feac8e04b9550bb7dbb92304423f0c67affa3 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 @@ -1,8 +1,10 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Inject, OnInit } from '@angular/core'; import { ContentText } from '../../../models/content-text'; import { ContentService } from '../../../services/http/content.service'; import { ActivatedRoute } from '@angular/router'; import { NotificationService } from '../../../services/util/notification.service'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; +import { ContentListComponent } from '../content-list/content-list.component'; @Component({ selector: 'app-content-text-creator', @@ -18,9 +20,13 @@ export class ContentTextCreatorComponent implements OnInit { '', 1); + editDialogMode = false; + constructor(private contentService: ContentService, private notificationService: NotificationService, - private route: ActivatedRoute) { + private route: ActivatedRoute, + public dialogRef: MatDialogRef<ContentListComponent>, + @Inject(MAT_DIALOG_DATA) public data: any) { } ngOnInit() { 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 5008de09bc5b0b3c87a2573cf81c1b3fd4305bce..37a863db7045065c874a0d9f179aaac69c77c56a 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 @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Inject, OnInit } from '@angular/core'; import { ContentChoice } from '../../../models/content-choice'; import { DisplayAnswer } from '../content-choice-creator/content-choice-creator.component'; import { AnswerOption } from '../../../models/answer-option'; @@ -6,6 +6,8 @@ import { NotificationService } from '../../../services/util/notification.service import { ContentType } from '../../../models/content-type.enum'; import { ContentService } from '../../../services/http/content.service'; import { ActivatedRoute } from '@angular/router'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; +import { ContentListComponent } from '../content-list/content-list.component'; @Component({ selector: 'app-content-yes-no-creator', @@ -34,9 +36,13 @@ export class ContentYesNoCreatorComponent implements OnInit { displayAnswers: DisplayAnswer[] = []; newAnswerOptionPoints = ''; + editDialogMode = false; + constructor(private contentService: ContentService, private route: ActivatedRoute, - private notificationService: NotificationService) { + private notificationService: NotificationService, + public dialogRef: MatDialogRef<ContentListComponent>, + @Inject(MAT_DIALOG_DATA) public data: any) { } ngOnInit() {