From f790653fcf866f9f03ad262a525cd40663265740 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Fri, 20 Dec 2024 12:36:21 +0100 Subject: [PATCH] reply comment on 360 working --- public/site/plugins/comments/routes/reply.php | 14 +++----------- public/site/plugins/comments/src/BaseComment.php | 2 +- src/components/comments/Comments.vue | 16 ++++++++++++++-- .../project/virtual-sample/DynamicView.vue | 6 ++++-- .../project/virtual-sample/Interactive360.vue | 2 +- .../project/virtual-sample/StaticView.vue | 4 +++- src/stores/api.js | 4 ++++ src/stores/dialog.js | 8 ++++++++ 8 files changed, 38 insertions(+), 18 deletions(-) diff --git a/public/site/plugins/comments/routes/reply.php b/public/site/plugins/comments/routes/reply.php index 91c9ceb..b4d2d00 100644 --- a/public/site/plugins/comments/routes/reply.php +++ b/public/site/plugins/comments/routes/reply.php @@ -9,19 +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()); foreach ($comments as &$comment) { @@ -36,7 +28,7 @@ return [ "parent" => $comment ], "position" => [ - "pageIndex" => $data->position->pageIndex, + "pageIndex" => $data->position->pageIndex ?? null, ], "date" => (string) $data->date, "text" => $data->text, diff --git a/public/site/plugins/comments/src/BaseComment.php b/public/site/plugins/comments/src/BaseComment.php index 407697c..d1c9330 100644 --- a/public/site/plugins/comments/src/BaseComment.php +++ b/public/site/plugins/comments/src/BaseComment.php @@ -11,7 +11,7 @@ class BaseComment { protected string $text; protected string $date; protected string $id; - protected Position $position; + protected ?Position $position = null; public function __construct($data) { $this->location = new Location($data["location"]); diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index ee39fb5..ef5fe91 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -121,7 +121,9 @@ dayjs.locale("fr"); const { user } = useUserStore(); const { page } = usePageStore(); const dialog = useDialogStore(); -const { comments, openedFile, draftComment } = storeToRefs(useDialogStore()); +const { comments, openedFile, draftComment, activeTracks } = storeToRefs( + useDialogStore() +); const api = useApiStore(); const openedComment = ref(null); @@ -170,7 +172,7 @@ function handleSubmit(event = null) { const date = dayjs().format(); const newComment = { dialogUri: route.fullPath, - fileName: openedFile ? openedFile.value.name : false, + fileName: openedFile.value ? openedFile.value.name : false, userUuid: user.uuid, text: draftComment.value.text, date, @@ -192,6 +194,10 @@ function handleSubmit(event = null) { async function replyComment(newComment) { newComment.parentId = openedComment.value.id; + const matchFileParentUri = openedComment.value.location.file.url.match( + /projects\/.*?(?=\/[^/]+\/[^/]+$)/ + ); + newComment.fileParentUri = matchFileParentUri ? matchFileParentUri[0] : null; const newFile = await api.replyComment(newComment); resetDraftComment(); isAddOpen.value = false; @@ -292,6 +298,12 @@ function prepareDraftCommentInImage(event) { function openComment(comment) { openedComment.value = comment; + + if (activeTracks?.value.length === 1) { + openedFile.value = activeTracks.value[0].files.find( + (file) => file.uuid === openedComment.value.location.file.uuid + ); + } } diff --git a/src/components/project/virtual-sample/DynamicView.vue b/src/components/project/virtual-sample/DynamicView.vue index 7531262..6058079 100644 --- a/src/components/project/virtual-sample/DynamicView.vue +++ b/src/components/project/virtual-sample/DynamicView.vue @@ -53,7 +53,9 @@ import Interactive360 from "./Interactive360.vue"; import { useDialogStore } from "../../../stores/dialog"; const { page } = storeToRefs(usePageStore()); -const { isCommentsOpen, isCommentPanelEnabled } = storeToRefs(useDialogStore()); +const { isCommentsOpen, isCommentPanelEnabled, activeTracks } = storeToRefs( + useDialogStore() +); const tracks = computed( () => @@ -75,7 +77,7 @@ watch(isCompareModeEnabled, (newValue) => { } }); -const activeTracks = ref([tracks.value[0]]); +activeTracks.value = [tracks.value[0]]; function getFrontViewUrl(track) { if (track.files.length > 1) { diff --git a/src/components/project/virtual-sample/Interactive360.vue b/src/components/project/virtual-sample/Interactive360.vue index 63014e9..dc936dd 100644 --- a/src/components/project/virtual-sample/Interactive360.vue +++ b/src/components/project/virtual-sample/Interactive360.vue @@ -5,7 +5,7 @@ class="drag-zone" :class="{ grabbing: isDragToRotateEnabled }" > - +
{ diff --git a/src/stores/api.js b/src/stores/api.js index 17f483f..73e068e 100644 --- a/src/stores/api.js +++ b/src/stores/api.js @@ -127,6 +127,8 @@ export const useApiStore = defineStore("api", () => { body: JSON.stringify(comment), }; + console.log("Commentaire à enregistrer :", comment); + try { const response = await fetch("/create-comment.json", headers); if (!response.ok) { @@ -172,6 +174,8 @@ export const useApiStore = defineStore("api", () => { body: JSON.stringify(comment), }; + console.log("Réponse à enregistrer :", comment); + try { const response = await fetch("/reply-comment.json", headers); if (!response.ok) { diff --git a/src/stores/dialog.js b/src/stores/dialog.js index 151ae11..1b5abd9 100644 --- a/src/stores/dialog.js +++ b/src/stores/dialog.js @@ -5,8 +5,14 @@ import { useRoute } from "vue-router"; export const useDialogStore = defineStore("dialog", () => { const content = ref(null); const openedFile = ref(null); + const activeTracks = ref(null); const comments = computed(() => { + if (activeTracks.value?.length > 0) { + return activeTracks.value[0].files.flatMap((file) => + file.comments ? file.comments : [] + ); + } return openedFile.value.comments; }); @@ -81,6 +87,7 @@ export const useDialogStore = defineStore("dialog", () => { function setCommentMarkers() { if (!comments.value) return; comments.value.forEach((comment) => { + if (comment.location.file.uuid !== openedFile.value.uuid) return; const bubble = document.createElement("a"); bubble.classList.add("comment-marker"); @@ -129,6 +136,7 @@ export const useDialogStore = defineStore("dialog", () => { return { content, + activeTracks, openedFile, comments, draftComment,