Skip to content
Snippets Groups Projects
Commit c684ba93 authored by Hagen Dreßler's avatar Hagen Dreßler
Browse files

Add delete button to component comment

parent ea9db993
1 merge request!46Resolve "comment creation - participant component logic"
...@@ -18,6 +18,11 @@ export class CommentService { ...@@ -18,6 +18,11 @@ export class CommentService {
return this.http.post<Comment>(this.commentsUrl, comment, httpOptions); return this.http.post<Comment>(this.commentsUrl, comment, httpOptions);
} }
deleteComment(comment: Comment): Observable<Comment> {
const url = `${this.commentsUrl}/${comment.id}`;
return this.http.delete<Comment>(url, httpOptions);
}
getComments(roomId: string): Observable<Comment[]> { getComments(roomId: string): Observable<Comment[]> {
const url = `${this.commentsUrl}/?roomId=${roomId}`; const url = `${this.commentsUrl}/?roomId=${roomId}`;
return this.http.get<Comment[]>(url); return this.http.get<Comment[]>(url);
......
...@@ -3,14 +3,20 @@ ...@@ -3,14 +3,20 @@
<li *ngFor="let comment of comments"> <li *ngFor="let comment of comments">
<mat-card> <mat-card>
<mat-card-content> <mat-card-content>
<h3>{{comment.subject}}</h3><br> <div class="comment-body">
<h3>{{comment.subject}}</h3><br>
{{comment.body}} {{comment.body}}
<div class="trash-icon">
<i class="material-icons" (click)="delete(comment)">delete</i>
</div>
</div>
</mat-card-content> </mat-card-content>
<mat-card-footer> <mat-card-footer>
<div class="date"> <div class="date">
<i> {{comment.creationTimestamp | date:'dd-MM-yyyy HH:mm:ss' : format}} </i> <i> Submitted on {{comment.creationTimestamp | date:'dd-MM-yyyy HH:mm:ss' : format}} </i>
</div> </div>
</mat-card-footer> </mat-card-footer>
</mat-card><br> </mat-card><br>
</li> </li>
......
.trash-icon {
position: absolute;
top: 50%;
left: 98%;
}
.date { .date {
text-align: right; text-align: right;
font-size: 80%; font-size: 80%;
......
...@@ -31,8 +31,7 @@ export class CommentComponent implements OnInit { ...@@ -31,8 +31,7 @@ export class CommentComponent implements OnInit {
this.roomService.getRoom(id).subscribe( this.roomService.getRoom(id).subscribe(
params => { params => {
this.getComments(params['id'], params['name']); this.getComments(params['id'], params['name']);
} });
);
} }
getComments(roomId: string, roomName: string): void { getComments(roomId: string, roomName: string): void {
...@@ -41,6 +40,13 @@ export class CommentComponent implements OnInit { ...@@ -41,6 +40,13 @@ export class CommentComponent implements OnInit {
this.notification.show(`All comments of room "${roomName}" loaded!`); this.notification.show(`All comments of room "${roomName}" loaded!`);
} }
delete(comment: Comment): void {
this.comments = this.comments.filter(c => c !== comment);
this.commentService.deleteComment(comment).subscribe(room => {
this.notification.show(`Comment '${comment.subject}' successfully deleted.`);
});
}
goBack(): void { goBack(): void {
this.location.back(); this.location.back();
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment