1
0
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:
Abijeet
2017-04-27 02:35:29 +05:30
parent d447355a61
commit c3ea0d333e
12 changed files with 127 additions and 34 deletions

View File

@@ -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) {

View File

@@ -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();
}
}]);
};