From 9a2ef7ef44d75c6d68499dd554ebca31a1e68401 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Fri, 16 Jun 2023 13:08:04 +0100 Subject: [PATCH] Comments: Added read-only listing into page editor --- app/Entities/Controllers/PageController.php | 14 ++++------- app/Entities/Tools/PageEditorData.php | 17 ++++++-------- lang/en/entities.php | 1 + resources/sass/_components.scss | 23 +++++++++++++++++++ resources/views/comments/comment.blade.php | 21 ++++++++++------- resources/views/comments/comments.blade.php | 2 +- .../pages/parts/editor-toolbox.blade.php | 8 ++++++- .../pages/parts/toolbox-comments.blade.php | 15 ++++++++++++ tests/Entity/CommentTest.php | 10 ++++++++ 9 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 resources/views/pages/parts/toolbox-comments.blade.php diff --git a/app/Entities/Controllers/PageController.php b/app/Entities/Controllers/PageController.php index 3187e6486..e96d41bb1 100644 --- a/app/Entities/Controllers/PageController.php +++ b/app/Entities/Controllers/PageController.php @@ -24,16 +24,10 @@ use Throwable; class PageController extends Controller { - protected PageRepo $pageRepo; - protected ReferenceFetcher $referenceFetcher; - - /** - * PageController constructor. - */ - public function __construct(PageRepo $pageRepo, ReferenceFetcher $referenceFetcher) - { - $this->pageRepo = $pageRepo; - $this->referenceFetcher = $referenceFetcher; + public function __construct( + protected PageRepo $pageRepo, + protected ReferenceFetcher $referenceFetcher + ) { } /** diff --git a/app/Entities/Tools/PageEditorData.php b/app/Entities/Tools/PageEditorData.php index 2342081bb..3c7c9e2ea 100644 --- a/app/Entities/Tools/PageEditorData.php +++ b/app/Entities/Tools/PageEditorData.php @@ -2,6 +2,7 @@ namespace BookStack\Entities\Tools; +use BookStack\Activity\Tools\CommentTree; use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\PageRepo; use BookStack\Entities\Tools\Markdown\HtmlToMarkdown; @@ -9,19 +10,14 @@ use BookStack\Entities\Tools\Markdown\MarkdownToHtml; class PageEditorData { - protected Page $page; - protected PageRepo $pageRepo; - protected string $requestedEditor; - protected array $viewData; protected array $warnings; - public function __construct(Page $page, PageRepo $pageRepo, string $requestedEditor) - { - $this->page = $page; - $this->pageRepo = $pageRepo; - $this->requestedEditor = $requestedEditor; - + public function __construct( + protected Page $page, + protected PageRepo $pageRepo, + protected string $requestedEditor + ) { $this->viewData = $this->build(); } @@ -69,6 +65,7 @@ class PageEditorData 'draftsEnabled' => $draftsEnabled, 'templates' => $templates, 'editor' => $editorType, + 'comments' => new CommentTree($page), ]; } diff --git a/lang/en/entities.php b/lang/en/entities.php index 5a148e1a2..8cd7e925f 100644 --- a/lang/en/entities.php +++ b/lang/en/entities.php @@ -371,6 +371,7 @@ return [ 'comment_updated_success' => 'Comment updated', 'comment_delete_confirm' => 'Are you sure you want to delete this comment?', 'comment_in_reply_to' => 'In reply to :commentId', + 'comment_editor_explain' => 'Here are the comments that have been left on this page. Comments can be added & managed when viewing the saved page.', // Revision 'revision_delete_confirm' => 'Are you sure you want to delete this revision?', diff --git a/resources/sass/_components.scss b/resources/sass/_components.scss index dab74341a..e6c0fdcd1 100644 --- a/resources/sass/_components.scss +++ b/resources/sass/_components.scss @@ -676,6 +676,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { @include lightDark(background-color, #FFF, #222); .content { font-size: 0.666em; + padding: $-m $-s; p, ul, ol { font-size: $fs-m; margin: .5em 0; @@ -700,6 +701,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { .comment-box .header { border-bottom: 1px solid #DDD; + padding: $-s; @include lightDark(border-color, #DDD, #000); button { font-size: .8rem; @@ -710,6 +712,9 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { .text-muted { color: #999; } + .meta a, .meta span { + white-space: nowrap; + } .right-meta .text-muted { opacity: .8; } @@ -735,6 +740,24 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { display: block; } +.comment-container-compact .comment-box { + .meta { + font-size: 0.8rem; + } + .header { + padding: $-xs; + } + .right-meta { + display: none; + } + .content { + padding: $-xs $-s; + } +} +.comment-container-compact .comment-thread-indicator { + width: $-m; +} + #tag-manager .drag-card { max-width: 500px; } diff --git a/resources/views/comments/comment.blade.php b/resources/views/comments/comment.blade.php index 04468b83c..8933e2e6a 100644 --- a/resources/views/comments/comment.blade.php +++ b/resources/views/comments/comment.blade.php @@ -1,4 +1,4 @@ -
-
-
-
+
+
+ @if ($comment->createdBy) +
+ {{ $comment->createdBy->name }} +
+ @endif +
@if ($comment->createdBy) - {{ $comment->createdBy->name }} -   {{ $comment->createdBy->getShortName(16) }} @else {{ trans('common.deleted_user') }} @@ -25,6 +28,7 @@ @endif
+ @if(!$readOnly && (userCan('comment-create-all') || userCan('comment-update', $comment) || userCan('comment-delete', $comment)))
@if(userCan('comment-create-all')) @@ -50,6 +54,7 @@  • 
+ @endif @@ -58,7 +63,7 @@
-
+
@if ($comment->parent_id)

@icon('reply'){{ trans('entities.comment_in_reply_to', ['commentId' => '#' . $comment->parent_id]) }} @@ -67,7 +72,7 @@ {!! $comment->html !!}

- @if(userCan('comment-update', $comment)) + @if(!$readOnly && userCan('comment-update', $comment))
diff --git a/resources/views/pages/parts/toolbox-comments.blade.php b/resources/views/pages/parts/toolbox-comments.blade.php new file mode 100644 index 000000000..d632b85c6 --- /dev/null +++ b/resources/views/pages/parts/toolbox-comments.blade.php @@ -0,0 +1,15 @@ +
+

{{ trans('entities.comments') }}

+ +
+

+ {{ trans('entities.comment_editor_explain') }} +

+ @foreach($comments->get() as $branch) + @include('comments.comment-branch', ['branch' => $branch, 'readOnly' => true]) + @endforeach + @if($comments->empty()) +

{{ trans('common.no_items') }}

+ @endif +
+
\ No newline at end of file diff --git a/tests/Entity/CommentTest.php b/tests/Entity/CommentTest.php index a04933ada..b3e9f3cd0 100644 --- a/tests/Entity/CommentTest.php +++ b/tests/Entity/CommentTest.php @@ -135,4 +135,14 @@ class CommentTest extends TestCase $respHtml->assertElementCount('.comment-branch', 4); $respHtml->assertElementContains('.comment-branch .comment-branch', 'My nested comment'); } + + public function test_comments_are_visible_in_the_page_editor() + { + $page = $this->entities->page(); + + $this->asAdmin()->postJson("/comment/$page->id", ['text' => 'My great comment to see in the editor']); + + $respHtml = $this->withHtml($this->get($page->getUrl('/edit'))); + $respHtml->assertElementContains('.comment-box .content', 'My great comment to see in the editor'); + } }