1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-30 15:42:41 +01:00

Added functionality to highlight a comment.

This commit is contained in:
Abijeet 2017-08-22 01:31:11 +05:30
parent ac07cb41b6
commit b5cd3bff3c
3 changed files with 28 additions and 24 deletions

View File

@ -144,17 +144,4 @@ module.exports = function (ngApp, events) {
};
}]);
// Controller used to fetch all comments for a page
ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', '$location', function ($scope, $http, $timeout, $location) {
function focusLinkedComment(linkedCommentId) {
let comment = angular.element('#' + linkedCommentId);
if (comment.length === 0) {
return;
}
window.setupPageShow.goToText(linkedCommentId);
}
}]);
};

View File

@ -59,7 +59,6 @@ const props = ['initialComment', 'index', 'level', 'permissions', 'currentUserId
function data() {
return {
commentHref: null,
trans: trans,
comments: [],
showEditor: false,
@ -144,13 +143,11 @@ const methods = {
};
const computed = {
commentId: {
get: function () {
return `comment-${this.comment.page_id}-${this.comment.id}`;
},
set: function () {
this.commentHref = `#?cm=${this.commentId}`
}
commentId: function () {
return `comment-${this.comment.page_id}-${this.comment.id}`;
},
commentHref: function () {
return `#?cm=${this.commentId}`;
}
};

View File

@ -45,7 +45,7 @@ let computed = {
function mounted() {
this.pageId = Number(this.$el.getAttribute('page-id'));
// let linkedCommentId = this.$route.query.cm;
let linkedCommentId = null;
let linkedCommentId = getUrlParameter('cm');
this.$http.get(window.baseUrl(`/ajax/page/${this.pageId}/comments/`)).then(resp => {
if (!isCommentOpSuccess(resp)) {
// just show that no comments are available.
@ -60,9 +60,13 @@ function mounted() {
if (!linkedCommentId) {
return;
}
focusLinkedComment(linkedCommentId);
// adding a setTimeout to give comment list some time to render.
setTimeout(function() {
focusLinkedComment(linkedCommentId);
});
}).catch(err => {
this.$events.emit('error', 'errors.comment_list');
this.$events.emit('error', trans('errors.comment_list'));
});
}
@ -91,6 +95,22 @@ function beforeDestroy() {
this.$off('new-comment');
}
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.hash);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
function focusLinkedComment(linkedCommentId) {
let comment = document.getElementById(linkedCommentId);
if (comment && comment.length === 0) {
return;
}
window.setupPageShow.goToText(linkedCommentId);
}
module.exports = {
data, methods, mounted, computed, components: {
comment, commentReply