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 93dc97d..04e1435 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 @@ -13,11 +13,23 @@ Template: document Comments: - - page: - uri: projects/miss-dior-blooming-bouquet - title: Miss Dior Blooming Bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG + location: + page: + uri: > + projects/miss-dior-blooming-bouquet/client-brief + title: Brief client + href: > + /projects/miss-dior-blooming-bouquet?dialog=client-brief + project: + title: Miss Dior Blooming Bouquet + uri: projects/miss-dior-blooming-bouquet + file: + uuid: file://s0lNtRA0Z7ybTCWG + url: file://s0lNtRA0Z7ybTCWG + position: + pageIndex: 1 + x: '32.518325137231' + y: '20.46332046332' replies: [ ] text: test author: @@ -25,10 +37,7 @@ Comments: email: adrien.payet@outlook.com uuid: user://WWjXgPWk role: admin - position: - pageIndex: 1 - x: '25.96184356358' - y: '22.393822393822' - date: 2024-11-17T12:13:39+01:00 - id: m3li0uhb - type: comment \ No newline at end of file + date: 2024-11-18T11:59:06+01:00 + id: m3mwxzuo + type: comment + isRead: false \ No newline at end of file diff --git a/public/site/models/project.php b/public/site/models/project.php index 6012db6..a5d04b0 100644 --- a/public/site/models/project.php +++ b/public/site/models/project.php @@ -28,6 +28,7 @@ class ProjectPage extends Page { return [ 'label' => $child->title()->value(), 'id' => $child->stepName()->value(), + 'slug' => $child->slug(), 'index' => intval($child->stepIndex()->value()), 'modified' => $child->modified('Y-MM-dd'), 'uri' => $uri, @@ -44,13 +45,13 @@ class ProjectPage extends Page { } if ($child->pdf()->isNotEmpty()) { - $uri = $child->parent()->uri() . '?dialog=' . $child->stepName()->value(); + $uri = $child->parent()->uri() . '?dialog=' . $child->slug(); $files[] = getFileData($child->pdf()->toFile()); } } private function handleVirtualSampleStep($child, &$files, &$uri) { - $uri = $child->parent()->uri() . '?dialog=' . $child->stepName()->value(); + $uri = $child->parent()->uri() . '?dialog=' . $child->slug(); foreach ($child->views()->toFiles() as $file) { $files[] = getFileData($file); } diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index b714964..2291da7 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -9,7 +9,14 @@ return [ $json = file_get_contents('php://input'); $data = json_decode($json); - $page = page($data->pageUri); + $parsedUrl = parse_url($data->path); + $query = $parsedUrl['query'] ?? null; + parse_str($query, $queryParams); + $stepSlug = $queryParams['dialog'] ?? null; + + $targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path']; + + $page = page($targetPageUri); $file = $page->file($data->fileName); $user = kirby()->user($data->userUuid); @@ -17,6 +24,7 @@ return [ $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); $data = [ + 'href' => $data->path, 'page' => $page, 'file' => $file, 'position' => [ diff --git a/public/site/plugins/comments/routes/delete.php b/public/site/plugins/comments/routes/delete.php index 8fb658a..b03a5fa 100644 --- a/public/site/plugins/comments/routes/delete.php +++ b/public/site/plugins/comments/routes/delete.php @@ -7,8 +7,9 @@ return [ $json = file_get_contents('php://input'); $data = json_decode($json); - $page = page($data->page->uri); - $file = $page->file($data->file->uuid); + $page = page($data->location->page->uri); + $project = page($data->location->project->uri); + $file = $page->file($data->location->file->uuid); $isReply = $data->parentId ?? false; $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); @@ -38,7 +39,7 @@ return [ echo json_encode(getFileData($newFile)); - kirby()->user()->deleteNotification($page->managers()->toUsers(), $data->id); + kirby()->user()->deleteNotification($project->managers()->toUsers(), $data->id); exit; } diff --git a/public/site/plugins/comments/src/BaseComment.php b/public/site/plugins/comments/src/BaseComment.php index 7b86fea..47a58b6 100644 --- a/public/site/plugins/comments/src/BaseComment.php +++ b/public/site/plugins/comments/src/BaseComment.php @@ -3,8 +3,8 @@ namespace adrienpayet\comments; class BaseComment { - protected $page; - protected $file; + protected $href; + protected $location; protected $position; protected $replies; protected $text; @@ -16,6 +16,7 @@ class BaseComment { public function __construct($data) { $page = $data['page']; + $project = $page->template() == 'project' ? $page : $page->parent(); $file = $data['file']; $position = $data['position']; $replies = $data['replies'] ?? []; @@ -25,13 +26,22 @@ class BaseComment { $id = $data['id']; $type = $data['type'] ?? 'comment'; - $this->page = [ - 'uri' => (string) $page->parent()->uri(), - 'title' => (string) $page->parent()->title(), - ]; - $this->file = [ + $this->location = [ + 'page' => [ + 'uri' => (string) $page->uri(), + 'title' => (string) $page->title(), + ], + 'href' => (string) $data['href'], + 'project' => [ + 'title' => (string) $project->title(), + 'uri' => (string) $project->uri(), + ], + 'file' => $file ? [ 'uuid' => (string) $file->uuid(), + 'url' => (string) $file->uuid() + ] : false, ]; + $this->replies = $replies ?? []; $this->text = $text; $this->author = [ @@ -47,12 +57,12 @@ class BaseComment { $this->position = $position; } - public function page() { - return $this->page; + public function location() { + return $this->location; } public function file() { - return $this->file; + return $this->location['file']; } public function replies() { @@ -99,12 +109,11 @@ class BaseComment { public function toArray() { return [ - 'page' => $this->page, - 'file' => $this->file, + 'location' => $this->location, + 'position' => $this->position, 'replies' => $this->replies, 'text' => $this->text, 'author' => $this->author, - 'position' => $this->position, 'date' => $this->date, 'id' => $this->id, 'type' => $this->type, diff --git a/public/site/plugins/notifications/user-methods/delete.php b/public/site/plugins/notifications/user-methods/delete.php index b9e029a..54f2133 100644 --- a/public/site/plugins/notifications/user-methods/delete.php +++ b/public/site/plugins/notifications/user-methods/delete.php @@ -1,22 +1,23 @@ user(); - try { - $notifications = $user->notifications()->isNotEmpty() - ? Yaml::decode($user->notifications()->value()) - : []; - - foreach ($notifications as $key => $notification) { - if ($notification['id'] === $notificationId) { - unset($notifications[$key]); +return function($projectManagers, $notificationId) { + foreach ($projectManagers as $projectManager) { + try { + $notifications = $projectManager->notifications()->isNotEmpty() + ? Yaml::decode($projectManager->notifications()->value()) + : []; + + foreach ($notifications as $key => $notification) { + if ($notification['id'] === $notificationId) { + unset($notifications[$key]); + } } + + $projectManager->update([ + 'notifications' => Yaml::encode(array_values($notifications)) + ]); + } catch (\Throwable $th) { + throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); } - - $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/Comment.vue b/src/components/comments/Comment.vue index ee82921..27d3493 100644 --- a/src/components/comments/Comment.vue +++ b/src/components/comments/Comment.vue @@ -12,7 +12,7 @@ #{{ commentIndex }} • - Page {{ comment.file.pageIndex }} + Page {{ comment.position.pageIndex }}