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 15f1a94f992f3905d07b32dbcfa26964dfd73334..e2b40e834674289e411690717f91947dcd3ef0fd 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 cc9a856544b82c240dd9b5a82583696266feb1dc..07918260f411cace35d250ddbadb8feb646c2371 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 77d5bb07717cd9433c3260a33bf96838a0bd9fda..761eb713673706f2f7fdf18427c47f81fca42b0b 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 {