mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-01-03 23:42:28 +03:00
#47 - Adds functionality to display child comments. Also has some code towards the reply functionality.
This commit is contained in:
@@ -731,14 +731,14 @@ module.exports = function (ngApp, events) {
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
console.log($scope.pageId);
|
||||
$http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
|
||||
if (!resp.data || resp.data.success !== true) {
|
||||
// TODO : Handle error
|
||||
return;
|
||||
}
|
||||
}
|
||||
vm.comments = resp.data.comments.data;
|
||||
vm.totalComments = resp.data.comments.total;
|
||||
vm.totalComments = resp.data.total;
|
||||
// TODO : Fetch message from translate.
|
||||
if (vm.totalComments === 0) {
|
||||
vm.totalCommentsStr = 'No comments found.';
|
||||
} else if (vm.totalComments === 1) {
|
||||
@@ -749,6 +749,18 @@ module.exports = function (ngApp, events) {
|
||||
}, checkError('app'));
|
||||
});
|
||||
|
||||
vm.loadSubComments = function(event, comment) {
|
||||
event.preventDefault();
|
||||
$http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/${comment.id}/sub-comments`)).then(resp => {
|
||||
console.log(resp);
|
||||
if (!resp.data || resp.data.success !== true) {
|
||||
return;
|
||||
}
|
||||
comment.is_loaded = true;
|
||||
comment.comments = resp.data.comments.data;
|
||||
}, checkError('app'));
|
||||
};
|
||||
|
||||
function checkError(errorGroupName) {
|
||||
$scope.errors[errorGroupName] = {};
|
||||
return function(response) {
|
||||
|
||||
@@ -865,5 +865,52 @@ module.exports = function (ngApp, events) {
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
ngApp.directive('commentReply', ['$timeout', function ($timeout) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'comment-reply.html',
|
||||
scope: {
|
||||
|
||||
},
|
||||
link: function (scope, element, attr) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}]);
|
||||
|
||||
ngApp.directive('commentReplyLink', ['$document', '$compile', function ($document, $compile) {
|
||||
return {
|
||||
link: function (scope, element, attr) {
|
||||
element.on('$destroy', function () {
|
||||
element.off('click');
|
||||
scope.$destroy();
|
||||
});
|
||||
|
||||
element.on('click', function () {
|
||||
var $container = element.parents('.comment-box').first();
|
||||
if (!$container.length) {
|
||||
console.error('commentReplyLink directive should be placed inside a container with class comment-box!');
|
||||
return;
|
||||
}
|
||||
if (attr.noCommentReplyDupe) {
|
||||
removeDupe();
|
||||
}
|
||||
var compiledHTML = $compile('<comment-reply></comment-reply>')(scope);
|
||||
$container.append(compiledHTML);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function removeDupe() {
|
||||
let $existingElement = $document.find('comment-reply');
|
||||
if (!$existingElement.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existingElement.remove();
|
||||
}
|
||||
}]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user