From ad340e2c6acff4ee47dec25a0c3a7ec31e8739a2 Mon Sep 17 00:00:00 2001
From: Sebastian Wittek <sebastian.wittek@mni.thm.de>
Date: Tue, 19 Mar 2019 12:46:09 +0100
Subject: [PATCH] clean up code

---
 .../comment-create-page.component.html        |  3 +-
 .../comment-create-page.component.ts          | 39 +++++++++++++++++--
 .../participant/participant.module.ts         |  7 +++-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/app/components/participant/comment-create-page/comment-create-page.component.html b/src/app/components/participant/comment-create-page/comment-create-page.component.html
index 15f1a94f9..e2b40e834 100644
--- a/src/app/components/participant/comment-create-page/comment-create-page.component.html
+++ b/src/app/components/participant/comment-create-page/comment-create-page.component.html
@@ -13,10 +13,11 @@
           <mat-hint align="end">{{commentBody.value.length}} / 255</mat-hint>
       </mat-form-field>
       <button mat-raised-button color="accent"
-        (click)="send(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button>
+        (click)="pressSend(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button>
     </form>
   </div>
   <div fxLayout="row" fxLayoutAlign="center">
     <app-comment-list></app-comment-list>
   </div>
 </div>
+
diff --git a/src/app/components/participant/comment-create-page/comment-create-page.component.ts b/src/app/components/participant/comment-create-page/comment-create-page.component.ts
index cc9a85654..07918260f 100644
--- a/src/app/components/participant/comment-create-page/comment-create-page.component.ts
+++ b/src/app/components/participant/comment-create-page/comment-create-page.component.ts
@@ -8,6 +8,8 @@ import { NotificationService } from '../../../services/util/notification.service
 import { AuthenticationService } from '../../../services/http/authentication.service';
 import { User } from '../../../models/user';
 import { CommentListComponent } from '../../shared/comment-list/comment-list.component';
+import { MatDialog } from '@angular/material';
+import { SubmitCommentComponent } from '../_diaglogs/submit-comment/submit-comment.component';
 
 @Component({
   selector: 'app-comment-create-page',
@@ -29,6 +31,7 @@ export class CommentCreatePageComponent implements OnInit {
     private route: ActivatedRoute,
     private commentService: CommentService,
     private notification: NotificationService,
+    public dialog: MatDialog,
     private translationService: TranslateService) { }
 
   ngOnInit(): void {
@@ -37,27 +40,55 @@ export class CommentCreatePageComponent implements OnInit {
     this.roomId = localStorage.getItem(`roomId`);
   }
 
-  send(subject: string, body: string): void {
+  pressSend(subject: string, body: string): void{
+    if (this.checkInputData(subject, body)) {
+      this.openSubmitDialog(subject, body);
+    }
+  }
+
+
+  openSubmitDialog(subject: string, body: string): void {
+
+        const dialogRef = this.dialog.open(SubmitCommentComponent, {
+          width: '400px'
+        });
+        dialogRef.componentInstance.comment = new Comment();
+        dialogRef.componentInstance.comment.subject = subject;
+        dialogRef.componentInstance.comment.body = body;
+        dialogRef.afterClosed()
+          .subscribe(result => {
+            if (result === 'send') {
+              this.send(subject, body);
+            } else {
+              return;
+            }
+          });
+    }
+
+  checkInputData(subject: string, body: string): boolean {
     subject = subject.trim();
     body = body.trim();
     if (!subject && !body) {
       this.translationService.get('comment-page.error-both-fields').subscribe(message => {
         this.notification.show(message);
       });
-      return;
+      return false;
     }
     if (!subject) {
       this.translationService.get('comment-page.error-title').subscribe(message => {
         this.notification.show(message);
       });
-      return;
+      return false;
     }
     if (!body) {
       this.translationService.get('comment-page.error-comment').subscribe(message => {
         this.notification.show(message);
       });
-      return;
+      return false;
     }
+  }
+
+  send(subject: string, body: string): void {
     this.commentService.addComment({
       id: '',
       roomId: this.roomId,
diff --git a/src/app/components/participant/participant.module.ts b/src/app/components/participant/participant.module.ts
index 77d5bb077..761eb7136 100644
--- a/src/app/components/participant/participant.module.ts
+++ b/src/app/components/participant/participant.module.ts
@@ -11,6 +11,7 @@ import { ParticipantContentCarouselPageComponent } from './participant-content-c
 import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
 import { HttpClient } from '@angular/common/http';
 import { TranslateHttpLoader } from '@ngx-translate/http-loader';
+import { SubmitCommentComponent } from './_diaglogs/submit-comment/submit-comment.component';
 
 @NgModule({
   imports: [
@@ -32,7 +33,11 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader';
     ContentTextParticipantComponent,
     HomeParticipantPageComponent,
     RoomParticipantPageComponent,
-    ParticipantContentCarouselPageComponent
+    ParticipantContentCarouselPageComponent,
+    SubmitCommentComponent
+  ],
+  entryComponents: [
+    SubmitCommentComponent
   ]
 })
 export class ParticipantModule {
-- 
GitLab