From 4daaa3dc8896b1f847acbb6346000070e4af0a88 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Thu, 19 Dec 2024 17:11:46 +0100 Subject: [PATCH] comment 360 working --- .../4_virtual-sample/1_piste-1/0_6.png.txt | 33 +++++++ .../adrien-payet_-az60.pdf.txt | 4 +- public/site/blueprints/files/default.yml | 3 + .../site/plugins/comments/routes/create.php | 16 +--- public/site/plugins/helpers/index.php | 2 +- src/components/comments/Comments.vue | 4 + src/components/project/PdfViewer.vue | 69 -------------- src/stores/dialog.js | 94 +++++++++++++++++-- 8 files changed, 134 insertions(+), 91 deletions(-) create mode 100644 public/site/blueprints/files/default.yml diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt index 057fd9c..9e7b110 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt @@ -1 +1,34 @@ +Comments: + +- + location: + page: + uri: > + projects/miss-dior-blooming-bouquet/virtual-sample/piste-1 + title: Piste 1 + project: + title: Miss Dior Blooming Bouquet + uri: projects/miss-dior-blooming-bouquet + dialogUri: > + /projects/miss-dior-blooming-bouquet?dialog=virtual-sample + file: + uuid: file://J9q2ceZL2aW19oEU + url: > + http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/virtual-sample/piste-1/f26b2c223b-1733765560/0_6.png + position: + x: '50.119047619048' + y: '42.563482466747' + text: test + author: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + date: 2024-12-19T16:49:15+01:00 + id: 4b311fe6-a6e4-486f-a9ce-b8820a234e2e + type: comment + replies: [ ] + +---- + Uuid: J9q2ceZL2aW19oEU \ No newline at end of file diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt index d39527e..ebb87db 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt @@ -1,5 +1,5 @@ -Uuid: WrFkfiMVZuxwdYad +Comments: ---- -Comments: \ No newline at end of file +Uuid: WrFkfiMVZuxwdYad \ No newline at end of file diff --git a/public/site/blueprints/files/default.yml b/public/site/blueprints/files/default.yml new file mode 100644 index 0000000..39d62c7 --- /dev/null +++ b/public/site/blueprints/files/default.yml @@ -0,0 +1,3 @@ +fields: + comments: + type: hidden diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 525dba9..69f18be 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -9,17 +9,11 @@ return [ $json = file_get_contents('php://input'); $data = json_decode($json); - $parsedUrl = parse_url($data->dialogUri); - $query = $parsedUrl['query'] ?? null; - parse_str($query, $queryParams); - $stepSlug = $queryParams['dialog'] ?? null; - - $targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path']; - - $project = page($parsedUrl['path']); - $page = page($targetPageUri); + $page = page($data->fileParentUri); + $project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent(); $file = $page->file($data->fileName); $user = kirby()->user($data->userUuid); + $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); @@ -41,13 +35,13 @@ return [ "type" => "comment", ]; - if ($data->position->pageIndex) { + if (isset($data->position->pageIndex)) { $commentData["position"]["pageIndex"] = $data->position->pageIndex; } $newComment = new Comment($commentData); - $comments[] = $newComment->toArray(); + $comments[] = $newComment->toArray(); $newFile = $file->update([ 'comments' => $comments diff --git a/public/site/plugins/helpers/index.php b/public/site/plugins/helpers/index.php index 34d7b0b..74c897d 100644 --- a/public/site/plugins/helpers/index.php +++ b/public/site/plugins/helpers/index.php @@ -19,7 +19,7 @@ function getFileData($file) { $data['tags'] = $file->tags()->split(); }; - if($file->extension() == "pdf") { + if($file->comments()->exists()) { $data['comments'] = $file->comments()->exists() && $file->comments() ? Data::decode($file->comments()->value(), 'yaml') : []; $data['cover'] = $file->cover()->exists() && $file->cover()->isNotEmpty() ? $file->cover()->toFile()->resize(576)->url() : false; } diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 1332104..ee39fb5 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -202,6 +202,10 @@ async function replyComment(newComment) { } async function addComment(newComment) { + const matchFileParentUri = openedFile.value.url.match( + /projects\/.*?(?=\/[^/]+\/[^/]+$)/ + ); + newComment.fileParentUri = matchFileParentUri ? matchFileParentUri[0] : null; const newFile = await api.addComment(newComment); resetDraftComment(); isAddOpen.value = false; diff --git a/src/components/project/PdfViewer.vue b/src/components/project/PdfViewer.vue index 53de449..82c872c 100644 --- a/src/components/project/PdfViewer.vue +++ b/src/components/project/PdfViewer.vue @@ -36,35 +36,6 @@ const { openedFile, isCommentsOpen, comments, draftComment } = storeToRefs( useDialogStore() ); -const isViewerDisabled = ref(false); - -watch(openedFile, () => { - removeCommentMarkers(); - setCommentMarkers(); -}); - -watch(isCommentsOpen, (newVal) => { - if (newVal) { - setCommentMarkers(); - } else { - removeCommentMarkers(); - } -}); - -watch(openedFile, (newVal, oldVal) => { - if (newVal.url === oldVal.url) return; - - isViewerDisabled.value = true; - - setTimeout(() => { - isViewerDisabled.value = false; - removeCommentMarkers(); - if (newVal.comments) { - setCommentMarkers(); - } - }, 100); -}); - const currentPageIndex = ref(1); // Functions @@ -107,46 +78,6 @@ const onPdfLoaded = () => { observePages(); }; - -function setCommentMarkers() { - if (!comments.value) return; - comments.value.forEach((comment) => { - const bubble = document.createElement("a"); - - bubble.classList.add("comment-marker"); - bubble.style.left = comment.position.x + "%"; - bubble.style.top = comment.position.y + "%"; - bubble.href = "#comment-" + comment.id; - - const container = document.querySelector( - `.vpv-page-inner-container[aria-label="page ${comment.position.pageIndex}"] .page-inner-container` - ); - - console.log(container); - - container.appendChild(bubble); - - setTimeout(() => { - bubble.addEventListener("mouseenter", () => highlight(comment)); - bubble.addEventListener("mouseleave", () => unhighlight(comment)); - }, 100); - }); -} - -function highlight(comment) { - const target = document.querySelector("#comment-" + comment.id); - target.classList.add("highlight"); -} -function unhighlight(comment) { - const target = document.querySelector("#comment-" + comment.id); - target.classList.remove("highlight"); -} - -function removeCommentMarkers() { - document.querySelectorAll(".comment-marker").forEach((bubble) => { - bubble.parentNode.removeChild(bubble); - }); -}