]> BookStack Code Mirror - bookstack/commitdiff
#47 - Updates the total comments when a comment is added.
authorAbijeet <redacted>
Sun, 4 Jun 2017 14:42:01 +0000 (20:12 +0530)
committerAbijeet <redacted>
Sun, 4 Jun 2017 14:42:01 +0000 (20:12 +0530)
app/Repos/CommentRepo.php
resources/assets/js/controllers.js
resources/assets/sass/_comments.scss
resources/lang/en/activities.php
resources/lang/en/entities.php
resources/views/comments/list-item.blade.php

index 55af0fe12ebac8508348847fa25d244a41e19ed4..b8aa579c6ed56cabe8c9470dd3f977353d0e839a 100644 (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;
index 0a4e7b33331871b654255a37fac148b80ee0c476..51f018232f708a14c25214026b184e005bccd2d2 100644 (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;
         }
index 0328341c38e5d7aa5a91aea3ce33cf7a685e9684..5da53a14de7e3638faf8066c03d739f09e25e58c 100644 (file)
         margin-bottom: 1em;
     }
 
+    .comment-inactive {
+        font-style: italic;
+        font-size: 0.85em;
+        padding-top: 5px;
+    }
+
     .user-image {
         float: left;
         margin-right: 10px;
index 56af4ca07b3c9914c9158a9e6c33fa116d07c2b7..125326b3304416c8fc82c48f8c8b4cba504c6ee3 100644 (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.'
+
 ];
index 610309362c2786212ca82caa3f0f154dd742cb8c..8480879d6c6517dd8ab58eedba929a1e8fba33ad 100644 (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...'
 ];
\ No newline at end of file
index 22cbb24c05fe39f2095c1791e317b681d3306af1..12629f0d6857d786fe32c14caa626f13ccaf1221 100644 (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">
Morty Proxy This is a proxified and sanitized view of the page, visit original site.