diff --git a/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.html b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.html index 62e7a2629777ae0dd6500300cff40d7b9d9eeac0..0f9f90b06c6a5ef9f78021cb6ad947fd2a1d4c92 100644 --- a/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.html +++ b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.html @@ -13,7 +13,7 @@ <mat-hint align="end">{{commentBody.value.length}} / 255</mat-hint> </mat-form-field> <button mat-raised-button color="accent" - (click)="closeDialog('send')">{{ 'comment-page.send' | translate}}</button> + (click)="closeDialog(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button> </form> </div> </div> diff --git a/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.ts b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.ts index ac1ee967e55d7a6d0d57125b405f2977bf3b1625..30f15e785fe4178da2990118e6a605d8b936b0e1 100644 --- a/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.ts +++ b/src/app/components/shared/_dialogs/submit-comment/submit-comment.component.ts @@ -1,12 +1,13 @@ import { Component, Inject, OnInit } from '@angular/core'; import { Comment } from '../../../../models/comment'; -import { Router } from '@angular/router'; +import { ActivatedRoute } from '@angular/router'; import { NotificationService } from '../../../../services/util/notification.service'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; import { TranslateService } from '@ngx-translate/core'; import { CommentPageComponent } from '../../comment-page/comment-page.component'; import { AuthenticationService } from '../../../../services/http/authentication.service'; import { FormControl, Validators } from '@angular/forms'; +import { User } from '../../../../models/user'; @Component({ @@ -17,10 +18,14 @@ import { FormControl, Validators } from '@angular/forms'; export class SubmitCommentComponent implements OnInit { comment: Comment; + + user: User; + subjectForm = new FormControl('', [Validators.required]); bodyForm = new FormControl('', [Validators.required]); + private date = new Date(Date.now()); - constructor(private router: Router, + constructor(private route: ActivatedRoute, private notification: NotificationService, public dialogRef: MatDialogRef<CommentPageComponent>, private translateService: TranslateService, @@ -32,6 +37,7 @@ export class SubmitCommentComponent implements OnInit { ngOnInit() { this.translateService.use(localStorage.getItem('currentLang')); + this.user = this.authenticationService.getUser(); } onNoClick(): void { @@ -63,8 +69,15 @@ export class SubmitCommentComponent implements OnInit { } closeDialog(subject: string, body: string) { + this.checkInputData(subject, body); const comment = new Comment(); - this.checkInputData(comment.b) + /* this.route.params.subscribe(params => { + comment.roomId = params['roomId']; + }); */ + comment.roomId = localStorage.getItem(`roomId`); + comment.subject = subject; + comment.body = body; + comment.userId = this.user.id; this.dialogRef.close(comment); } } diff --git a/src/app/components/shared/comment-page/comment-page.component.html b/src/app/components/shared/comment-page/comment-page.component.html index 695ecb493024e5d4e2faaf219c37d552c61a9793..12043ecf8ef1b914d7a383a7636e2571288c638e 100644 --- a/src/app/components/shared/comment-page/comment-page.component.html +++ b/src/app/components/shared/comment-page/comment-page.component.html @@ -1,7 +1,7 @@ <div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="20px"> <div fxLayout="row" fxLayoutAlign="center"> <button mat-raised-button color="accent" - (click)="pressSend(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button> + (click)="openSubmitDialog()">{{ 'comment-page.send' | translate}}</button> </div> <div fxLayout="row" fxLayoutAlign="center"> <app-comment-list></app-comment-list> diff --git a/src/app/components/shared/comment-page/comment-page.component.ts b/src/app/components/shared/comment-page/comment-page.component.ts index 5aa350e279ce773638bd5cb2032d27873a51a86f..cb91f65b5aa91afd1c15c22cfab901a334db020d 100644 --- a/src/app/components/shared/comment-page/comment-page.component.ts +++ b/src/app/components/shared/comment-page/comment-page.component.ts @@ -1,12 +1,8 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { FormControl, Validators } from '@angular/forms'; -import { TranslateService } from '@ngx-translate/core'; import { Comment } from '../../../models/comment'; import { CommentService } from '../../../services/http/comment.service'; import { NotificationService } from '../../../services/util/notification.service'; -import { AuthenticationService } from '../../../services/http/authentication.service'; -import { User } from '../../../models/user'; import { CommentListComponent } from '../comment-list/comment-list.component'; import { MatDialog } from '@angular/material'; import { SubmitCommentComponent } from '../_dialogs/submit-comment/submit-comment.component'; @@ -18,34 +14,23 @@ import { SubmitCommentComponent } from '../_dialogs/submit-comment/submit-commen }) export class CommentPageComponent implements OnInit { @ViewChild(CommentListComponent) child: CommentListComponent; - roomId: string; - roomShortId: string; - user: User; - private date = new Date(Date.now()); - - - constructor( - protected authenticationService: AuthenticationService, - private route: ActivatedRoute, - private commentService: CommentService, - private notification: NotificationService, - public dialog: MatDialog) { } + constructor(private route: ActivatedRoute, + private commentService: CommentService, + private notification: NotificationService, + public dialog: MatDialog) { } ngOnInit(): void { - this.user = this.authenticationService.getUser(); - this.roomShortId = this.route.snapshot.paramMap.get('roomId'); - this.roomId = localStorage.getItem(`roomId`); } openSubmitDialog(): void { - const dialogRef = this.dialog.open(SubmitCommentComponent, { width: '400px' }); dialogRef.afterClosed() .subscribe(result => { if (result !== null) { + console.log(result); this.send(result); } else { return; @@ -53,19 +38,20 @@ export class CommentPageComponent implements OnInit { }); } - send(subject: string, body: string): void { + send(comment: Comment): void { this.commentService.addComment({ id: '', - roomId: this.roomId, - userId: this.user.id, - subject: subject, - body: body, - creationTimestamp: this.date.getTime(), + roomId: comment.roomId, + userId: comment.userId, + subject: comment.subject, + body: comment.body, + creationTimestamp: comment.creationTimestamp, read: false, revision: '' } as Comment).subscribe(() => { this.child.getComments(); - this.notification.show(`Comment '${subject}' successfully created.`); + this.notification.show(`Comment '${comment.subject}' successfully created.`); }); + } } diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index d9560745a18b931c5c95f97ece5d410ea7ded5cc..14e32bda25f4953022fd905d46062bc33448a9ee 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -10,14 +10,14 @@ export class Comment { favorite: boolean; creationTimestamp: number; - constructor(roomId: string, - userId: string, - subject: string, - body: string, - read: boolean, - correct: boolean, - favorite: boolean, - creationTimestamp: number) { + constructor(roomId: string = '', + userId: string = '', + subject: string = '', + body: string = '', + read: boolean = false, + correct: boolean = false, + favorite: boolean = false, + creationTimestamp: number = 0) { this.id = ''; this.roomId = roomId; this.userId = userId;