create store for comment draft
This commit is contained in:
parent
13cbfd8309
commit
94ae220174
7 changed files with 162 additions and 47 deletions
|
|
@ -1,7 +1,76 @@
|
|||
Comments:
|
||||
|
||||
-
|
||||
location:
|
||||
page:
|
||||
uri: >
|
||||
projects/projet-recharge-en-forme/extended-brief
|
||||
title: Brief enrichi
|
||||
project:
|
||||
title: Projet Recharge en forme
|
||||
uri: projects/projet-recharge-en-forme
|
||||
dialogUri: >
|
||||
/projects/projet-recharge-en-forme?dialog=extended-brief
|
||||
file:
|
||||
uuid: file://7Bqr3iCH8ltDrdGi
|
||||
url: >
|
||||
http://localhost:8888/media/pages/projects/projet-recharge-en-forme/extended-brief/d44de3da29-1733319278/wip-20240916-demonstrateurs-recharge-en-forme.pdf
|
||||
position:
|
||||
pageIndex: 1
|
||||
x: "64.385025360981"
|
||||
y: "48.295454545455"
|
||||
text: test
|
||||
author:
|
||||
name: Adrien Payet
|
||||
email: adrien.payet@outlook.com
|
||||
uuid: user://WWjXgPWk
|
||||
role: admin
|
||||
date: 2024-12-19T16:02:45+01:00
|
||||
id: ee0c6c8d-4d0f-4262-b4b7-d6c5230b2802
|
||||
type: comment
|
||||
replies:
|
||||
-
|
||||
location:
|
||||
page:
|
||||
uri: >
|
||||
projects/projet-recharge-en-forme/extended-brief
|
||||
title: Brief enrichi
|
||||
project:
|
||||
title: Projet Recharge en forme
|
||||
uri: projects/projet-recharge-en-forme
|
||||
dialogUri: >
|
||||
/projects/projet-recharge-en-forme?dialog=extended-brief
|
||||
file:
|
||||
uuid: file://7Bqr3iCH8ltDrdGi
|
||||
url: >
|
||||
http://localhost:8888/media/pages/projects/projet-recharge-en-forme/extended-brief/d44de3da29-1733319278/wip-20240916-demonstrateurs-recharge-en-forme.pdf
|
||||
parent:
|
||||
author:
|
||||
name: Adrien Payet
|
||||
email: adrien.payet@outlook.com
|
||||
id: ee0c6c8d-4d0f-4262-b4b7-d6c5230b2802
|
||||
position:
|
||||
pageIndex: 1
|
||||
text: test
|
||||
author:
|
||||
name: Adrien Payet
|
||||
email: adrien.payet@outlook.com
|
||||
uuid: user://WWjXgPWk
|
||||
role: admin
|
||||
date: 2024-12-19T16:02:52+01:00
|
||||
id: 3ddd2679-4c67-4efa-8492-a325fda425fb
|
||||
type: comment-reply
|
||||
|
||||
----
|
||||
|
||||
Cover:
|
||||
|
||||
----
|
||||
|
||||
Label:
|
||||
|
||||
----
|
||||
|
||||
Uuid: 7Bqr3iCH8ltDrdGi
|
||||
|
||||
----
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ return [
|
|||
"file" => $file
|
||||
],
|
||||
"position" => [
|
||||
"pageIndex" => $data->position->pageIndex,
|
||||
"x" => $data->position->x,
|
||||
"y" => $data->position->y
|
||||
],
|
||||
|
|
@ -42,6 +41,10 @@ return [
|
|||
"type" => "comment",
|
||||
];
|
||||
|
||||
if ($data->position->pageIndex) {
|
||||
$commentData["position"]["pageIndex"] = $data->position->pageIndex;
|
||||
}
|
||||
|
||||
$newComment = new Comment($commentData);
|
||||
|
||||
$comments[] = $newComment->toArray();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
@ -240,8 +231,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 +260,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 +384,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 {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
>{{ isCommentsOpen ? "Masquer" : "Afficher" }} les commentaires</span
|
||||
>
|
||||
</button>
|
||||
<Comments v-if="isCommentsOpen" @show-draft-marker="showDraftMarker" />
|
||||
<Comments v-if="isCommentsOpen" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
|
@ -32,9 +32,9 @@ import { useRoute, useRouter } from "vue-router";
|
|||
const licenseKey = import.meta.env.VITE_VPV_LICENSE ?? 'd0ab730a-ebba-4060-856c-76d322565645';
|
||||
useLicense({ licenseKey });
|
||||
|
||||
const { openedFile, isCommentsOpen, comments } = storeToRefs(useDialogStore());
|
||||
|
||||
const draftComment = ref(null);
|
||||
const { openedFile, isCommentsOpen, comments, draftComment } = storeToRefs(
|
||||
useDialogStore()
|
||||
);
|
||||
|
||||
const isViewerDisabled = ref(false);
|
||||
|
||||
|
|
@ -122,6 +122,8 @@ function setCommentMarkers() {
|
|||
`.vpv-page-inner-container[aria-label="page ${comment.position.pageIndex}"] .page-inner-container`
|
||||
);
|
||||
|
||||
console.log(container);
|
||||
|
||||
container.appendChild(bubble);
|
||||
|
||||
setTimeout(() => {
|
||||
|
|
@ -145,22 +147,6 @@ function removeCommentMarkers() {
|
|||
bubble.parentNode.removeChild(bubble);
|
||||
});
|
||||
}
|
||||
|
||||
function showDraftMarker(draftComment) {
|
||||
const bubble = document.createElement("a");
|
||||
|
||||
bubble.classList.add("comment-marker");
|
||||
bubble.classList.add("comment-marker--draft");
|
||||
bubble.style.left = draftComment.position.x + "%";
|
||||
bubble.style.top = draftComment.position.y + "%";
|
||||
bubble.href = "#comment-" + draftComment.id;
|
||||
|
||||
const container = document.querySelector(
|
||||
`.vpv-page-inner-container[aria-label="page ${draftComment.position.pageIndex}"] .page-inner-container`
|
||||
);
|
||||
|
||||
container.appendChild(bubble);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
<span class="label">Verre parachevé</span>
|
||||
</button>
|
||||
</header>
|
||||
<div class="dialog__inner" id="verre-brut">
|
||||
<div id="vpv-container" class="dialog__inner">
|
||||
<PdfViewer />
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import { ref, computed, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
export const useDialogStore = defineStore("dialog", () => {
|
||||
const content = ref(null);
|
||||
const openedFile = ref(null);
|
||||
|
||||
const comments = computed(() => {
|
||||
return openedFile.value.comments;
|
||||
});
|
||||
|
|
@ -23,5 +24,37 @@ export const useDialogStore = defineStore("dialog", () => {
|
|||
route.query.hasOwnProperty("comments") ? true : false
|
||||
);
|
||||
|
||||
return { content, openedFile, comments, isCommentsOpen, updateFile };
|
||||
const draftComment = ref({});
|
||||
watch(
|
||||
draftComment,
|
||||
(newVal) => {
|
||||
if (draftComment.value.position) showDraftMarker(newVal);
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
function showDraftMarker(draftComment) {
|
||||
console.log("showDraftMarker");
|
||||
const bubble = document.createElement("a");
|
||||
|
||||
bubble.classList.add("comment-marker");
|
||||
bubble.classList.add("comment-marker--draft");
|
||||
bubble.style.left = draftComment.position.x + "%";
|
||||
bubble.style.top = draftComment.position.y + "%";
|
||||
bubble.href = "#comment-" + draftComment.id;
|
||||
|
||||
const container = document.querySelector(
|
||||
`.vpv-page-inner-container[aria-label="page ${draftComment.position.pageIndex}"] .page-inner-container`
|
||||
);
|
||||
|
||||
container.appendChild(bubble);
|
||||
}
|
||||
|
||||
return {
|
||||
content,
|
||||
openedFile,
|
||||
comments,
|
||||
draftComment,
|
||||
isCommentsOpen,
|
||||
updateFile,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue