From 231bb21a4f6ee4044c28ce517a75496f35da2cc7 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Wed, 18 Dec 2024 18:22:41 +0100 Subject: [PATCH] #68 - reply working + remove marker on comment delete --- ...mise-au-service-de-sarkozy-le-boss.pdf.txt | 59 +------------------ public/site/plugins/classes/Position.php | 21 ++++--- .../plugins/classes/location/Location.php | 15 +++++ .../site/plugins/comments/routes/create.php | 2 - public/site/plugins/comments/routes/reply.php | 36 ++++++----- .../site/plugins/comments/src/BaseComment.php | 6 +- public/site/plugins/comments/src/Comment.php | 6 -- public/site/plugins/comments/src/Reply.php | 9 ++- src/components/project/PdfViewer.vue | 5 ++ 9 files changed, 64 insertions(+), 95 deletions(-) diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/2_proposal/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/2_proposal/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf.txt index ded5934..6872059 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/2_proposal/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/2_proposal/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf.txt @@ -1,61 +1,4 @@ -Comments: - -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/proposal - title: Offre commerciale - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0' - file: - uuid: file://3vTh1tMFeFM2JxaN - url: > - http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf - text: test - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-12-18T16:20:04+01:00 - id: 6dbb6d56-a6b7-467b-8341-3d8112a73684 - position: - pageIndex: 1 - x: "73.3181571571" - y: "27.272727272727" - type: comment - replies: [ ] -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/proposal - title: Offre commerciale - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0' - file: - uuid: file://3vTh1tMFeFM2JxaN - url: > - http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf - text: est - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-12-18T16:23:42+01:00 - id: 5b2d93f9-fc44-4a69-955a-bf282fba8966 - position: - pageIndex: 1 - x: '43.56742057598' - y: '65.340909090909' - type: comment - replies: [ ] +Comments: ---- diff --git a/public/site/plugins/classes/Position.php b/public/site/plugins/classes/Position.php index 5707606..b85b596 100644 --- a/public/site/plugins/classes/Position.php +++ b/public/site/plugins/classes/Position.php @@ -5,21 +5,28 @@ namespace adrienpayet\D2P\data; class Position { public int $pageIndex; - public float $x; - public float $y; + public ?float $x = null; + public ?float $y = null; public function __construct(array $data) { $this->pageIndex = $data['pageIndex']; - $this->x = (float) $data['x']; - $this->y = (float) $data['y']; + if (isset($data["x"])) { + $this->x = (float) $data['x']; + $this->y = (float) $data['y']; + } } public function toArray() { - return [ + $array = [ "pageIndex" => $this->pageIndex, - "x" => $this->x, - "y" => $this->y, ]; + + if ($this->x) { + $array["x"] = $this->x; + $array["y"] = $this->y; + } + + return $array; } } diff --git a/public/site/plugins/classes/location/Location.php b/public/site/plugins/classes/location/Location.php index f1e8e3c..c9ace9b 100644 --- a/public/site/plugins/classes/location/Location.php +++ b/public/site/plugins/classes/location/Location.php @@ -8,6 +8,7 @@ class Location protected ?string $dialogUri = null; protected ProjectDetails $project; protected ?FileDetails $file = null; + protected ?string $parentCommentId = null; public function __construct(array $data) { @@ -18,6 +19,17 @@ class Location if (isset($data['file'])) { $this->file = new FileDetails($data["file"]); } + if (isset($data["parentCommentId"])) { + $this->parentCommentId(); + } + } + + public function setParentCommentId($id) { + $this->parentCommentId = $id; + } + + public function parentId() { + return $this->parentCommentId; } public function toArray() { @@ -28,6 +40,9 @@ class Location if ($this->dialogUri) { $array["dialogUri"] = $this->dialogUri; + } + + if ($this->file) { $array["file"] = $this->file; } diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index cd1d26c..695d848 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -42,8 +42,6 @@ return [ "type" => "comment", ]; - $user->sendNotification($project, $commentData); - $newComment = new Comment($commentData); $comments[] = $newComment->toArray(); diff --git a/public/site/plugins/comments/routes/reply.php b/public/site/plugins/comments/routes/reply.php index 6c0a70a..383b19d 100644 --- a/public/site/plugins/comments/routes/reply.php +++ b/public/site/plugins/comments/routes/reply.php @@ -9,36 +9,40 @@ return [ $json = file_get_contents('php://input'); $data = json_decode($json); - $parsedUrl = parse_url($data->path); + $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); $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()); - $data = [ - 'href' => $data->path, - 'page' => $page, - 'parentId' => $data->parentId, - 'file' => $file, - 'position' => [ - 'pageIndex' => $data->position->pageIndex, + $replyData = [ + "location" => [ + "page" => $page, + "project" => $project, + "dialogUri" => $data->dialogUri, + "file" => $file, ], - 'text' => $data->text, - 'author' => $user, - 'date' => (string) $data->date, - 'id' => $data->id, - 'type' => 'comment' + "parentId" => $data->parentId, + "position" => [ + "pageIndex" => $data->position->pageIndex, + ], + "date" => (string) $data->date, + "text" => $data->text, + "author" => kirby()->user(), + "id" => Str::uuid(), + "type" => "comment", ]; - $newReply = new Reply($data); + $newReply = new Reply($replyData); foreach ($comments as &$comment) { if ($comment['id'] === $newReply->parentId()) { @@ -50,7 +54,7 @@ return [ 'comments' => $comments ]); - $user->sendNotification($page->parent(), $newReply->toArray()); + $user->sendNotification($project, $replyData); return getFileData($newFile); } diff --git a/public/site/plugins/comments/src/BaseComment.php b/public/site/plugins/comments/src/BaseComment.php index 67c89ed..a98d40e 100644 --- a/public/site/plugins/comments/src/BaseComment.php +++ b/public/site/plugins/comments/src/BaseComment.php @@ -3,14 +3,16 @@ namespace adrienpayet\comments; use adrienpayet\D2P\data\location\Location; use adrienpayet\D2P\data\Author; +use adrienpayet\D2P\data\Position; class BaseComment { protected string $type; protected Location $location; - protected string $text; protected Author $author; + protected string $text; protected string $date; protected string $id; + protected Position $position; public function __construct($data) { $this->location = new Location($data["location"]); @@ -18,11 +20,13 @@ class BaseComment { $this->author = new Author($data["author"]); $this->date = $data["date"]; $this->id = $data["id"]; + $this->position = new Position($data['position']); } public function toArray() { return [ "location" => $this->location->toArray(), + "position" => $this->position->toArray(), "text" => $this->text, "author" => $this->author->toArray(), "date" => $this->date, diff --git a/public/site/plugins/comments/src/Comment.php b/public/site/plugins/comments/src/Comment.php index 223223b..f7c818b 100644 --- a/public/site/plugins/comments/src/Comment.php +++ b/public/site/plugins/comments/src/Comment.php @@ -1,24 +1,18 @@ position = new Position($data['position']); - } } public function toArray() { $array = parent::toArray(); - $array['position'] = $this->position; $array['type'] = $this->type; $array['replies'] = $this->replies; diff --git a/public/site/plugins/comments/src/Reply.php b/public/site/plugins/comments/src/Reply.php index 4ff9382..7ab2b04 100644 --- a/public/site/plugins/comments/src/Reply.php +++ b/public/site/plugins/comments/src/Reply.php @@ -3,21 +3,20 @@ namespace adrienpayet\comments; class Reply extends BaseComment { - protected $parentId; + protected string $type = "comment-reply"; public function __construct($data) { parent::__construct($data); - $this->parentId = $data['parentId']; + $this->location->setParentCommentId($data["parentId"]); } - public function parentId() { - return $this->parentId; + return $this->location->parentId(); } public function toArray() { $array = parent::toArray(); - $array['parentId'] = $this->parentId; + $array['type'] = $this->type; return $array; } diff --git a/src/components/project/PdfViewer.vue b/src/components/project/PdfViewer.vue index 834e16e..7cc203c 100644 --- a/src/components/project/PdfViewer.vue +++ b/src/components/project/PdfViewer.vue @@ -36,6 +36,11 @@ const draftComment = ref(null); const isViewerDisabled = ref(false); +watch(openedFile, () => { + removeCommentMarkers(); + setCommentMarkers(); +}); + watch(isCommentsOpen, (newVal) => { if (newVal) { setCommentMarkers();