mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-18 18:38:44 +00:00
Comments: Updated to show form in expected location
Includes a change of create response to use a branch as a template.
This commit is contained in:
parent
154924cc0c
commit
3b46b92bb9
7 changed files with 68 additions and 51 deletions
app/Activity/Controllers
resources
js/components
sass
views/comments
|
@ -10,11 +10,9 @@ use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class CommentController extends Controller
|
class CommentController extends Controller
|
||||||
{
|
{
|
||||||
protected $commentRepo;
|
public function __construct(
|
||||||
|
protected CommentRepo $commentRepo
|
||||||
public function __construct(CommentRepo $commentRepo)
|
) {
|
||||||
{
|
|
||||||
$this->commentRepo = $commentRepo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +41,12 @@ class CommentController extends Controller
|
||||||
$this->checkPermission('comment-create-all');
|
$this->checkPermission('comment-create-all');
|
||||||
$comment = $this->commentRepo->create($page, $request->get('text'), $request->get('parent_id'));
|
$comment = $this->commentRepo->create($page, $request->get('text'), $request->get('parent_id'));
|
||||||
|
|
||||||
return view('comments.comment', ['comment' => $comment]);
|
return view('comments.comment-branch', [
|
||||||
|
'branch' => [
|
||||||
|
'comment' => $comment,
|
||||||
|
'children' => [],
|
||||||
|
]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,10 @@ export class PageComment extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
setupListeners() {
|
setupListeners() {
|
||||||
this.replyButton.addEventListener('click', () => this.$emit('reply', {id: this.commentLocalId}));
|
this.replyButton.addEventListener('click', () => this.$emit('reply', {
|
||||||
|
id: this.commentLocalId,
|
||||||
|
element: this.container,
|
||||||
|
}));
|
||||||
this.editButton.addEventListener('click', this.startEdit.bind(this));
|
this.editButton.addEventListener('click', this.startEdit.bind(this));
|
||||||
this.deleteButton.addEventListener('click', this.delete.bind(this));
|
this.deleteButton.addEventListener('click', this.delete.bind(this));
|
||||||
this.form.addEventListener('submit', this.update.bind(this));
|
this.form.addEventListener('submit', this.update.bind(this));
|
||||||
|
|
|
@ -41,7 +41,7 @@ export class PageComments extends Component {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.elem.addEventListener('page-comment-reply', event => {
|
this.elem.addEventListener('page-comment-reply', event => {
|
||||||
this.setReply(event.detail.id);
|
this.setReply(event.detail.id, event.detail.element);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.form) {
|
if (this.form) {
|
||||||
|
@ -66,15 +66,16 @@ export class PageComments extends Component {
|
||||||
|
|
||||||
window.$http.post(`/comment/${this.pageId}`, reqData).then(resp => {
|
window.$http.post(`/comment/${this.pageId}`, reqData).then(resp => {
|
||||||
const newElem = htmlToDom(resp.data);
|
const newElem = htmlToDom(resp.data);
|
||||||
this.container.appendChild(newElem);
|
this.formContainer.after(newElem);
|
||||||
window.$events.success(this.createdText);
|
window.$events.success(this.createdText);
|
||||||
this.resetForm();
|
this.hideForm();
|
||||||
this.updateCount();
|
this.updateCount();
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.form.toggleAttribute('hidden', false);
|
this.form.toggleAttribute('hidden', false);
|
||||||
window.$events.showValidationErrors(err);
|
window.$events.showValidationErrors(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.form.toggleAttribute('hidden', false);
|
||||||
loading.remove();
|
loading.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,32 +86,38 @@ export class PageComments extends Component {
|
||||||
|
|
||||||
resetForm() {
|
resetForm() {
|
||||||
this.formInput.value = '';
|
this.formInput.value = '';
|
||||||
this.hideForm();
|
|
||||||
this.removeReplyTo();
|
this.removeReplyTo();
|
||||||
|
this.container.append(this.formContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
showForm() {
|
showForm() {
|
||||||
this.formContainer.toggleAttribute('hidden', false);
|
this.formContainer.toggleAttribute('hidden', false);
|
||||||
this.addButtonContainer.toggleAttribute('hidden', true);
|
this.addButtonContainer.toggleAttribute('hidden', true);
|
||||||
|
setTimeout(() => {
|
||||||
this.formInput.focus();
|
this.formInput.focus();
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
hideForm() {
|
hideForm() {
|
||||||
|
this.resetForm();
|
||||||
this.formContainer.toggleAttribute('hidden', true);
|
this.formContainer.toggleAttribute('hidden', true);
|
||||||
if (this.getCommentCount() > 0) {
|
if (this.getCommentCount() > 0) {
|
||||||
this.elem.appendChild(this.addButtonContainer);
|
this.elem.append(this.addButtonContainer);
|
||||||
} else {
|
} else {
|
||||||
this.commentCountBar.appendChild(this.addButtonContainer);
|
this.commentCountBar.append(this.addButtonContainer);
|
||||||
}
|
}
|
||||||
this.addButtonContainer.toggleAttribute('hidden', false);
|
this.addButtonContainer.toggleAttribute('hidden', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommentCount() {
|
getCommentCount() {
|
||||||
return this.container.querySelectorAll('[compontent="page-comment"]').length;
|
return this.container.querySelectorAll('[component="page-comment"]').length;
|
||||||
}
|
}
|
||||||
|
|
||||||
setReply(commentLocalId) {
|
setReply(commentLocalId, commentElement) {
|
||||||
|
const targetFormLocation = commentElement.closest('.comment-branch').querySelector('.comment-branch-children');
|
||||||
this.showForm();
|
this.showForm();
|
||||||
|
targetFormLocation.append(this.formContainer);
|
||||||
|
this.formContainer.scrollIntoView({behavior: 'smooth', block: 'nearest'});
|
||||||
this.parentId = commentLocalId;
|
this.parentId = commentLocalId;
|
||||||
this.replyToRow.toggleAttribute('hidden', false);
|
this.replyToRow.toggleAttribute('hidden', false);
|
||||||
const replyLink = this.replyToRow.querySelector('a');
|
const replyLink = this.replyToRow.querySelector('a');
|
||||||
|
|
|
@ -682,6 +682,9 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
|
||||||
&:hover .actions, &:focus-within .actions {
|
&:hover .actions, &:focus-within .actions {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
.actions button:focus {
|
||||||
|
outline: 1px dotted var(--color-primary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment-box .header {
|
.comment-box .header {
|
||||||
|
@ -709,6 +712,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
|
||||||
@include lightDark(border-color, #DDD, #444);
|
@include lightDark(border-color, #DDD, #444);
|
||||||
margin-inline-start: $-xs;
|
margin-inline-start: $-xs;
|
||||||
width: $-l;
|
width: $-l;
|
||||||
|
height: calc(100% - $-m);
|
||||||
}
|
}
|
||||||
|
|
||||||
#tag-manager .drag-card {
|
#tag-manager .drag-card {
|
||||||
|
|
|
@ -2,16 +2,14 @@
|
||||||
<div class="mb-m">
|
<div class="mb-m">
|
||||||
@include('comments.comment', ['comment' => $branch['comment']])
|
@include('comments.comment', ['comment' => $branch['comment']])
|
||||||
</div>
|
</div>
|
||||||
@if(count($branch['children']) > 0)
|
|
||||||
<div class="flex-container-row">
|
<div class="flex-container-row">
|
||||||
<div class="pb-m">
|
<div class="comment-thread-indicator-parent">
|
||||||
<div class="comment-thread-indicator fill-height"></div>
|
<div class="comment-thread-indicator"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex">
|
<div class="comment-branch-children flex">
|
||||||
@foreach($branch['children'] as $childBranch)
|
@foreach($branch['children'] as $childBranch)
|
||||||
@include('comments.comment-branch', ['branch' => $childBranch])
|
@include('comments.comment-branch', ['branch' => $childBranch])
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
|
@ -28,14 +28,14 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="actions text-right">
|
<div class="actions text-right">
|
||||||
@if(userCan('comment-update', $comment))
|
@if(userCan('comment-update', $comment))
|
||||||
<button refs="page-comment@edit-button" type="button" class="text-button" aria-label="{{ trans('common.edit') }}" title="{{ trans('common.edit') }}">@icon('edit')</button>
|
<button refs="page-comment@edit-button" type="button" class="text-button icon p-xs" aria-label="{{ trans('common.edit') }}" title="{{ trans('common.edit') }}">@icon('edit')</button>
|
||||||
@endif
|
@endif
|
||||||
@if(userCan('comment-create-all'))
|
@if(userCan('comment-create-all'))
|
||||||
<button refs="page-comment@reply-button" type="button" class="text-button" aria-label="{{ trans('common.reply') }}" title="{{ trans('common.reply') }}">@icon('reply')</button>
|
<button refs="page-comment@reply-button" type="button" class="text-button icon p-xs" aria-label="{{ trans('common.reply') }}" title="{{ trans('common.reply') }}">@icon('reply')</button>
|
||||||
@endif
|
@endif
|
||||||
@if(userCan('comment-delete', $comment))
|
@if(userCan('comment-delete', $comment))
|
||||||
<div component="dropdown" class="dropdown-container">
|
<div component="dropdown" class="dropdown-container">
|
||||||
<button type="button" refs="dropdown@toggle" aria-haspopup="true" aria-expanded="false" class="text-button" title="{{ trans('common.delete') }}">@icon('delete')</button>
|
<button type="button" refs="dropdown@toggle" aria-haspopup="true" aria-expanded="false" class="text-button icon p-xs" title="{{ trans('common.delete') }}">@icon('delete')</button>
|
||||||
<ul refs="dropdown@menu" class="dropdown-menu" role="menu">
|
<ul refs="dropdown@menu" class="dropdown-menu" role="menu">
|
||||||
<li class="px-m text-small text-muted pb-s">{{trans('entities.comment_delete_confirm')}}</li>
|
<li class="px-m text-small text-muted pb-s">{{trans('entities.comment_delete_confirm')}}</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<div refs="page-comments@form-container" hidden class="comment-box">
|
<div refs="page-comments@form-container" hidden class="comment-branch mb-m">
|
||||||
|
<div class="comment-box">
|
||||||
|
|
||||||
<div class="header p-s">{{ trans('entities.comment_new') }}</div>
|
<div class="header p-s">{{ trans('entities.comment_new') }}</div>
|
||||||
<div refs="page-comments@reply-to-row" hidden class="primary-background-light text-muted px-s py-xs mb-s">
|
<div refs="page-comments@reply-to-row" hidden class="primary-background-light text-muted px-s py-xs mb-s">
|
||||||
|
@ -28,3 +29,4 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
Loading…
Add table
Reference in a new issue