From 98878fa1f9c1186765b95564eff16e05a3afbcad Mon Sep 17 00:00:00 2001 From: Thomas Lenz <Thomas.Lenz@mni.thm.de> Date: Sun, 8 Apr 2018 12:11:36 +0200 Subject: [PATCH] Add content-delete component to all content components --- .../content-delete.component.ts | 47 ++----------------- .../content-choice-creator.component.html | 2 +- .../content-choice-creator.component.ts | 15 ++++++ .../content-likert-creator.component.html | 2 +- .../content-likert-creator.component.ts | 18 ++++++- .../content-text-creator.component.html | 2 +- .../content-text-creator.component.ts | 18 ++++++- .../content-yes-no-creator.component.html | 2 +- .../content-yes-no-creator.component.ts | 18 ++++++- 9 files changed, 74 insertions(+), 50 deletions(-) diff --git a/src/app/components/dialogs/content-delete/content-delete.component.ts b/src/app/components/dialogs/content-delete/content-delete.component.ts index ef6acc85e..a0abe7bd2 100644 --- a/src/app/components/dialogs/content-delete/content-delete.component.ts +++ b/src/app/components/dialogs/content-delete/content-delete.component.ts @@ -1,12 +1,7 @@ import { Component, Inject, OnInit } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; -import { RoomService } from '../../../services/http/room.service'; import { Router } from '@angular/router'; import { NotificationService } from '../../../services/util/notification.service'; -import { ContentChoiceCreatorComponent } from '../../fragments/content-choice-creator/content-choice-creator.component'; -import { ContentLikertCreatorComponent } from '../../fragments/content-likert-creator/content-likert-creator.component'; -import { ContentYesNoCreatorComponent } from '../../fragments/content-yes-no-creator/content-yes-no-creator.component'; -import { ContentTextCreatorComponent } from '../../fragments/content-text-creator/content-text-creator.component'; import { ContentType } from '../../../models/content-type.enum'; import { Content } from '../../../models/content'; @@ -20,52 +15,18 @@ export class ContentDeleteComponent implements OnInit { format: ContentType; content: Content; - constructor(private roomService: RoomService, - private router: Router, + constructor(private router: Router, private notification: NotificationService, - public dialogRef: MatDialogRef<ContentChoiceCreatorComponent>, - public dialogRefLikert: MatDialogRef<ContentLikertCreatorComponent>, - public dialogRefYesNo: MatDialogRef<ContentYesNoCreatorComponent>, - public dialogRefText: MatDialogRef<ContentTextCreatorComponent>, + public dialogRef: MatDialogRef<any>, @Inject(MAT_DIALOG_DATA) public data: any) { } onNoClick(): void { - switch (this.format) { - case ContentType.CHOICE: - this.dialogRef.close(); - break; - case ContentType.SCALE: - this.dialogRefLikert.close(); - break; - case ContentType.BINARY: - this.dialogRefYesNo.close(); - break; - case ContentType.TEXT: - this.dialogRefText.close(); - break; - default: - return; - } + this.dialogRef.close('abort'); } closeDialog(action: string) { - switch (this.format) { - case ContentType.CHOICE: - this.dialogRef.close(action); - break; - case ContentType.SCALE: - this.dialogRefLikert.close(action); - break; - case ContentType.BINARY: - this.dialogRefYesNo.close(action); - break; - case ContentType.TEXT: - this.dialogRefText.close(action); - break; - default: - return; - } + this.dialogRef.close(action); } ngOnInit() { 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 0e6db52f0..a61d5163b 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 @@ -85,7 +85,7 @@ <div *ngIf="editDialogMode"> <button mat-raised-button (click)="editDialogClose($event,'edit')" color="primary">Update</button> <button mat-raised-button (click)="editDialogClose($event,'abort')" color="primary">Abort</button> - <button mat-raised-button (click)="editDialogClose($event,'delete')" color="warn">Delete</button> + <button mat-raised-button (click)="openDeletionContentDialog($event)" color="warn">Delete</button> </div> </div> </form> 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 de311fa72..b4f9600e3 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 @@ -8,6 +8,7 @@ import { AnswerEditComponent } from '../../dialogs/answer-edit/answer-edit.compo 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'; export class DisplayAnswer { answerOption: AnswerOption; @@ -267,4 +268,18 @@ export class ContentChoiceCreatorComponent implements OnInit { onNoClick(): void { this.dialogRef.close(); } + + openDeletionContentDialog($event): void { + $event.preventDefault(); + const dialogRef = this.dialog.open(ContentDeleteComponent, { + width: '400px' + }); + dialogRef.componentInstance.content = this.content; + dialogRef.afterClosed() + .subscribe(result => { + if (result === 'delete') { + this.dialogRef.close(result); + } + }); + } } diff --git a/src/app/components/fragments/content-likert-creator/content-likert-creator.component.html b/src/app/components/fragments/content-likert-creator/content-likert-creator.component.html index dc46e25f7..29748e8b1 100644 --- a/src/app/components/fragments/content-likert-creator/content-likert-creator.component.html +++ b/src/app/components/fragments/content-likert-creator/content-likert-creator.component.html @@ -26,6 +26,6 @@ <div *ngIf="editDialogMode"> <button mat-raised-button (click)="editDialogClose($event,'edit')" color="primary">Update</button> <button mat-raised-button (click)="editDialogClose($event,'abort')" color="primary">Abort</button> - <button mat-raised-button (click)="editDialogClose($event,'delete')" color="warn">Delete</button> + <button mat-raised-button (click)="openDeletionContentDialog($event)" color="warn">Delete</button> </div> </form> 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 e3b3c7cb6..24c5a125c 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 @@ -6,8 +6,9 @@ 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 { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; import { ContentListComponent } from '../content-list/content-list.component'; +import { ContentDeleteComponent } from '../../dialogs/content-delete/content-delete.component'; @Component({ selector: 'app-content-likert-creator', @@ -44,6 +45,7 @@ export class ContentLikertCreatorComponent implements OnInit { constructor(private contentService: ContentService, private notificationService: NotificationService, private route: ActivatedRoute, + public dialog: MatDialog, public dialogRef: MatDialogRef<ContentListComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { } @@ -95,4 +97,18 @@ export class ContentLikertCreatorComponent implements OnInit { onNoClick(): void { this.dialogRef.close(); } + + openDeletionContentDialog($event): void { + $event.preventDefault(); + const dialogRef = this.dialog.open(ContentDeleteComponent, { + width: '400px' + }); + dialogRef.componentInstance.content = this.content; + dialogRef.afterClosed() + .subscribe(result => { + if (result === 'delete') { + this.dialogRef.close(result); + } + }); + } } diff --git a/src/app/components/fragments/content-text-creator/content-text-creator.component.html b/src/app/components/fragments/content-text-creator/content-text-creator.component.html index 0cc5f6284..a21dd0820 100644 --- a/src/app/components/fragments/content-text-creator/content-text-creator.component.html +++ b/src/app/components/fragments/content-text-creator/content-text-creator.component.html @@ -11,6 +11,6 @@ <div *ngIf="editDialogMode"> <button mat-raised-button (click)="editDialogClose($event,'edit')" color="primary">Update</button> <button mat-raised-button (click)="editDialogClose($event,'abort')" color="primary">Abort</button> - <button mat-raised-button (click)="editDialogClose($event,'delete')" color="warn">Delete</button> + <button mat-raised-button (click)="openDeletionContentDialog($event)" color="warn">Delete</button> </div> </form> 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 f57a8cf31..5608961eb 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 @@ -3,8 +3,9 @@ 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 { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; import { ContentListComponent } from '../content-list/content-list.component'; +import { ContentDeleteComponent } from '../../dialogs/content-delete/content-delete.component'; @Component({ selector: 'app-content-text-creator', @@ -25,6 +26,7 @@ export class ContentTextCreatorComponent implements OnInit { constructor(private contentService: ContentService, private notificationService: NotificationService, private route: ActivatedRoute, + public dialog: MatDialog, public dialogRef: MatDialogRef<ContentListComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { } @@ -62,4 +64,18 @@ export class ContentTextCreatorComponent implements OnInit { onNoClick(): void { this.dialogRef.close(); } + + openDeletionContentDialog($event): void { + $event.preventDefault(); + const dialogRef = this.dialog.open(ContentDeleteComponent, { + width: '400px' + }); + dialogRef.componentInstance.content = this.content; + dialogRef.afterClosed() + .subscribe(result => { + if (result === 'delete') { + this.dialogRef.close(result); + } + }); + } } diff --git a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html index 893460353..789031a51 100644 --- a/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html +++ b/src/app/components/fragments/content-yes-no-creator/content-yes-no-creator.component.html @@ -29,6 +29,6 @@ <div *ngIf="editDialogMode"> <button mat-raised-button (click)="editDialogClose($event,'edit')" color="primary">Update</button> <button mat-raised-button (click)="editDialogClose($event,'abort')" color="primary">Abort</button> - <button mat-raised-button (click)="editDialogClose($event,'delete')" color="warn">Delete</button> + <button mat-raised-button (click)="openDeletionContentDialog($event)" color="warn">Delete</button> </div> </form> 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 f395fa7c1..75857efdc 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 @@ -6,8 +6,9 @@ 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 { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; import { ContentListComponent } from '../content-list/content-list.component'; +import { ContentDeleteComponent } from '../../dialogs/content-delete/content-delete.component'; @Component({ selector: 'app-content-yes-no-creator', @@ -41,6 +42,7 @@ export class ContentYesNoCreatorComponent implements OnInit { constructor(private contentService: ContentService, private route: ActivatedRoute, private notificationService: NotificationService, + public dialog: MatDialog, public dialogRef: MatDialogRef<ContentListComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { } @@ -110,4 +112,18 @@ export class ContentYesNoCreatorComponent implements OnInit { onNoClick(): void { this.dialogRef.close(); } + + openDeletionContentDialog($event): void { + $event.preventDefault(); + const dialogRef = this.dialog.open(ContentDeleteComponent, { + width: '400px' + }); + dialogRef.componentInstance.content = this.content; + dialogRef.afterClosed() + .subscribe(result => { + if (result === 'delete') { + this.dialogRef.close(result); + } + }); + } } -- GitLab