From fb36329556a77e11f833546e605c3a537c13e605 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Tue, 29 Oct 2024 11:12:57 +0100 Subject: [PATCH] refactor comment system into comments plugin --- ...-bureaux-artistiquement-consideree.pdf.txt | 106 ++++++------------ public/site/config/config.php | 1 - public/site/plugins/comments/index.php | 9 ++ .../comments/routes/create.php} | 19 +++- .../site/plugins/comments/routes/delete.php | 25 +++++ .../site/plugins/comments/routes/update.php | 28 +++++ src/components/comments/Comments.vue | 45 ++++---- src/stores/api.js | 2 +- 8 files changed, 134 insertions(+), 101 deletions(-) create mode 100644 public/site/plugins/comments/index.php rename public/site/{config/routes/add-comment.php => plugins/comments/routes/create.php} (60%) create mode 100644 public/site/plugins/comments/routes/delete.php create mode 100644 public/site/plugins/comments/routes/update.php diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt index 3a78880..d3f57a4 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt @@ -12,75 +12,37 @@ Template: document Comments: -1: - m2t7307h: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: Un commentaire - username: Adrien Payet - date: 2024-10-28T16:49:51+01:00 - id: m2t7307h - m2t76m4t: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: Autre commentaire - username: Utilisateur Dior - date: 2024-10-28T16:52:39+01:00 - id: m2t76m4t - m2t7pg5m: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: Nouveau commentaire - username: Adrien Payet - date: 2024-10-28T17:07:18+01:00 - id: m2t7pg5m - m2t82m8c: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: test - username: Adrien Payet - date: 2024-10-28T17:17:32+01:00 - id: m2t82m8c - m2t83fp2: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: tt - username: Adrien Payet - date: 2024-10-28T17:18:11+01:00 - id: m2t83fp2 - m2t83syr: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: test - username: Adrien Payet - date: 2024-10-28T17:18:28+01:00 - id: m2t83syr - m2t85i0w: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: test - username: Adrien Payet - date: 2024-10-28T17:19:47+01:00 - id: m2t85i0w - m2t8ayc5: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: test - username: Adrien Payet - date: 2024-10-28T17:24:01+01:00 - id: m2t8ayc5 - m2t9dyjc: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 1 - text: test 89 - username: Utilisateur Dior - date: 2024-10-28T17:54:21+01:00 - id: m2t9dyjc -2: - m2t8bv59: - fileUuid: file://s0lNtRA0Z7ybTCWG - page: 2 - text: test 40 - username: Adrien Payet - date: 2024-10-28T17:24:44+01:00 - id: m2t8bv59 \ No newline at end of file +m2u905al: + pageUri: > + projects/miss-dior-blooming-bouquet/client-brief + fileUuid: file://s0lNtRA0Z7ybTCWG + filePageTarget: 1 + position: + x: null + y: null + replies: [ ] + text: com1 + user: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + date: 2024-10-29T10:31:23+01:00 + id: m2u905al +m2u955a7: + pageUri: > + projects/miss-dior-blooming-bouquet/client-brief + fileUuid: file://s0lNtRA0Z7ybTCWG + filePageTarget: 1 + position: + x: null + y: null + replies: [ ] + text: come2 + user: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + date: 2024-10-29T10:35:16+01:00 + id: m2u955a7 \ No newline at end of file diff --git a/public/site/config/config.php b/public/site/config/config.php index 12b34df..e4d6a71 100644 --- a/public/site/config/config.php +++ b/public/site/config/config.php @@ -26,7 +26,6 @@ return [ require(__DIR__ . '/routes/save-file.php'), require(__DIR__ . '/routes/remove-file.php'), require(__DIR__ . '/routes/upload-pdf.php'), - require(__DIR__ . '/routes/add-comment.php'), require(__DIR__ . '/routes/read-notification.php'), ], 'hooks' => [ diff --git a/public/site/plugins/comments/index.php b/public/site/plugins/comments/index.php new file mode 100644 index 0000000..fdb6655 --- /dev/null +++ b/public/site/plugins/comments/index.php @@ -0,0 +1,9 @@ + [ + require(__DIR__ . '/routes/create.php'), + require(__DIR__ . '/routes/update.php'), + require(__DIR__ . '/routes/delete.php'), + ] +]); diff --git a/public/site/config/routes/add-comment.php b/public/site/plugins/comments/routes/create.php similarity index 60% rename from public/site/config/routes/add-comment.php rename to public/site/plugins/comments/routes/create.php index 716d481..282fbe7 100644 --- a/public/site/config/routes/add-comment.php +++ b/public/site/plugins/comments/routes/create.php @@ -1,7 +1,7 @@ '(:all)add-comment.json', + 'pattern' => '(:all)create-comment.json', 'method' => 'POST', 'action' => function () { $json = file_get_contents('php://input'); @@ -15,15 +15,26 @@ return [ $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); $newComment = [ + 'pageUri' => $data->pageUri, 'fileUuid' => (string) $file->uuid(), - 'page' => $data->targetPage, + 'filePageTarget' => $data->targetPage, + 'position' => [ + 'x' => null, + 'y' => null + ], + 'replies' => [], 'text' => $data->text, - 'username' => $user->name()->isNotEmpty() ? (string) $user->name() : (string) $user->email(), + 'user' => [ + 'name' => (string) $user->name(), + 'email' => (string) $user->email(), + 'uuid' => (string) $user->uuid(), + 'role' => (string) $user->role() + ], 'date' => (string) $data->date, 'id' => $data->id, ]; - $comments[$data->targetPage][$data->id] = $newComment; + $comments[$data->id] = $newComment; $newFile = $file->update([ 'comments' => $comments diff --git a/public/site/plugins/comments/routes/delete.php b/public/site/plugins/comments/routes/delete.php new file mode 100644 index 0000000..9c5bced --- /dev/null +++ b/public/site/plugins/comments/routes/delete.php @@ -0,0 +1,25 @@ + '(:all)delete-comment.json', + 'method' => 'POST', + 'action' => function () { + $json = file_get_contents('php://input'); + $data = json_decode($json); + + $page = page($data->pageUri); + $file = $page->file($data->fileName); + $user = kirby()->user($data->userUuid); + + + $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); + + unset($comments[$data->id] ); + + $newFile = $file->update([ + 'comments' => $comments + ]); + + return getFileData($newFile); + } +]; \ No newline at end of file diff --git a/public/site/plugins/comments/routes/update.php b/public/site/plugins/comments/routes/update.php new file mode 100644 index 0000000..db611e5 --- /dev/null +++ b/public/site/plugins/comments/routes/update.php @@ -0,0 +1,28 @@ + '(:all)create-comment.json', + 'method' => 'POST', + 'action' => function () { + $json = file_get_contents('php://input'); + $data = json_decode($json); + + $page = page($data->pageUri); + $file = $page->file($data->fileName); + $user = kirby()->user($data->userUuid); + + + $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); + + $comments[$data->id]['text'] = $data->text; + $comments[$data->id]['date'] = $data->date; + + $newFile = $file->update([ + 'comments' => $comments + ]); + + // $user->sendNotification('comments', $comments[$data->id]); + + return getFileData($newFile); + } +]; \ No newline at end of file diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 296e43a..317cf92 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -2,32 +2,30 @@