Skip to content

Commit

Permalink
feat: add timestamp to comments and replies (#535)
Browse files Browse the repository at this point in the history
This adds a timestamp to comments and replies in the admin view

Resolves #534
  • Loading branch information
SudharakaP authored Dec 31, 2020
1 parent a7b47d8 commit 2d50de9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2 id="page-heading">
<td>
<ul class="list-unstyled">
<li *ngFor="let commentAndReplies of commentAndAllReplies(comment)">
<button class="btn" type="submit" (click)="changeToApprove(comment, commentAndReplies)"><fa-icon [icon]="commentAndReplies.approved ? 'check': 'question'"></fa-icon> {{commentAndReplies.commentBody}}</button>
<button class="btn" type="submit" (click)="changeToApprove(comment, commentAndReplies)"><fa-icon [icon]="commentAndReplies.approved ? 'check': 'question'"></fa-icon> {{commentAndReplies.commentBody}} ({{commentAndReplies.createdDate | date:'dd/MM/yy HH:mm'}})</button>
</li>
<li>
<div class="btn-group">
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/app/entities/comment/comment.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ export class CommentComponent implements OnInit, OnDestroy {
this.jhiAlertService.error(errorMessage, null, null);
}

commentAndAllReplies(comment: IComment): { commentBody: string; index: number; approved: boolean }[] {
const commentAndReplies: { commentBody: string; index: number; approved: boolean }[] = [];
commentAndReplies.push({ commentBody: comment.commentBody, index: -1, approved: comment.isApproved });
commentAndAllReplies(comment: IComment): { commentBody: string; index: number; approved: boolean; createdDate: Date }[] {
const commentAndReplies: { commentBody: string; index: number; approved: boolean; createdDate: Date }[] = [];
commentAndReplies.push({ commentBody: comment.commentBody, index: -1, approved: comment.isApproved, createdDate: comment.createdDate });
if (comment.replies !== undefined && comment.replies !== null) {
for (const index of Object.keys(comment.replies)) {
const reply: ICommentReply = comment.replies[index];
commentAndReplies.push({ commentBody: reply.replyBody, index: +index, approved: reply.approved });
commentAndReplies.push({ commentBody: reply.replyBody, index: +index, approved: reply.approved, createdDate: reply.createdDate });
}
}
return commentAndReplies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,33 @@ describe('Component Tests', () => {

it('Should call commentAndAllReplies', () => {
// GIVEN
const createdDate: Date = new Date();
const comment: IComment = {
commentBody: 'Test Comment',
replies: [
{ replyBody: 'Test Reply', isAdminReply: true, createdBy: 'Sudharaka', createdDate: new Date(), dislikesCount: 0, approved: true }
{
replyBody: 'Test Reply',
isAdminReply: true,
createdBy: 'Sudharaka',
createdDate,
dislikesCount: 0,
approved: true
}
],
likesCount: 0,
dislikesCount: 0,
isApproved: true,
isAdminComment: false,
createdBy: 'Sudharaka',
createdDate: new Date(),
createdDate,
lastModifiedBy: 'Asanka',
lastModifiedDate: new Date()
};

// THEN
expect(comp.commentAndAllReplies(comment)).toEqual([
{ commentBody: 'Test Comment', index: -1, approved: true },
{ commentBody: 'Test Reply', index: 0, approved: true }
{ commentBody: 'Test Comment', index: -1, approved: true, createdDate },
{ commentBody: 'Test Reply', index: 0, approved: true, createdDate }
]);
});

Expand Down

0 comments on commit 2d50de9

Please sign in to comment.