From 6bffbc170711cc8fa0873e3b9089bff0df985ee6 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Wed, 23 Oct 2024 11:32:51 +0200 Subject: [PATCH] add / show comments working --- package-lock.json | 6 ++ package.json | 1 + ...-bureaux-artistiquement-consideree.pdf.txt | 29 +++++- public/site/config/config.php | 1 + public/site/config/routes/add-comment.php | 32 +++++++ public/site/plugins/helpers/index.php | 6 +- src/components/comments/Comments.vue | 89 ++++++++++++++----- src/components/project/ProjectStep.vue | 7 +- .../project/client-brief/PdfViewer.vue | 17 ++-- src/views/Project.vue | 15 ++-- 10 files changed, 163 insertions(+), 40 deletions(-) create mode 100644 public/site/config/routes/add-comment.php diff --git a/package-lock.json b/package-lock.json index c04fdef..7b4dda4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "primevue": "^4.0.6", "slugify": "^1.6.6", "three": "^0.168.0", + "uniqid": "^5.4.0", "vue": "^3.5.6", "vue-router": "^4.4.5" }, @@ -1827,6 +1828,11 @@ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", "optional": true }, + "node_modules/uniqid": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/uniqid/-/uniqid-5.4.0.tgz", + "integrity": "sha512-38JRbJ4Fj94VmnC7G/J/5n5SC7Ab46OM5iNtSstB/ko3l1b5g7ALt4qzHFgGciFkyiRNtDXtLNb+VsxtMSE77A==" + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index be7e559..a1f7162 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "primevue": "^4.0.6", "slugify": "^1.6.6", "three": "^0.168.0", + "uniqid": "^5.4.0", "vue": "^3.5.6", "vue-router": "^4.4.5" }, 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 cb27a3c..cc8a950 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 @@ -6,4 +6,31 @@ Uuid: s0lNtRA0Z7ybTCWG ---- -Template: document \ No newline at end of file +Template: document + +---- + +Comments: + +1: + m2lmqu2u: + text: test + username: Adrien Payet + date: 2024-10-23T10:46:08+02:00 + m2lo4obv: + text: nouveau commentaire + username: Adrien Payet + date: 2024-10-23T11:24:53+02:00 + m2lo6ckw: + text: Encore un autre commentaire + username: Adrien Payet + date: 2024-10-23T11:26:11+02:00 +2: + m2loaj2f: + text: Autre commentaire + username: Adrien Payet + date: 2024-10-23T11:29:26+02:00 + m2loam7s: + text: Autre commentaire + username: Adrien Payet + date: 2024-10-23T11:29:30+02:00 \ No newline at end of file diff --git a/public/site/config/config.php b/public/site/config/config.php index e15869d..2b684b6 100644 --- a/public/site/config/config.php +++ b/public/site/config/config.php @@ -26,6 +26,7 @@ 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'), ], 'hooks' => [ 'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'), diff --git a/public/site/config/routes/add-comment.php b/public/site/config/routes/add-comment.php new file mode 100644 index 0000000..0a69530 --- /dev/null +++ b/public/site/config/routes/add-comment.php @@ -0,0 +1,32 @@ + '(:all)add-comment.json', + 'method' => 'POST', + 'action' => function () { + $json = file_get_contents('php://input'); + $data = json_decode($json); + + // return json_encode($data->pageUri); + + $page = page($data->pageUri); + $file = $page->file($data->fileName); + $user = kirby()->user($data->userUuid); + + + $comments = $file->comments()->isEmpty() == true ? [] : Data::decode($file->comments()->toArray()['comments'], 'yaml'); + + $comments[$data->targetPage][$data->id] = [ + 'text' => $data->text, + 'username' => (string) $user->name(), + 'date' => (string) $data->date, + ]; + + + $newFile = $file->update([ + 'comments' => $comments + ]); + + return $comments; + } +]; \ No newline at end of file diff --git a/public/site/plugins/helpers/index.php b/public/site/plugins/helpers/index.php index 4cae530..3d296df 100644 --- a/public/site/plugins/helpers/index.php +++ b/public/site/plugins/helpers/index.php @@ -5,7 +5,7 @@ function getFileData($file) { 'url' => $file->url(), 'uuid' => (string) $file->uuid(), 'name' => $file->filename(), - 'type' => (string) $file->type() + 'type' => (string) $file->type(), ]; if ($file->description()->exists()) { @@ -13,5 +13,9 @@ function getFileData($file) { $data['tags'] = $file->tags()->split(); }; + if($file->comments()->exists()) { + $data['comments'] = Data::decode($file->comments()->value(), 'yaml'); + } + return $data; } \ No newline at end of file diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 86cf6ab..647fdad 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -2,20 +2,31 @@