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 66903d4..8b8e1a4 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 @@ -28,9 +28,93 @@ Comments: url: file://s0lNtRA0Z7ybTCWG position: pageIndex: 1 - x: '27.05459466102' - y: '35.135135135135' - replies: [ ] + x: "27.05459466102" + y: "35.135135135135" + replies: + - + 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 + replies: [ ] + text: test + author: + name: Utilisateur Dior + email: utilisateur@dior.com + uuid: user://HfuumN8s + role: client + date: 2024-11-22T08:08:39+01:00 + id: m3seh19r + type: comment + isRead: false + parentId: m3sdsq23 + - + 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 + replies: [ ] + text: Deuxième réponse + author: + name: Utilisateur Dior + email: utilisateur@dior.com + uuid: user://HfuumN8s + role: client + date: 2024-11-22T08:10:12+01:00 + id: m3sej19k + type: comment + isRead: false + parentId: m3sdsq23 + - + 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 + replies: [ ] + text: Encore + author: + name: Utilisateur Dior + email: utilisateur@dior.com + uuid: user://HfuumN8s + role: client + date: 2024-11-22T08:12:39+01:00 + id: m3sem6sz + type: comment + isRead: false + parentId: m3sdsq23 text: test author: name: Adrien Payet @@ -40,4 +124,91 @@ Comments: date: 2024-11-22T07:49:45+01:00 id: m3sdsq23 type: comment + isRead: false +- + 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: "65.847110638459" + y: "53.474903474903" + replies: [ ] + text: test + author: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + date: 2024-11-22T08:50:41+01:00 + id: m3sfz36o + type: comment + isRead: false +- + 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: "62.548262548263" + replies: [ ] + text: test + author: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + date: 2024-11-22T09:18:05+01:00 + id: m3sgybwq + type: comment + isRead: false +- + 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: '73.769521704789' + y: '83.204633204633' + replies: [ ] + text: 'Adrien Payet : test' + author: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + date: 2024-11-22T09:20:04+01:00 + id: m3sh0vfu + type: comment isRead: false \ No newline at end of file diff --git a/public/site/config/routes/validate-brief.php b/public/site/config/routes/validate-brief.php index 54a7faa..342e6f8 100644 --- a/public/site/config/routes/validate-brief.php +++ b/public/site/config/routes/validate-brief.php @@ -1,32 +1,49 @@ '(:all)validate-brief.json', + 'pattern' => 'validate-brief.json', 'method' => 'POST', 'action' => function () { - $json = file_get_contents('php://input'); - $data = json_decode($json); + $json = file_get_contents('php://input'); + $data = json_decode($json); - $page = page($data->pageUri); - try { - $newPage = $page->update([ - 'isValidated' => 'true' - ]); - echo json_encode([ - "success" => "'" . $newPage->title()->value() . "' brief validated." - ]); + $brief = page($data->briefUri); + $project = $brief->parent(); + $href = $data->dialogUri ? $data->dialogUri : $brief->url(); + + try { + $newPage = $brief->update([ + 'isValidated' => 'true' + ]); - kirby()->user()->sendNotification($newPage->parent(), [ - 'date' => $newPage->modified('YYYY-MM-DD'), - 'author' => kirby()->user()->name()->isNotEmpty() ? kirby()->user()->name() : kirby()->user()->email(), - 'url' => $newPage->url(), - 'type' => 'content' - ]); - } catch (\Throwable $th) { - return [ - "error" => "Can't validate '" . $page->title()->value() . "' brief.", - 'details' => $th->getMessage() - ]; - } + $notification = [ + 'location' => [ + 'href' => (string) $href, + 'project' => [ + 'title' => (string) $project->title(), + 'uri' => (string) $project->url() + ] + ], + 'date' => $newPage->modified('YYYY-MM-DD'), + 'author' => [ + 'name' => (string) kirby()->user()->name(), + 'email' => (string) kirby()->user()->email(), + 'uuid' => (string) kirby()->user()->uuid(), + 'role' => (string) kirby()->user()->role(), + ], + 'type' => 'content' + ]; + + kirby()->user()->sendNotification($project, $notification); + + return [ + "success" => "'" . $project->title()->value() . "' brief validated." + ]; + } catch (\Throwable $th) { + return [ + "error" => "Can't validate '" . $brief->title()->value() . "' brief.", + 'details' => $th->getMessage() + ]; + } } -]; \ No newline at end of file +]; diff --git a/public/site/models/project.php b/public/site/models/project.php index 4b3d93d..4a6ae6c 100644 --- a/public/site/models/project.php +++ b/public/site/models/project.php @@ -35,7 +35,7 @@ class ProjectPage extends Page { 'slug' => $child->slug(), 'index' => intval($child->stepIndex()->value()), 'modified' => $child->modified('Y-MM-dd'), - 'isValidated' => $child->isValidated()->value() ?? false, + 'isValidated' => (bool) $child->isValidated()->value() ?? false, 'uri' => $uri, 'files' => $files, ]; diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index b4f84b9..1ee3abe 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -33,7 +33,7 @@ return [ 'y' => $data->position->y ], 'replies' => [], - 'text' => $data->text, + 'text' => $user->name()->isNotEmpty() ? $user->name()->value() . ' : ' . $data->text : $user->email()->value() . ' : ' . $data->text, 'author' => $user, 'date' => (string) $data->date, 'id' => $data->id, diff --git a/public/site/plugins/comments/routes/reply.php b/public/site/plugins/comments/routes/reply.php index cac1a8a..6c0a70a 100644 --- a/public/site/plugins/comments/routes/reply.php +++ b/public/site/plugins/comments/routes/reply.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, 'parentId' => $data->parentId, 'file' => $file, diff --git a/public/site/plugins/notifications/user-methods/send.php b/public/site/plugins/notifications/user-methods/send.php index b28389d..589f6be 100644 --- a/public/site/plugins/notifications/user-methods/send.php +++ b/public/site/plugins/notifications/user-methods/send.php @@ -13,25 +13,27 @@ * @throws Exception If an error occurs while updating a user's notifications. */ -return function ($project, $notificationData) { + return function ($project, $notificationData) { $recipients = $project->managers()->without($this); - - if (!$recipients) return; - - $notificationData['isRead']; - foreach ($recipients as $otherUser) { - try { - $notifications = $otherUser->notifications()->isNotEmpty() - ? Yaml::decode($otherUser->notifications()->value()) - : []; - - $notifications[] = $notificationData; - $otherUser->update([ - 'notifications' => $notifications - ]); - } catch (\Throwable $th) { - throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); - } + if ($recipients->isEmpty()) return; + + $notificationData['isRead'] = false; + + foreach ($recipients as $otherUser) { + try { + $notifications = $otherUser->notifications()->isNotEmpty() + ? Yaml::decode($otherUser->notifications()->value()) + : []; + + $notifications[] = $notificationData; + + $otherUser->update([ + 'notifications' => $notifications + ]); + } catch (\Throwable $th) { + error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage()); + throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); + } } -}; \ No newline at end of file +}; diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 0546f4f..bde3d95 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -183,12 +183,13 @@ function handleSubmit(event = null) { userUuid: user.uuid, text: draftComment.value.text, date, - position: - { - pageIndex: draftComment.value.position.pageIndex, - x: draftComment.value.position?.x, - y: draftComment.value.position?.y, - } ?? false, + position: { + pageIndex: openedComment.value + ? openedComment.value.position.pageIndex + : draftComment.value.position.pageIndex, + x: openedComment.value ? false : draftComment.value.position.x, + y: openedComment.value ? false : draftComment.value.position.y, + }, id: uniqid(), }; if (openedComment.value) { @@ -201,9 +202,7 @@ function handleSubmit(event = null) { async function replyComment(newComment) { newComment.parentId = openedComment.value.id; const newFile = await api.replyComment(newComment); - draftComment.value.text = ""; - draftComment.value.position = null; - draftComment.value.padeIndex = null; + resetDraftComment(); isAddOpen.value = false; dialog.updateFile(newFile); openedComment.value = newFile.comments.find( @@ -213,12 +212,15 @@ async function replyComment(newComment) { async function addComment(newComment) { const newFile = await api.addComment(newComment); + resetDraftComment(); + isAddOpen.value = false; + dialog.updateFile(newFile); +} + +function resetDraftComment() { draftComment.value.text = ""; draftComment.value.position = null; draftComment.value.padeIndex = null; - isAddOpen.value = false; - - dialog.updateFile(newFile); } function closeComment() { @@ -267,9 +269,7 @@ function handleCommentPositionClick(event) { } function openComment(comment) { - if (comment.replies.length) { - openedComment.value = comment; - } + openedComment.value = comment; } diff --git a/src/components/project/brief/PdfViewer.vue b/src/components/project/brief/PdfViewer.vue index 2635a52..32c413e 100644 --- a/src/components/project/brief/PdfViewer.vue +++ b/src/components/project/brief/PdfViewer.vue @@ -12,7 +12,8 @@