mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Fixed formatting and added error messages.
This commit is contained in:
parent
e8fa58f201
commit
ac07cb41b6
@ -21,28 +21,24 @@ const props = {
|
|||||||
}, isEdit: {
|
}, isEdit: {
|
||||||
default: false,
|
default: false,
|
||||||
type: Boolean
|
type: Boolean
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function data() {
|
function data() {
|
||||||
var comment = null;
|
let comment = {
|
||||||
// initialize comment if not passed.
|
|
||||||
if (!this.commentObj || this.isReply) {
|
|
||||||
comment = {
|
|
||||||
text: ''
|
text: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.isReply) {
|
if (this.isReply) {
|
||||||
comment.page_id = this.commentObj.page_id;
|
comment.page_id = this.commentObj.page_id;
|
||||||
comment.id = this.commentObj.id;
|
comment.id = this.commentObj.id;
|
||||||
}
|
} else if (this.isEdit) {
|
||||||
} else {
|
|
||||||
comment = this.commentObj;
|
comment = this.commentObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
trans: trans,
|
comment: comment,
|
||||||
parentId: null,
|
trans: trans
|
||||||
comment: comment
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +47,7 @@ const methods = {
|
|||||||
let pageId = this.comment.page_id || this.pageId;
|
let pageId = this.comment.page_id || this.pageId;
|
||||||
let commentText = this.comment.text;
|
let commentText = this.comment.text;
|
||||||
if (!commentText) {
|
if (!commentText) {
|
||||||
return this.$emit('evt.empty-comment');
|
return this.$events.emit('error', trans('errors.empty_comment'))
|
||||||
}
|
}
|
||||||
let commentHTML = md.render(commentText);
|
let commentHTML = md.render(commentText);
|
||||||
let serviceUrl = `/ajax/page/${pageId}/comment/`;
|
let serviceUrl = `/ajax/page/${pageId}/comment/`;
|
||||||
@ -69,9 +65,9 @@ const methods = {
|
|||||||
// if its reply, get the parent comment id
|
// if its reply, get the parent comment id
|
||||||
reqObj.parent_id = this.comment.id;
|
reqObj.parent_id = this.comment.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$http[httpMethod](window.baseUrl(serviceUrl), reqObj).then(resp => {
|
$http[httpMethod](window.baseUrl(serviceUrl), reqObj).then(resp => {
|
||||||
if (!isCommentOpSuccess(resp)) {
|
if (!isCommentOpSuccess(resp)) {
|
||||||
|
this.$events.emit('error', getErrorMsg(resp));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// hide the comments first, and then retrigger the refresh
|
// hide the comments first, and then retrigger the refresh
|
||||||
@ -85,10 +81,11 @@ const methods = {
|
|||||||
} else {
|
} else {
|
||||||
this.$parent.$emit('new-comment', event, resp.data.comment);
|
this.$parent.$emit('new-comment', event, resp.data.comment);
|
||||||
}
|
}
|
||||||
this.$emit('evt.comment-success', null, true);
|
|
||||||
}
|
}
|
||||||
|
this.$events.emit('success', resp.data.message);
|
||||||
}, checkError);
|
}).catch(err => {
|
||||||
|
this.$events.emit('error', trans('errors.comment_add'))
|
||||||
|
});
|
||||||
},
|
},
|
||||||
closeBox: function (event) {
|
closeBox: function (event) {
|
||||||
this.$emit('editor-removed', event);
|
this.$emit('editor-removed', event);
|
||||||
@ -104,20 +101,11 @@ function isCommentOpSuccess(resp) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkError(msgKey) {
|
function getErrorMsg(response) {
|
||||||
return function(response) {
|
if (response.data) {
|
||||||
let msg = null;
|
return response.data.message;
|
||||||
if (isCommentOpSuccess(response)) {
|
|
||||||
// all good
|
|
||||||
return;
|
|
||||||
} else if (response.data) {
|
|
||||||
msg = response.data.message;
|
|
||||||
} else {
|
} else {
|
||||||
msg = trans(msgKey);
|
return trans('errors.comment_add');
|
||||||
}
|
|
||||||
if (msg) {
|
|
||||||
events.emit('success', msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ const template = `
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="showEditor && level <= 3">
|
<div v-if="showEditor">
|
||||||
<comment-reply :page-id="comment.page_id" :comment-obj="comment"
|
<comment-reply :page-id="comment.page_id" :comment-obj="comment"
|
||||||
v-on:editor-removed.stop.prevent="hideComment"
|
v-on:editor-removed.stop.prevent="hideComment"
|
||||||
v-on:comment-replied.stop="commentReplied(...arguments)"
|
v-on:comment-replied.stop="commentReplied(...arguments)"
|
||||||
@ -59,8 +59,8 @@ const props = ['initialComment', 'index', 'level', 'permissions', 'currentUserId
|
|||||||
|
|
||||||
function data() {
|
function data() {
|
||||||
return {
|
return {
|
||||||
trans: trans,
|
|
||||||
commentHref: null,
|
commentHref: null,
|
||||||
|
trans: trans,
|
||||||
comments: [],
|
comments: [],
|
||||||
showEditor: false,
|
showEditor: false,
|
||||||
comment: this.initialComment,
|
comment: this.initialComment,
|
||||||
@ -76,15 +76,13 @@ const methods = {
|
|||||||
}
|
}
|
||||||
this.$http.delete(window.baseUrl(`/ajax/comment/${this.comment.id}`)).then(resp => {
|
this.$http.delete(window.baseUrl(`/ajax/comment/${this.comment.id}`)).then(resp => {
|
||||||
if (!isCommentOpSuccess(resp)) {
|
if (!isCommentOpSuccess(resp)) {
|
||||||
|
this.$events.emit('error', trans('error.comment_delete'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateComment(this.comment, resp.data, true);
|
|
||||||
}, function (resp) {
|
|
||||||
if (isCommentOpSuccess(resp)) {
|
|
||||||
this.$events.emit('success', trans('entities.comment_deleted'));
|
this.$events.emit('success', trans('entities.comment_deleted'));
|
||||||
} else {
|
this.comment = resp.data.comment;
|
||||||
|
}).catch(err => {
|
||||||
this.$events.emit('error', trans('error.comment_delete'));
|
this.$events.emit('error', trans('error.comment_delete'));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
replyComment: function () {
|
replyComment: function () {
|
||||||
@ -170,21 +168,10 @@ function isCommentOpSuccess(resp) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateComment(comment, resp, isDelete) {
|
|
||||||
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');
|
|
||||||
} else {
|
|
||||||
comment.html = resp.comment.html;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'comment',
|
name: 'comment',
|
||||||
template, data, props, methods, computed, mounted, components: {
|
template, data, props, methods, computed, mounted, components: {
|
||||||
commentReply
|
commentReply
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ function mounted() {
|
|||||||
if (!isCommentOpSuccess(resp)) {
|
if (!isCommentOpSuccess(resp)) {
|
||||||
// just show that no comments are available.
|
// just show that no comments are available.
|
||||||
vm.totalComments = 0;
|
vm.totalComments = 0;
|
||||||
|
this.$events.emit('error', getErrorMsg(resp));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.comments = resp.data.comments;
|
this.comments = resp.data.comments;
|
||||||
@ -59,11 +60,10 @@ function mounted() {
|
|||||||
if (!linkedCommentId) {
|
if (!linkedCommentId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$timeout(function() {
|
|
||||||
// wait for the UI to render.
|
|
||||||
focusLinkedComment(linkedCommentId);
|
focusLinkedComment(linkedCommentId);
|
||||||
|
}).catch(err => {
|
||||||
|
this.$events.emit('error', 'errors.comment_list');
|
||||||
});
|
});
|
||||||
}, checkError('errors.comment_list'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCommentOpSuccess(resp) {
|
function isCommentOpSuccess(resp) {
|
||||||
@ -73,20 +73,11 @@ function isCommentOpSuccess(resp) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkError(msgKey) {
|
function getErrorMsg(response) {
|
||||||
return function(response) {
|
if (response.data) {
|
||||||
let msg = null;
|
return response.data.message;
|
||||||
if (isCommentOpSuccess(response)) {
|
|
||||||
// all good
|
|
||||||
return;
|
|
||||||
} else if (response.data) {
|
|
||||||
msg = response.data.message;
|
|
||||||
} else {
|
} else {
|
||||||
msg = trans(msgKey);
|
return trans('errors.comment_add');
|
||||||
}
|
|
||||||
if (msg) {
|
|
||||||
events.emit('success', msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ return [
|
|||||||
// Comments
|
// Comments
|
||||||
'comment_list' => 'An error occurred while fetching the comments.',
|
'comment_list' => 'An error occurred while fetching the comments.',
|
||||||
'cannot_add_comment_to_draft' => 'You cannot add comments to a draft.',
|
'cannot_add_comment_to_draft' => 'You cannot add comments to a draft.',
|
||||||
'comment_add' => 'An error occurred while adding the comment.',
|
'comment_add' => 'An error occurred while adding / updating the comment.',
|
||||||
'comment_delete' => 'An error occurred while deleting the comment.',
|
'comment_delete' => 'An error occurred while deleting the comment.',
|
||||||
'empty_comment' => 'Cannot add an empty comment.',
|
'empty_comment' => 'Cannot add an empty comment.',
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user