From 37b0175941c2e6c279a13755f6fe6c45b72752e5 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Sun, 9 Feb 2025 10:07:15 +0100 Subject: [PATCH] Revert "kaban : fix comments count for virtual sample step" This reverts commit 57b5ee394998ddbbc5f604736023c3d06586fb77. --- public/site/blueprints/users/client.yml | 1 + .../site/plugins/comments/routes/create.php | 54 +++++++++---------- .../site/plugins/comments/routes/delete.php | 41 +++++++------- src/components/project/cards/Images.vue | 33 ++---------- 4 files changed, 51 insertions(+), 78 deletions(-) diff --git a/public/site/blueprints/users/client.yml b/public/site/blueprints/users/client.yml index 9476739..fbdf2e6 100644 --- a/public/site/blueprints/users/client.yml +++ b/public/site/blueprints/users/client.yml @@ -12,6 +12,7 @@ permissions: inspirations: false materials: false creations: false + pages: false user: changeRole: false delete: false diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 3068d0d..794a454 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -4,58 +4,56 @@ use adrienpayet\comments\Comment; return [ 'pattern' => '(:all)create-comment.json', - 'method' => 'POST', + 'method' => 'POST', 'action' => function () { $json = file_get_contents('php://input'); $data = json_decode($json); - // kirby()->impersonate('kirby'); - $page = page($data->fileParentUri); - $project = $page->parent()->template() == 'project' ? $page->parent() : $page->parent()->parent(); + $project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent(); $file = $page->file($data->fileName); - $user = kirby()->user($data->userUuid); - + $user = kirby()->user($data->userUuid); + $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); $commentData = [ - 'location' => [ - 'page' => $page, - 'project' => $project, - 'file' => $file, + "location" => [ + "page" => $page, + "project" => $project, + "file" => $file ], - 'position' => [ - 'x' => $data->position->x, - 'y' => $data->position->y, + "position" => [ + "x" => $data->position->x, + "y" => $data->position->y ], - 'date' => (string) $data->date, - 'text' => $data->text, - 'author' => kirby()->user(), - 'id' => Str::uuid(), - 'type' => 'comment', + "date" => (string) $data->date, + "text" => $data->text, + "author" => kirby()->user(), + "id" => Str::uuid(), + "type" => "comment", ]; if (isset($data->position->pageIndex)) { - $commentData['position']['pageIndex'] = $data->position->pageIndex; + $commentData["position"]["pageIndex"] = $data->position->pageIndex; } $newComment = new Comment($commentData); - $comments[] = $newComment->toArray(); - + $comments[] = $newComment->toArray(); + $newFile = $file->update([ - 'comments' => $comments, - ]); + 'comments' => $comments + ]); echo json_encode(getFileData($newFile)); - + try { - $project->createNotification($commentData); + $project->createNotification($commentData); } catch (\Throwable $th) { - throw new Exception($th->getMessage() . '. line ' . $th->getLine() . ' in file ' . $th->getFile(), 1); + throw new Exception($th->getMessage() . ". line " . $th->getLine() . " in file " . $th->getFile(), 1); } exit; - }, -]; + } +]; \ No newline at end of file diff --git a/public/site/plugins/comments/routes/delete.php b/public/site/plugins/comments/routes/delete.php index 8bc9e07..3146f43 100644 --- a/public/site/plugins/comments/routes/delete.php +++ b/public/site/plugins/comments/routes/delete.php @@ -2,46 +2,45 @@ return [ 'pattern' => '(:all)delete-comment.json', - 'method' => 'POST', + 'method' => 'POST', 'action' => function () { $json = file_get_contents('php://input'); $data = json_decode($json); - // kirby()->impersonate('kirby'); $page = page($data->location->page->uri); - + $file = $page->file($data->location->file->uuid); $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); $isReply = $data->location->parent->id ?? false; foreach ($comments as $key => &$comment) { - if ($isReply) { - if ($comment['id'] === $data->location->parent->id) { - foreach ($comment['replies'] as $replyKey => $reply) { - if ($reply['id'] === $data->id) { - unset($comment['replies'][$replyKey]); - $comment['replies'] = array_values($comment['replies']); - } - } - } - } else { - if ($comment['id'] === $data->id) { - unset($comments[$key]); + if ($isReply) { + if ($comment['id'] === $data->location->parent->id) { + foreach ($comment['replies'] as $replyKey => $reply) { + if ($reply['id'] === $data->id) { + unset($comment['replies'][$replyKey]); + $comment['replies'] = array_values($comment['replies']); } + } } + } else { + if ($comment['id'] === $data->id) { + unset($comments[$key]); + } + } } $comments = array_values($comments); $newFile = $file->update([ - 'comments' => $comments, + 'comments' => $comments ]); - + echo json_encode(getFileData($newFile)); - - $project = $page->parents()->findBy('template', 'project'); + + $project = $page->parents()->findBy("template", "project"); $project->deleteNotification($data->id); - + exit; - }, + } ]; diff --git a/src/components/project/cards/Images.vue b/src/components/project/cards/Images.vue index be43396..7836729 100644 --- a/src/components/project/cards/Images.vue +++ b/src/components/project/cards/Images.vue @@ -17,10 +17,12 @@
import DateTime from './DateTime.vue'; import { useDesignToLightStore } from '../../../stores/designToLight'; -import { computed } from 'vue'; const { images, step, uri } = defineProps({ images: Array, @@ -44,30 +45,4 @@ const { images, step, uri } = defineProps({ }); const { isDesignToLightStep } = useDesignToLightStore(); - -const commentsCount = computed(() => { - let count = 0; - - if (Array.isArray(step.files)) { - for (const file of step.files) { - count += file?.comments?.length || 0; - } - } else { - if (step.files?.dynamic) { - for (const track of step.files.dynamic) { - for (const file of track.files) { - count += file?.comments?.length || 0; - } - } - } - - if (step.files?.static) { - for (const element of Object.values(step.files.static)) { - count += element?.comments?.length || 0; - } - } - } - - return count; -});