From 0580139c8823f08083837a19d21f3b34f138b1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=A4sler?= <tom.kaesler@mni.thm.de> Date: Wed, 20 Mar 2019 01:31:55 +0100 Subject: [PATCH] remove subject from comment --- .../submit-comment.component.html | 8 +------- .../submit-comment.component.ts | 20 +++---------------- .../comment-list/comment-list.component.ts | 19 +++++++++++------- .../comment-page/comment-page.component.ts | 4 ++-- .../shared/comment/comment.component.ts | 2 +- src/app/models/comment.ts | 3 --- src/app/models/messages/create-comment.ts | 4 +--- src/app/models/messages/patch-comment.ts | 17 ++++++++++++++++ src/app/services/http/comment.service.ts | 3 +-- 9 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 src/app/models/messages/patch-comment.ts 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 ac95224c0..a28a98182 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 8ac28bd7e..caca1c72a 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 679fbcb7e..a7a6ee930 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 669a7e698..1510402b7 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 0a7b94d7b..0ee9be9f7 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 14e32bda2..4ad14507d 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 43331c038..ca7c5fa54 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 000000000..4d8313101 --- /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 5a6b17c0b..d8673aa27 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(_ => ''), -- GitLab