]> BookStack Code Mirror - bookstack/commitdiff
#47 - Adds direct linking to comments.
authorAbijeet <redacted>
Wed, 7 Jun 2017 19:44:53 +0000 (01:14 +0530)
committerAbijeet <redacted>
Wed, 7 Jun 2017 19:44:53 +0000 (01:14 +0530)
resources/assets/js/controllers.js
resources/assets/js/directives.js
resources/assets/js/pages/page-show.js
resources/views/comments/list-item.blade.php

index a929f4aed2543dad113c157c6efa563f24b8070c..c1bfd441f649d55c728a6cf7302296ed8a195f5b 100644 (file)
@@ -776,7 +776,7 @@ module.exports = function (ngApp, events) {
     }]);
 
     // Controller used to fetch all comments for a page
-    ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
+    ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', '$location', function ($scope, $http, $timeout, $location) {
         let vm = this;
         $scope.errors = {};
         // keep track of comment levels
@@ -808,7 +808,7 @@ module.exports = function (ngApp, events) {
             if (vm.permissions[propOwn] && comment.created_by.id === vm.current_user_id) {
                 return true;
             }
-            
+
             return false;
         };
 
@@ -816,6 +816,9 @@ module.exports = function (ngApp, events) {
             return vm.permissions.comment_create;
         };
 
+        // check if there are is any direct linking
+        let linkedCommentId = $location.search().cm;
+
         $timeout(function() {
             $http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
                 if (!isCommentOpSuccess(resp)) {
@@ -829,6 +832,13 @@ module.exports = function (ngApp, events) {
                 vm.permissions = resp.data.permissions;
                 vm.current_user_id = resp.data.user_id;
                 setTotalCommentMsg();
+                if (!linkedCommentId) {
+                    return;
+                }
+                $timeout(function() {
+                    // wait for the UI to render.
+                    focusLinkedComment(linkedCommentId);
+                });
             }, checkError);
         });
 
@@ -844,6 +854,15 @@ module.exports = function (ngApp, events) {
             }
         }
 
+        function focusLinkedComment(linkedCommentId) {
+            let comment = angular.element('#' + linkedCommentId);
+            if (comment.length === 0) {
+                return;
+            }
+
+            window.setupPageShow.goToText(linkedCommentId);
+        }
+
         function checkError(response) {
             let msg = null;
             if (isCommentOpSuccess(response)) {
index 0b9402a6b6101d6f7c2a8b163288a249febc5908..bbdf1a0aee0e87422419d418b77e684ad0875b5e 100644 (file)
@@ -889,7 +889,8 @@ module.exports = function (ngApp, events) {
                     scope.$destroy();
                 });
 
-                element.on('click', function () {
+                element.on('click', function (e) {
+                    e.preventDefault();
                     var $container = element.parents('.comment-actions').first();
                     if (!$container.length) {
                         console.error('commentReplyLink directive should be placed inside a container with class comment-box!');
@@ -933,13 +934,14 @@ module.exports = function (ngApp, events) {
             },
             link: function (scope, element, attr, ctrl) {
 
-                element.on('click', function() {
-                   var resp = $window.confirm('This will remove the content of the comment, are you sure you want to continue?');
-                   if (!resp) {
-                       return;
-                   }
+                element.on('click', function(e) {
+                    e.preventDefault();
+                    var resp = $window.confirm('This will remove the content of the comment, are you sure you want to continue?');
+                    if (!resp) {
+                        return;
+                    }
 
-                   ctrl.delete(scope.comment);
+                    ctrl.delete(scope.comment);
                 });
             }
         };
index 67d339d63a32c139831550c7be13bc9ee3fa9f13..020229d2ff5f12e13b9d575ec4a98089d3630014 100644 (file)
@@ -161,6 +161,8 @@ let setupPageShow = window.setupPageShow = function (pageId) {
         }
     });
 
+    // in order to call from other places.
+    window.setupPageShow.goToText = goToText;
 };
 
 module.exports = setupPageShow;
\ No newline at end of file
index 6904a4abfa2d423da174965ac598678acff0cbec..391e64baf41d42e544c6ec041fa38acc809a5fac 100644 (file)
@@ -17,7 +17,7 @@
                 <li ng-if="::(level < 3 && vm.canComment())"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" is-reply="true">{{ trans('entities.comment_reply') }}</a></li>
                 <li ng-if="::vm.canEditDelete(comment, 'comment_update')"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" >{{ trans('entities.comment_edit') }}</a></li>
                 <li ng-if="::vm.canEditDelete(comment, 'comment_delete')"><a href="#" comment-delete-link comment="comment" >{{ trans('entities.comment_delete') }}</a></li>
-                <li>Created <a title="@{{::comment.created.day_time_str}}" href="#comment-@{{::comment.id}}-@{{::pageId}}">@{{::comment.created.diff}}</a></li>
+                <li>Created <a title="@{{::comment.created.day_time_str}}" href="#?cm=comment-@{{::pageId}}-@{{::comment.id}}">@{{::comment.created.diff}}</a></li>
                 <li ng-if="::comment.updated"><span title="@{{::comment.updated.day_time_str}}">@{{ ::vm.trans('entities.comment_updated_text', { updateDiff: comment.updated.diff }) }}
                         <a href="@{{::comment.updated_by.profile_url}}">@{{::comment.updated_by.name}}</a></span></li>
             </ul>