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 ac95224c073f242c673681e05e688c0f5763b55d..a28a981824d16e13c9a6d57de3b8a59f0009fb8c 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 @@ -1,12 +1,6 @@ <div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="20px"> <div fxLayout="row" fxLayoutAlign="center"> <form> - <mat-form-field class="input-block"> - <input matInput #commentSubject type="text" maxlength="25" - placeholder="{{ 'comment-page.enter-title' | translate}}" onkeypress="return event.keyCode !=13;" - [formControl]="subjectForm"> - <mat-hint align="end">{{commentSubject.value.length}} / 25</mat-hint> - </mat-form-field> <mat-form-field class="input-block"> <textarea matInput #commentBody placeholder="{{ 'comment-page.enter-comment' | translate}}" matAutosizeMinRows=2 matAutosizeMaxRows=5 maxlength="255" [formControl]="bodyForm"></textarea> @@ -15,7 +9,7 @@ <button mat-raised-button color="warn" (click)="onNoClick()">{{ 'comment-page.abort' | translate}}</button> <button mat-raised-button color="accent" - (click)="closeDialog(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button> + (click)="closeDialog(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 8ac28bd7eaaa3662e9ea48e1a62787e0eb558e62..caca1c72a4921ef3610a4c1289d2b28784be762a 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 @@ -41,21 +41,8 @@ export class SubmitCommentComponent implements OnInit { this.dialogRef.close(); } - checkInputData(subject: string, body: string): boolean { - subject = subject.trim(); + checkInputData(body: string): boolean { body = body.trim(); - if (!subject && !body) { - this.translationService.get('comment-page.error-both-fields').subscribe(message => { - this.notification.show(message); - }); - return false; - } - if (!subject) { - this.translationService.get('comment-page.error-title').subscribe(message => { - this.notification.show(message); - }); - return false; - } if (!body) { this.translationService.get('comment-page.error-comment').subscribe(message => { this.notification.show(message); @@ -65,11 +52,10 @@ export class SubmitCommentComponent implements OnInit { return true; } - closeDialog(subject: string, body: string) { - if (this.checkInputData(subject, body) === true) { + closeDialog(body: string) { + if (this.checkInputData(body) === true) { const comment = new Comment(); 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-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index 679fbcb7e171e555636de62b89291de2a59a2799..a7a6ee930d806d2eae76cd7af3b75cbaaf7fd590 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -49,13 +49,18 @@ export class CommentListComponent implements OnInit { } parseIncomingMessage(message: Message) { - const payload = JSON.parse(message.body).payload; - const c = new Comment(); - c.roomId = this.roomId; - c.subject = payload.subject; - c.body = payload.body; - - this.comments = this.comments.concat(c); + const msg = JSON.parse(message.body); + const payload = msg.payload; + if (msg.type === 'CommentCreated') { + const c = new Comment(); + c.roomId = this.roomId; + c.body = payload.body; + c.id = payload.id; + c.creationTimestamp = payload.timestamp; + this.comments = this.comments.concat(c); + } else if (msg.type === 'CommentPatched') { + console.log(msg); + } } } 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 669a7e698d09edb5838d3ba330a4e1c0c1a3748c..1510402b7775bc6192972a243325f6a18e67bc73 100644 --- a/src/app/components/shared/comment-page/comment-page.component.ts +++ b/src/app/components/shared/comment-page/comment-page.component.ts @@ -30,7 +30,7 @@ export class CommentPageComponent implements OnInit { private authenticationService: AuthenticationService) { } ngOnInit(): void { - this.roomId = localStorage.getItem("roomId"); + this.roomId = localStorage.getItem('roomId'); this.user = this.authenticationService.getUser(); } @@ -64,7 +64,7 @@ export class CommentPageComponent implements OnInit { this.child.getComments(); this.notification.show(`Comment '${comment.subject}' successfully created.`); });*/ - const message = new CreateComment(comment.roomId, comment.userId, comment.subject, comment.body); + const message = new CreateComment(comment.roomId, comment.userId, comment.body); this.rxStompService.publish({ destination: `/queue/comment.command`, body: JSON.stringify(message), diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index 0a7b94d7b03ccd714d9ece9b3213bd20b238fbf9..0ee9be9f73c1dc47fd66df382a089f4a794be2c3 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -51,7 +51,7 @@ export class CommentComponent implements OnInit { delete(comment: Comment): void { this.commentService.deleteComment(comment.id).subscribe(room => { - this.notification.show(`Comment '${comment.subject}' successfully deleted.`); + this.notification.show(`Comment '${comment.body}' successfully deleted.`); }); } } diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index 14e32bda25f4953022fd905d46062bc33448a9ee..4ad14507ddd5ea9032774f6d80cce46d8a7a9a7d 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -3,7 +3,6 @@ export class Comment { roomId: string; userId: string; revision: string; - subject: string; body: string; read: boolean; correct: boolean; @@ -12,7 +11,6 @@ export class Comment { constructor(roomId: string = '', userId: string = '', - subject: string = '', body: string = '', read: boolean = false, correct: boolean = false, @@ -22,7 +20,6 @@ export class Comment { this.roomId = roomId; this.userId = userId; this.revision = ''; - this.subject = subject; this.body = body; this.read = read; this.correct = correct; diff --git a/src/app/models/messages/create-comment.ts b/src/app/models/messages/create-comment.ts index 43331c038f5e27a81b53fd56121787bc96e65da3..ca7c5fa54fa4f92461aea73de49b1906f4b2b26a 100644 --- a/src/app/models/messages/create-comment.ts +++ b/src/app/models/messages/create-comment.ts @@ -3,16 +3,14 @@ export class CreateComment { payload: { roomId: string; creatorId: string; - subject: string; body: string; }; - constructor(roomId: string, creatorId: string, subject: string, body: string) { + constructor(roomId: string, creatorId: string, body: string) { this.type = 'CreateComment'; this.payload = { roomId: roomId, creatorId: creatorId, - subject: subject, body: body }; } diff --git a/src/app/models/messages/patch-comment.ts b/src/app/models/messages/patch-comment.ts new file mode 100644 index 0000000000000000000000000000000000000000..4d8313101e98043190084d7e3ff2c3dab98b959a --- /dev/null +++ b/src/app/models/messages/patch-comment.ts @@ -0,0 +1,17 @@ +export class PatchComment { + type: string; + payload: { + roomId: string; + creatorId: string; + body: string; + }; + + constructor(roomId: string, creatorId: string, body: string) { + this.type = 'CreateComment'; + this.payload = { + roomId: roomId, + creatorId: creatorId, + body: body + }; + } +} diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index 5a6b17c0bd419591980b7f0e2ec49550297e6272..d8673aa279dd3247b6afc5c2c36c2057201a47df 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -32,8 +32,7 @@ export class CommentService extends BaseHttpService { addComment(comment: Comment): Observable<Comment> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/'; return this.http.post<Comment>(connectionUrl, - { - roomId: comment.roomId, subject: comment.subject, body: comment.body, + { roomId: comment.roomId, body: comment.body, read: comment.read, creationTimestamp: comment.creationTimestamp }, httpOptions).pipe( tap(_ => ''),