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 c63a8f2..98dbc42 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 @@ -27,9 +27,30 @@ Comments: role: admin position: pageIndex: 1 - x: "19.132179426191" - y: "21.235521235521" - date: 2024-11-16T12:15:12+01:00 - id: m3k2mztq + x: "34.157449699143" + y: "50.965250965251" + date: 2024-11-17T11:51:35+01:00 + id: m3lh8h5h + type: comment + isRead: false +- + page: + uri: projects/miss-dior-blooming-bouquet + title: Miss Dior Blooming Bouquet + file: + uuid: file://s0lNtRA0Z7ybTCWG + replies: [ ] + text: deuxième commentaire + author: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + position: + pageIndex: 1 + x: '84.696990994209' + y: '56.949806949807' + date: 2024-11-17T11:59:37+01:00 + id: m3lhisy6 type: comment isRead: false \ No newline at end of file diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 0b4b41a..b714964 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -40,11 +40,14 @@ return [ 'comments' => $comments ]); + echo json_encode(getFileData($newFile)); + try { $user->sendNotification($page->parent()->uri(), $newComment->toArray()); } catch (\Throwable $th) { throw new Exception($th->getMessage(), 1); } - return getFileData($newFile); + + 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 cc3ac57..eba45cb 100644 --- a/public/site/plugins/comments/routes/delete.php +++ b/public/site/plugins/comments/routes/delete.php @@ -30,32 +30,16 @@ return [ } } - $comments = array_values($comments); // Réindexe les commentaires + $comments = array_values($comments); - foreach (kirby()->users() as $user) { - try { - $notifications = $user->notifications()->isNotEmpty() - ? Yaml::decode($user->notifications()->value()) - : []; - - foreach ($notifications as $key => $notification) { - if ($notification['id'] === $data->id) { - unset($notifications[$key]); - } - } - - $user->update([ - 'notifications' => $notifications - ]); - } catch (\Throwable $th) { - throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); - } - } - $newFile = $file->update([ 'comments' => $comments ]); + + echo json_encode(getFileData($newFile)); + + kirby()->user()->deleteNotification($page, $data->id); - return getFileData($newFile); + exit; } ]; diff --git a/public/site/plugins/notifications/index.php b/public/site/plugins/notifications/index.php index 10130ae..7a80fd1 100644 --- a/public/site/plugins/notifications/index.php +++ b/public/site/plugins/notifications/index.php @@ -1,10 +1,11 @@ [ - require(__DIR__ . '/routes/mark-as-read.php'), - ], + // 'routes' => [ + // require(__DIR__ . '/routes/mark-as-read.php'), + // ], 'userMethods' => [ - 'sendNotification' => require(__DIR__ . '/user-methods/send.php') + 'sendNotification' => require(__DIR__ . '/user-methods/send.php'), + 'deleteNotification' => require(__DIR__ . '/user-methods/delete.php') ] ]); diff --git a/public/site/plugins/notifications/user-methods/delete.php b/public/site/plugins/notifications/user-methods/delete.php new file mode 100644 index 0000000..82a6d28 --- /dev/null +++ b/public/site/plugins/notifications/user-methods/delete.php @@ -0,0 +1,26 @@ +managers()->toUsers(); + + foreach ($projectManagers as $user) { + try { + $notifications = $user->notifications()->isNotEmpty() + ? Yaml::decode($user->notifications()->value()) + : []; + + foreach ($notifications as $key => $notification) { + if ($notification['id'] === $notificationId) { + unset($notifications[$key]); + } + } + + // Réindexation et ré-encodage en YAML avant la mise à jour + $user->update([ + 'notifications' => Yaml::encode(array_values($notifications)) + ]); + } catch (\Throwable $th) { + throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); + } + } +}; diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index db6a3d0..996b0e1 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -1,7 +1,10 @@