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 9bb3fda15edcd84f54d010f7dbfaf204452a86be..756295061ad1c9f6378274d66d5efdad82d291d0 100644 --- a/src/app/components/fragments/content-list/content-list.component.html +++ b/src/app/components/fragments/content-list/content-list.component.html @@ -1,8 +1,5 @@ <mat-list> <mat-list-item *ngFor="let content of contents"> -<!-- <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> 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 bdaf0c4e71e103aa6f83c34056a05a0e64800e22..6f645a5326922e1d133c7b241c3564de5d99ef7c 100644 --- a/src/app/components/fragments/content-list/content-list.component.ts +++ b/src/app/components/fragments/content-list/content-list.component.ts @@ -10,6 +10,7 @@ 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'; +import { NotificationService } from '../../../services/util/notification.service'; @Component({ selector: 'app-content-list', @@ -62,10 +63,13 @@ export class ContentListComponent implements OnInit { ContentType.SCALE) ]; + contentBackup: Content; + ContentType: typeof ContentType = ContentType; constructor(private contentService: ContentService, private route: ActivatedRoute, + private notificationService: NotificationService, public dialog: MatDialog) { } @@ -93,10 +97,53 @@ export class ContentListComponent implements OnInit { return index; } + createChoiceContentBackup(content: ContentChoice) { + const answerOptions: Array<AnswerOption> = new Array<AnswerOption> (); + const correctAnswers: number[] = []; + + for (let i = 0; i < content.options.length; i++) { + answerOptions.push(content.options[i]); + } + + for (let i = 0; i < content.correctOptionIndexes.length; i++) { + correctAnswers.push(content.correctOptionIndexes[i]); + } + + this.contentBackup = new ContentChoice( + content.contentId, + content.revision, + content.roomId, + content.subject, + content.body, + content.round, + answerOptions, + correctAnswers, + content.multiple, + content.format + ); + } + + createTextContentBackup(content: ContentText) { + this.contentBackup = new ContentText( + content.contentId, + content.revision, + content.roomId, + content.subject, + content.body, + content.round + ); + } + editContent(subject: string) { const index = this.findIndexOfSubject(subject); const format = this.contents[index].format; + if (format === this.ContentType.TEXT) { + this.createTextContentBackup(this.contents[index] as ContentText); + } else { + this.createChoiceContentBackup(this.contents[index] as ContentChoice); + } + switch (format) { case this.ContentType.CHOICE: this.editChoiceContentDialog(index, this.contents[index] as ContentChoice); @@ -130,7 +177,7 @@ export class ContentListComponent implements OnInit { dialogRef.componentInstance.content = content; dialogRef.afterClosed() .subscribe(result => { - console.log(result); + this.updateContentChanges(index, result); }); } @@ -144,7 +191,7 @@ export class ContentListComponent implements OnInit { dialogRef.componentInstance.content = content; dialogRef.afterClosed() .subscribe(result => { - console.log(result); + this.updateContentChanges(index, result); }); } @@ -156,7 +203,7 @@ export class ContentListComponent implements OnInit { dialogRef.componentInstance.content = content; dialogRef.afterClosed() .subscribe(result => { - console.log(result); + this.updateContentChanges(index, result); }); } @@ -168,7 +215,22 @@ export class ContentListComponent implements OnInit { dialogRef.componentInstance.content = content; dialogRef.afterClosed() .subscribe(result => { - console.log(result); + this.updateContentChanges(index, result); }); } + + updateContentChanges(index: number, action: string) { + if (action.valueOf() === 'delete') { + this.notificationService.show('Content "' + this.contents[index].subject + '" deleted.'); + this.contentService.deleteContent(this.contents[index].contentId); + this.contents.splice(index, 1); + } + if (action.valueOf() === 'edit') { + this.notificationService.show('Content "' + this.contents[index].subject + '" updated.'); + this.contentService.updateContent(this.contents[index]); + } + if (action.valueOf() === 'abort') { + this.contents[index] = this.contentBackup; + } + } } diff --git a/src/app/services/http/content.service.ts b/src/app/services/http/content.service.ts index 2ffd5eba9c13c2c82b287e8d5e7a43245465df88..2e29b4985e3c40b79afdea27189eac9f5a9eb01a 100644 --- a/src/app/services/http/content.service.ts +++ b/src/app/services/http/content.service.ts @@ -39,6 +39,11 @@ export class ContentService extends BaseHttpService { updateContent(content: Content) { // ToDo: implement service, api call - console.log(content); + console.log('Content updated.'); + } + + deleteContent(contentId: string) { + // ToDo: implement service, api call + console.log('Content deleted.'); } }