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 623c4e1..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,63 +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 - position: - pageIndex: 1 - x: "57.105131038425" - y: "13.127413127413" - text: un commentaire - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-12-19T10:26:05+01:00 - id: e16a5304-330b-4460-acbd-a6e471f4cda2 - 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 - parent: - author: - name: Adrien Payet - email: adrien.payet@outlook.com - id: e16a5304-330b-4460-acbd-a6e471f4cda2 - position: - pageIndex: 1 - text: une réponse - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-12-19T10:26:09+01:00 - id: bc64e066-299d-4d80-a651-2c17482cda2f - type: comment-reply +Comments: ---- diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt index 057fd9c..9e7b110 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/1_piste-1/0_6.png.txt @@ -1 +1,34 @@ +Comments: + +- + location: + page: + uri: > + projects/miss-dior-blooming-bouquet/virtual-sample/piste-1 + title: Piste 1 + project: + title: Miss Dior Blooming Bouquet + uri: projects/miss-dior-blooming-bouquet + dialogUri: > + /projects/miss-dior-blooming-bouquet?dialog=virtual-sample + file: + uuid: file://J9q2ceZL2aW19oEU + url: > + http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/virtual-sample/piste-1/f26b2c223b-1733765560/0_6.png + position: + x: '50.119047619048' + y: '42.563482466747' + text: test + author: + name: Adrien Payet + email: adrien.payet@outlook.com + uuid: user://WWjXgPWk + role: admin + date: 2024-12-19T16:49:15+01:00 + id: 4b311fe6-a6e4-486f-a9ce-b8820a234e2e + type: comment + replies: [ ] + +---- + Uuid: J9q2ceZL2aW19oEU \ No newline at end of file diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt index d39527e..ebb87db 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/4_virtual-sample/adrien-payet_-az60.pdf.txt @@ -1,5 +1,5 @@ -Uuid: WrFkfiMVZuxwdYad +Comments: ---- -Comments: \ No newline at end of file +Uuid: WrFkfiMVZuxwdYad \ No newline at end of file diff --git a/public/content/projects/2_projet-recharge-en-forme/2_extended-brief/wip-20240916-demonstrateurs-recharge-en-forme.pdf.txt b/public/content/projects/2_projet-recharge-en-forme/2_extended-brief/wip-20240916-demonstrateurs-recharge-en-forme.pdf.txt index fec48c0..03aea75 100644 --- a/public/content/projects/2_projet-recharge-en-forme/2_extended-brief/wip-20240916-demonstrateurs-recharge-en-forme.pdf.txt +++ b/public/content/projects/2_projet-recharge-en-forme/2_extended-brief/wip-20240916-demonstrateurs-recharge-en-forme.pdf.txt @@ -1,7 +1,15 @@ +Comments: + +---- + Cover: ---- +Label: + +---- + Uuid: 7Bqr3iCH8ltDrdGi ---- diff --git a/public/site/blueprints/files/default.yml b/public/site/blueprints/files/default.yml new file mode 100644 index 0000000..39d62c7 --- /dev/null +++ b/public/site/blueprints/files/default.yml @@ -0,0 +1,3 @@ +fields: + comments: + type: hidden diff --git a/public/site/plugins/classes/Position.php b/public/site/plugins/classes/Position.php index b85b596..29c8dca 100644 --- a/public/site/plugins/classes/Position.php +++ b/public/site/plugins/classes/Position.php @@ -4,13 +4,15 @@ namespace adrienpayet\D2P\data; class Position { - public int $pageIndex; + public ?int $pageIndex = null; public ?float $x = null; public ?float $y = null; public function __construct(array $data) { - $this->pageIndex = $data['pageIndex']; + if (isset($data["pageIndex"])) { + $this->pageIndex = $data['pageIndex']; + } if (isset($data["x"])) { $this->x = (float) $data['x']; $this->y = (float) $data['y']; @@ -18,9 +20,11 @@ class Position } public function toArray() { - $array = [ - "pageIndex" => $this->pageIndex, - ]; + $array = []; + + if ($this->pageIndex) { + $array["pageIndex"] = $this->pageIndex; + } if ($this->x) { $array["x"] = $this->x; diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 695d848..69f18be 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -9,17 +9,11 @@ return [ $json = file_get_contents('php://input'); $data = json_decode($json); - $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); + $page = page($data->fileParentUri); + $project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent(); $file = $page->file($data->fileName); $user = kirby()->user($data->userUuid); + $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); @@ -31,7 +25,6 @@ return [ "file" => $file ], "position" => [ - "pageIndex" => $data->position->pageIndex, "x" => $data->position->x, "y" => $data->position->y ], @@ -42,9 +35,13 @@ return [ "type" => "comment", ]; + if (isset($data->position->pageIndex)) { + $commentData["position"]["pageIndex"] = $data->position->pageIndex; + } + $newComment = new Comment($commentData); - $comments[] = $newComment->toArray(); + $comments[] = $newComment->toArray(); $newFile = $file->update([ 'comments' => $comments @@ -55,9 +52,7 @@ return [ try { $user->sendNotification($project, $commentData); } catch (\Throwable $th) { - echo json_encode([ - "error" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(), - ]); + throw new Exception($th->getMessage(), 1); } exit; diff --git a/public/site/plugins/helpers/index.php b/public/site/plugins/helpers/index.php index 34d7b0b..74c897d 100644 --- a/public/site/plugins/helpers/index.php +++ b/public/site/plugins/helpers/index.php @@ -19,7 +19,7 @@ function getFileData($file) { $data['tags'] = $file->tags()->split(); }; - if($file->extension() == "pdf") { + if($file->comments()->exists()) { $data['comments'] = $file->comments()->exists() && $file->comments() ? Data::decode($file->comments()->value(), 'yaml') : []; $data['cover'] = $file->cover()->exists() && $file->cover()->isNotEmpty() ? $file->cover()->toFile()->resize(576)->url() : false; } diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 7fb7d5f..ee39fb5 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -118,15 +118,12 @@ import { useRoute } from "vue-router"; dayjs.locale("fr"); -const emits = defineEmits(["show-draft-marker"]); - const { user } = useUserStore(); const { page } = usePageStore(); const dialog = useDialogStore(); -const { comments, openedFile } = storeToRefs(useDialogStore()); +const { comments, openedFile, draftComment } = storeToRefs(useDialogStore()); const api = useApiStore(); -const draftComment = ref({}); const openedComment = ref(null); const isAddOpen = ref(false); @@ -150,17 +147,10 @@ watch(isAddOpen, (newVal) => { } }); -watch( - draftComment, - (newVal) => { - if (newVal.position) { - emits("show-draft-marker", newVal); - } - }, - { deep: true } -); - -const viewContainer = document.querySelector(".vpv-pages-inner-container"); +const viewContainer = + openedFile.value.type === "document" + ? document.querySelector(".vpv-pages-inner-container") + : document.querySelector(".track"); window.addEventListener("keydown", (event) => { if ( @@ -171,6 +161,7 @@ window.addEventListener("keydown", (event) => { handleSubmit(); } }); + // Functions function handleSubmit(event = null) { if (event) { @@ -211,6 +202,10 @@ async function replyComment(newComment) { } async function addComment(newComment) { + const matchFileParentUri = openedFile.value.url.match( + /projects\/.*?(?=\/[^/]+\/[^/]+$)/ + ); + newComment.fileParentUri = matchFileParentUri ? matchFileParentUri[0] : null; const newFile = await api.addComment(newComment); resetDraftComment(); isAddOpen.value = false; @@ -240,8 +235,18 @@ function toggleCommentPositionMode(enable) { } function handleCommentPositionClick(event) { + if (openedFile.value.type === "document") { + prepareDraftCommentInPdf(event); + } else { + prepareDraftCommentInImage(event); + } + isAddOpen.value = true; + toggleCommentPositionMode(false); +} + +function prepareDraftCommentInPdf(event) { const pageContainer = event.target.closest(".page-inner-container"); - if (!pageContainer) return; + if (!pageContainer || !viewContainer) return; const pageLabel = pageContainer .closest(".vpv-page-inner-container") @@ -259,13 +264,30 @@ function handleCommentPositionClick(event) { const relativeX = (x / pageRect.width) * 100; const relativeY = (y / pageRect.height) * 100; + console.log(pageIndex); + draftComment.value.position = { x: relativeX, y: relativeY, pageIndex: parseInt(pageIndex), }; - isAddOpen.value = true; - toggleCommentPositionMode(false); +} + +function prepareDraftCommentInImage(event) { + if (!viewContainer) return; + + const imageRect = viewContainer.getBoundingClientRect(); + + const mouseTop = event.clientY; + const mouseLeft = event.clientX; + + const relativeX = ((mouseLeft - imageRect.left) / imageRect.width) * 100; + const relativeY = ((mouseTop - imageRect.top) / imageRect.height) * 100; + + draftComment.value.position = { + x: relativeX, + y: relativeY, + }; } function openComment(comment) { @@ -366,6 +388,8 @@ function openComment(comment) { flex-grow: 1; } +.track.waiting-comment, +.track.waiting-comment .drag-zone, .vpv-pages-inner-container.waiting-comment .page-inner-container, .vpv-pages-inner-container.waiting-comment .vpv-text-layer-text, .vpv-pages-inner-container.waiting-comment .vpv-text-layer-wrapper { diff --git a/src/components/project/PdfViewer.vue b/src/components/project/PdfViewer.vue index f7f5a8c..10b07e9 100644 --- a/src/components/project/PdfViewer.vue +++ b/src/components/project/PdfViewer.vue @@ -18,7 +18,7 @@ >{{ isCommentsOpen ? "Masquer" : "Afficher" }} les commentaires - +