1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-30 07:32:39 +01:00

#47 - Updates the total comments when a comment is added.

This commit is contained in:
Abijeet 2017-06-04 20:12:01 +05:30
parent 9558f84b97
commit 06d75e1804
6 changed files with 41 additions and 21 deletions

View File

@ -46,8 +46,8 @@ class CommentRepo {
}
public function delete($comment) {
$comment->text = trans('errors.cannot_add_comment_to_draft');
$comment->html = trans('errors.cannot_add_comment_to_draft');
$comment->text = trans('activities.comment_deleted');
$comment->html = trans('activities.comment_deleted');
$comment->active = false;
$userId = user()->id;
$comment->updated_by = $userId;

View File

@ -777,12 +777,14 @@ module.exports = function (ngApp, events) {
$scope.errors = {};
// keep track of comment levels
$scope.level = 1;
vm.totalCommentsStr = 'Loading...';
vm.totalCommentsStr = trans('entities.comments_loading');
vm.permissions = {};
$scope.$on('evt.new-comment', function (event, comment) {
// add the comment to the comment list.
vm.comments.push(comment);
++vm.totalComments;
setTotalCommentMsg();
event.stopPropagation();
event.preventDefault();
});
@ -812,21 +814,26 @@ module.exports = function (ngApp, events) {
return;
}
vm.comments = resp.data.comments;
vm.totalComments = resp.data.total;
vm.totalComments = +resp.data.total;
vm.permissions = resp.data.permissions;
vm.current_user_id = resp.data.user_id;
// TODO : Fetch message from translate.
if (vm.totalComments === 0) {
vm.totalCommentsStr = 'No comments found.';
} else if (vm.totalComments === 1) {
vm.totalCommentsStr = '1 Comments';
} else {
vm.totalCommentsStr = vm.totalComments + ' Comments';
}
setTotalCommentMsg();
}, checkError('app'));
});
function setTotalCommentMsg () {
// TODO : Fetch message from translate.
if (vm.totalComments === 0) {
vm.totalCommentsStr = trans('entities.no_comments');
} else if (vm.totalComments === 1) {
vm.totalCommentsStr = trans('entities.one_comment');
} else {
vm.totalCommentsStr = trans('entities.x_comments', {
numComments: vm.totalComments
});
}
}
function checkError(errorGroupName) {
$scope.errors[errorGroupName] = {};
return function(response) {
@ -836,15 +843,12 @@ module.exports = function (ngApp, events) {
}]);
function updateComment(comment, resp, $timeout, isDelete) {
if (isDelete && !resp.comment.active) {
comment.html = trans('entities.comment_deleted');
}
comment.text = resp.comment.text;
comment.updated = resp.comment.updated;
comment.updated_by = resp.comment.updated_by;
comment.active = resp.comment.active;
if (isDelete && !resp.comment.active) {
comment.html = trans('entities.comment_deleted');
comment.html = trans('activities.comment_deleted');
} else {
comment.html = resp.comment.html;
}

View File

@ -54,6 +54,12 @@
margin-bottom: 1em;
}
.comment-inactive {
font-style: italic;
font-size: 0.85em;
padding-top: 5px;
}
.user-image {
float: left;
margin-right: 10px;

View File

@ -37,4 +37,10 @@ return [
'book_sort' => 'sorted book',
'book_sort_notification' => 'Book Successfully Re-sorted',
// Comments
'comment_create_notification' => '',
'comment_update_notification' => '',
'comment_delete_notification' => '',
'comment_deleted' => 'This comment has been deleted.'
];

View File

@ -240,5 +240,9 @@ return [
*/
'comment' => 'Comment',
'comments' => 'Comments',
'comment_placeholder' => 'Enter your comments here, markdown supported...'
'comment_placeholder' => 'Enter your comments here, markdown supported...',
'no_comments' => 'No Comments',
'x_comments' => ':numComments Comments',
'one_comment' => '1 Comment',
'comments_loading' => 'Loading...'
];

View File

@ -6,11 +6,11 @@
<div class="comment-header">
<a href="@{{::comment.created_by.profile_url}}">@{{ ::comment.created_by.name }}</a>
</div>
<div ng-bind-html="comment.html" ng-if="::comment.active" class="comment-body">
<div ng-bind-html="comment.html" ng-if="::comment.active" class="comment-body" ng-class="!comment.active ? 'comment-inactive' : ''">
</div>
<div ng-if="::!comment.active" class="comment-body">
{{ trans('entites.comment_deleted') }}
<div ng-if="::!comment.active" class="comment-body comment-inactive">
{{ trans('activities.comment_deleted') }}
</div>
<div class="comment-actions">
<ul ng-if="!comment.is_hidden">