diff --git a/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.html b/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.html new file mode 100644 index 0000000000000000000000000000000000000000..efb99a94313dedc72250ce710100b6f2b77be485 --- /dev/null +++ b/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.html @@ -0,0 +1,10 @@ +<h3>{{ 'room-page.sure' | translate }}</h3> +<mat-divider></mat-divider> +<p>{{ 'comment-page.really-delete-answer' | translate }}</p> +<app-dialog-action-buttons + buttonsLabelSection="content" + confirmButtonLabel="delete" + [confirmButtonType]=confirmButtonType + [cancelButtonClickAction]="buildCloseDialogActionCallback()" + [confirmButtonClickAction]="buildCommentDeleteActionCallback()" +></app-dialog-action-buttons> diff --git a/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.scss b/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.spec.ts b/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d3032231bd93340cb0033e80bc47b15abfcd57b6 --- /dev/null +++ b/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.spec.ts @@ -0,0 +1,27 @@ +/* +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DeleteAnswerComponent } from './delete-answer.component'; + +describe('DeleteAnswerComponent', () => { + let component: DeleteAnswerComponent; + let fixture: ComponentFixture<DeleteAnswerComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DeleteAnswerComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DeleteAnswerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); +*/ diff --git a/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.ts b/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..4c082a042d0d75c1b2f076ae7ee33c8a29f420a9 --- /dev/null +++ b/src/app/components/creator/_dialogs/delete-answer/delete-answer.component.ts @@ -0,0 +1,41 @@ +import { Component, Inject, OnInit } from '@angular/core'; +import { DialogConfirmActionButtonType } from '../../../shared/dialog/dialog-action-buttons/dialog-action-buttons.component'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; +import { RoomEditComponent } from '../room-edit/room-edit.component'; +import { LiveAnnouncer } from '@angular/cdk/a11y'; +import { TranslateService } from '@ngx-translate/core'; + +@Component({ + selector: 'app-delete-answer', + templateUrl: './delete-answer.component.html', + styleUrls: ['./delete-answer.component.scss'] +}) +export class DeleteAnswerComponent implements OnInit { + + confirmButtonType: DialogConfirmActionButtonType = DialogConfirmActionButtonType.Alert; + + constructor(public dialogRef: MatDialogRef<RoomEditComponent>, + @Inject(MAT_DIALOG_DATA) public data: any, + private liveAnnouncer: LiveAnnouncer, + private translationService: TranslateService ) { } + + ngOnInit() { + this.translationService.get('comment-page.really-delete-answer').subscribe(msg => { + this.liveAnnouncer.announce(msg); + }); + } + + /** + * Returns a lambda which closes the dialog on call. + */ + buildCloseDialogActionCallback(): () => void { + return () => this.dialogRef.close('abort'); + } + + /** + * Returns a lambda which executes the dialog dedicated action on call. + */ + buildCommentDeleteActionCallback(): () => void { + return () => this.dialogRef.close('delete'); + } +} diff --git a/src/app/components/creator/creator.module.ts b/src/app/components/creator/creator.module.ts index b4fb412f1c6ac89d46df63a10baa0b98cc7aa938..22517930ce168a6333418086fbc5a1506dec3dd8 100644 --- a/src/app/components/creator/creator.module.ts +++ b/src/app/components/creator/creator.module.ts @@ -20,6 +20,7 @@ import { DeleteCommentComponent } from './_dialogs/delete-comment/delete-comment import { DeleteCommentsComponent } from './_dialogs/delete-comments/delete-comments.component'; import { BonusDeleteComponent } from './_dialogs/bonus-delete/bonus-delete.component'; import { MarkdownModule } from 'ngx-markdown'; +import { DeleteAnswerComponent } from './_dialogs/delete-answer/delete-answer.component'; @NgModule({ imports: [ @@ -50,7 +51,8 @@ import { MarkdownModule } from 'ngx-markdown'; ModeratorDeleteComponent, DeleteCommentsComponent, DeleteCommentComponent, - BonusDeleteComponent + BonusDeleteComponent, + DeleteAnswerComponent ], exports: [], entryComponents: [ @@ -64,7 +66,8 @@ import { MarkdownModule } from 'ngx-markdown'; TagsComponent, DeleteCommentsComponent, DeleteCommentComponent, - BonusDeleteComponent + BonusDeleteComponent, + DeleteAnswerComponent ] }) export class CreatorModule { diff --git a/src/app/components/shared/comment-answer/comment-answer.component.html b/src/app/components/shared/comment-answer/comment-answer.component.html index 20395fa0db8d1b0b3f241c1de42ce58d61e7861d..1981cf4d219b801bde48cac3e8cec70fff180b52 100644 --- a/src/app/components/shared/comment-answer/comment-answer.component.html +++ b/src/app/components/shared/comment-answer/comment-answer.component.html @@ -28,6 +28,8 @@ </mat-tab> </mat-tab-group> <div fxLayout="row" fxLayoutAlign="end"> + <button mat-raised-button *ngIf="!isStudent && answer" class="delete" (click)="openDeleteAnswerDialog()"> + {{'comment-page.delete-answer' | translate}}</button> <button mat-raised-button *ngIf="!isStudent" class="save" (click)="saveAnswer()"> {{'comment-page.save-answer' | translate}}</button> </div> diff --git a/src/app/components/shared/comment-answer/comment-answer.component.scss b/src/app/components/shared/comment-answer/comment-answer.component.scss index d8b5bf773337ed67548c7285a1a4a3f2cacd2195..43534c57e04467e3501feea426e0e1263c79a65a 100644 --- a/src/app/components/shared/comment-answer/comment-answer.component.scss +++ b/src/app/components/shared/comment-answer/comment-answer.component.scss @@ -10,13 +10,23 @@ app-comment, mat-card { box-sizing: border-box } +button { + min-width: 95px; + margin-top: 2%; +} + .save { background-color: var(--primary); color: var(--on-primary); - margin-top: 2%; margin-right: 1%; } +.delete { + background-color: var(--red); + color: var(--white); + margin-right: 20px; +} + mat-form-field { color: var(--on-surface); } diff --git a/src/app/components/shared/comment-answer/comment-answer.component.ts b/src/app/components/shared/comment-answer/comment-answer.component.ts index 5a77070c15b8a1a6a2e0923f6e47952ffb7782c6..9561be860538f55255175ccc8cceeb96011c5b7b 100644 --- a/src/app/components/shared/comment-answer/comment-answer.component.ts +++ b/src/app/components/shared/comment-answer/comment-answer.component.ts @@ -9,6 +9,8 @@ import { User } from '../../../models/user'; import { AuthenticationService } from '../../../services/http/authentication.service'; import { UserRole } from '../../../models/user-roles.enum'; import { NotificationService } from '../../../services/util/notification.service'; +import { MatDialog } from '@angular/material'; +import { DeleteAnswerComponent } from '../../creator/_dialogs/delete-answer/delete-answer.component'; @Component({ selector: 'app-comment-answer', @@ -29,7 +31,8 @@ export class CommentAnswerComponent implements OnInit { protected langService: LanguageService, protected wsCommentService: WsCommentServiceService, protected commentService: CommentService, - private authenticationService: AuthenticationService) { } + private authenticationService: AuthenticationService, + public dialog: MatDialog) { } ngOnInit() { this.user = this.authenticationService.getUser(); @@ -47,9 +50,28 @@ export class CommentAnswerComponent implements OnInit { saveAnswer() { this.wsCommentService.answer(this.comment, this.answer); - this.translateService.get('comment-list.comment-answered').subscribe(msg => { + this.translateService.get('comment-page.comment-answered').subscribe(msg => { this.notificationService.show(msg); }); } + openDeleteAnswerDialog(): void { + const dialogRef = this.dialog.open(DeleteAnswerComponent, { + width: '400px' + }); + dialogRef.afterClosed() + .subscribe(result => { + if (result === 'delete') { + this.deleteAnswer(); + } + }); + } + + deleteAnswer() { + this.answer = null; + this.wsCommentService.answer(this.comment, this.answer); + this.translateService.get('comment-page.answer-deleted').subscribe(msg => { + this.notificationService.show(msg); + }); + } } diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index 7dde7e39ca18e27952366c06bf899b178419b7fc..52a9a4e0e61b84c73dc6f4e57e333214fd9d02c8 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -184,6 +184,7 @@ export class CommentListComponent implements OnInit, OnDestroy { } parseIncomingMessage(message: Message) { + console.log(message); const msg = JSON.parse(message.body); const payload = msg.payload; switch (msg.type) { diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json index 629d8692e4464944c1b963801fa8595c3fd9bf7b..9d6f84831d4b95fbd92a1634e1c8f3cd526403f3 100644 --- a/src/assets/i18n/creator/de.json +++ b/src/assets/i18n/creator/de.json @@ -19,7 +19,6 @@ "answered": "Beantwortete Fragen", "pause-comments": "Pausiere den Fragen-Stream", "play-comments": "Starte den Fragen-Stream", - "comment-answered": "Antwort abgesendet", "comment-stream-stopped": "Der Fragen-Stream wurde gestoppt.", "comment-stream-started": "Der Fragen-Stream wurde gestartet.", "comment-sent": "Die Frage wurde veröffentlicht.", @@ -71,6 +70,10 @@ "your-answer": "Deine Antwort", "answer": "Frage kommentieren", "save-answer": "Speichern", + "comment-answered": "Antwort abgesendet.", + "delete-answer": "Löschen", + "really-delete-answer": "Willst du die Antwort wirklich löschen?", + "answer-deleted": "Antwort wurde gelöscht.", "has-answer": "Du hast die Frage kommentiert.", "cancel": "Abbrechen", "cancel-description": "Abbrechen", diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json index e6dd9c6d35d5c1ec008ed05fac1d79d9d7254960..c907a7106abd31aee4c9d74771ffebed5f855e68 100644 --- a/src/assets/i18n/creator/en.json +++ b/src/assets/i18n/creator/en.json @@ -19,7 +19,6 @@ "add-comment": "Ask a question!", "pause-comments": "Pause the question stream", "play-comments": "Start the question stream", - "comment-answered": "Answer has been sent!", "comment-stream-stopped": "The question stream has been stopped.", "comment-stream-started": "The question stream has been started.", "comment-sent": "The question has been published.", @@ -71,6 +70,10 @@ "your-answer": "Your answer", "answer": "Comment this question", "save-answer": "Save", + "comment-answered": "Answer has been sent.", + "delete-answer": "Delete", + "really-delete-answer": "Do you really want to delete this answer?", + "answer-deleted": "Answer has been deleted.", "has-answer": "You commented on the question.", "ask-question-description": "Enter your question to the audience here!", "cancel": "Cancel",