Merge branch 'main' of https://framagit.org/isUnknown/design-to-pack
* 'main' of https://framagit.org/isUnknown/design-to-pack: comment 360 working create comment working create store for comment draft
This commit is contained in:
commit
b4be010af7
12 changed files with 230 additions and 194 deletions
|
|
@ -1,64 +1,5 @@
|
||||||
Comments:
|
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
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Cover: - file://wS6ILTHIDQb1DHJN
|
Cover: - file://wS6ILTHIDQb1DHJN
|
||||||
|
|
|
||||||
|
|
@ -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
|
Uuid: J9q2ceZL2aW19oEU
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Uuid: WrFkfiMVZuxwdYad
|
Comments:
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Comments:
|
Uuid: WrFkfiMVZuxwdYad
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
|
Comments:
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
Cover:
|
Cover:
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
Label:
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
Uuid: 7Bqr3iCH8ltDrdGi
|
Uuid: 7Bqr3iCH8ltDrdGi
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
|
||||||
3
public/site/blueprints/files/default.yml
Normal file
3
public/site/blueprints/files/default.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fields:
|
||||||
|
comments:
|
||||||
|
type: hidden
|
||||||
|
|
@ -4,13 +4,15 @@ namespace adrienpayet\D2P\data;
|
||||||
|
|
||||||
class Position
|
class Position
|
||||||
{
|
{
|
||||||
public int $pageIndex;
|
public ?int $pageIndex = null;
|
||||||
public ?float $x = null;
|
public ?float $x = null;
|
||||||
public ?float $y = null;
|
public ?float $y = null;
|
||||||
|
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->pageIndex = $data['pageIndex'];
|
if (isset($data["pageIndex"])) {
|
||||||
|
$this->pageIndex = $data['pageIndex'];
|
||||||
|
}
|
||||||
if (isset($data["x"])) {
|
if (isset($data["x"])) {
|
||||||
$this->x = (float) $data['x'];
|
$this->x = (float) $data['x'];
|
||||||
$this->y = (float) $data['y'];
|
$this->y = (float) $data['y'];
|
||||||
|
|
@ -18,9 +20,11 @@ class Position
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray() {
|
public function toArray() {
|
||||||
$array = [
|
$array = [];
|
||||||
"pageIndex" => $this->pageIndex,
|
|
||||||
];
|
if ($this->pageIndex) {
|
||||||
|
$array["pageIndex"] = $this->pageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->x) {
|
if ($this->x) {
|
||||||
$array["x"] = $this->x;
|
$array["x"] = $this->x;
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,12 @@ return [
|
||||||
$json = file_get_contents('php://input');
|
$json = file_get_contents('php://input');
|
||||||
$data = json_decode($json);
|
$data = json_decode($json);
|
||||||
|
|
||||||
$parsedUrl = parse_url($data->dialogUri);
|
$page = page($data->fileParentUri);
|
||||||
$query = $parsedUrl['query'] ?? null;
|
$project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent();
|
||||||
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);
|
$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());
|
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||||
|
|
||||||
$commentData = [
|
$commentData = [
|
||||||
|
|
@ -31,7 +25,6 @@ return [
|
||||||
"file" => $file
|
"file" => $file
|
||||||
],
|
],
|
||||||
"position" => [
|
"position" => [
|
||||||
"pageIndex" => $data->position->pageIndex,
|
|
||||||
"x" => $data->position->x,
|
"x" => $data->position->x,
|
||||||
"y" => $data->position->y
|
"y" => $data->position->y
|
||||||
],
|
],
|
||||||
|
|
@ -42,6 +35,10 @@ return [
|
||||||
"type" => "comment",
|
"type" => "comment",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isset($data->position->pageIndex)) {
|
||||||
|
$commentData["position"]["pageIndex"] = $data->position->pageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
$newComment = new Comment($commentData);
|
$newComment = new Comment($commentData);
|
||||||
|
|
||||||
$comments[] = $newComment->toArray();
|
$comments[] = $newComment->toArray();
|
||||||
|
|
@ -55,9 +52,7 @@ return [
|
||||||
try {
|
try {
|
||||||
$user->sendNotification($project, $commentData);
|
$user->sendNotification($project, $commentData);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
echo json_encode([
|
throw new Exception($th->getMessage(), 1);
|
||||||
"error" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ function getFileData($file) {
|
||||||
$data['tags'] = $file->tags()->split();
|
$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['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;
|
$data['cover'] = $file->cover()->exists() && $file->cover()->isNotEmpty() ? $file->cover()->toFile()->resize(576)->url() : false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,15 +118,12 @@ import { useRoute } from "vue-router";
|
||||||
|
|
||||||
dayjs.locale("fr");
|
dayjs.locale("fr");
|
||||||
|
|
||||||
const emits = defineEmits(["show-draft-marker"]);
|
|
||||||
|
|
||||||
const { user } = useUserStore();
|
const { user } = useUserStore();
|
||||||
const { page } = usePageStore();
|
const { page } = usePageStore();
|
||||||
const dialog = useDialogStore();
|
const dialog = useDialogStore();
|
||||||
const { comments, openedFile } = storeToRefs(useDialogStore());
|
const { comments, openedFile, draftComment } = storeToRefs(useDialogStore());
|
||||||
const api = useApiStore();
|
const api = useApiStore();
|
||||||
|
|
||||||
const draftComment = ref({});
|
|
||||||
const openedComment = ref(null);
|
const openedComment = ref(null);
|
||||||
|
|
||||||
const isAddOpen = ref(false);
|
const isAddOpen = ref(false);
|
||||||
|
|
@ -150,17 +147,10 @@ watch(isAddOpen, (newVal) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
const viewContainer =
|
||||||
draftComment,
|
openedFile.value.type === "document"
|
||||||
(newVal) => {
|
? document.querySelector(".vpv-pages-inner-container")
|
||||||
if (newVal.position) {
|
: document.querySelector(".track");
|
||||||
emits("show-draft-marker", newVal);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ deep: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
const viewContainer = document.querySelector(".vpv-pages-inner-container");
|
|
||||||
|
|
||||||
window.addEventListener("keydown", (event) => {
|
window.addEventListener("keydown", (event) => {
|
||||||
if (
|
if (
|
||||||
|
|
@ -171,6 +161,7 @@ window.addEventListener("keydown", (event) => {
|
||||||
handleSubmit();
|
handleSubmit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
function handleSubmit(event = null) {
|
function handleSubmit(event = null) {
|
||||||
if (event) {
|
if (event) {
|
||||||
|
|
@ -211,6 +202,10 @@ async function replyComment(newComment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addComment(newComment) {
|
async function addComment(newComment) {
|
||||||
|
const matchFileParentUri = openedFile.value.url.match(
|
||||||
|
/projects\/.*?(?=\/[^/]+\/[^/]+$)/
|
||||||
|
);
|
||||||
|
newComment.fileParentUri = matchFileParentUri ? matchFileParentUri[0] : null;
|
||||||
const newFile = await api.addComment(newComment);
|
const newFile = await api.addComment(newComment);
|
||||||
resetDraftComment();
|
resetDraftComment();
|
||||||
isAddOpen.value = false;
|
isAddOpen.value = false;
|
||||||
|
|
@ -240,8 +235,18 @@ function toggleCommentPositionMode(enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCommentPositionClick(event) {
|
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");
|
const pageContainer = event.target.closest(".page-inner-container");
|
||||||
if (!pageContainer) return;
|
if (!pageContainer || !viewContainer) return;
|
||||||
|
|
||||||
const pageLabel = pageContainer
|
const pageLabel = pageContainer
|
||||||
.closest(".vpv-page-inner-container")
|
.closest(".vpv-page-inner-container")
|
||||||
|
|
@ -259,13 +264,30 @@ function handleCommentPositionClick(event) {
|
||||||
const relativeX = (x / pageRect.width) * 100;
|
const relativeX = (x / pageRect.width) * 100;
|
||||||
const relativeY = (y / pageRect.height) * 100;
|
const relativeY = (y / pageRect.height) * 100;
|
||||||
|
|
||||||
|
console.log(pageIndex);
|
||||||
|
|
||||||
draftComment.value.position = {
|
draftComment.value.position = {
|
||||||
x: relativeX,
|
x: relativeX,
|
||||||
y: relativeY,
|
y: relativeY,
|
||||||
pageIndex: parseInt(pageIndex),
|
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) {
|
function openComment(comment) {
|
||||||
|
|
@ -366,6 +388,8 @@ function openComment(comment) {
|
||||||
flex-grow: 1;
|
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 .page-inner-container,
|
||||||
.vpv-pages-inner-container.waiting-comment .vpv-text-layer-text,
|
.vpv-pages-inner-container.waiting-comment .vpv-text-layer-text,
|
||||||
.vpv-pages-inner-container.waiting-comment .vpv-text-layer-wrapper {
|
.vpv-pages-inner-container.waiting-comment .vpv-text-layer-wrapper {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
>{{ isCommentsOpen ? "Masquer" : "Afficher" }} les commentaires</span
|
>{{ isCommentsOpen ? "Masquer" : "Afficher" }} les commentaires</span
|
||||||
>
|
>
|
||||||
</button>
|
</button>
|
||||||
<Comments v-if="isCommentsOpen" @show-draft-marker="showDraftMarker" />
|
<Comments v-if="isCommentsOpen" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
|
@ -32,38 +32,9 @@ import { useRoute, useRouter } from "vue-router";
|
||||||
const licenseKey = import.meta.env.VITE_VPV_LICENSE ?? 'd0ab730a-ebba-4060-856c-76d322565645';
|
const licenseKey = import.meta.env.VITE_VPV_LICENSE ?? 'd0ab730a-ebba-4060-856c-76d322565645';
|
||||||
useLicense({ licenseKey });
|
useLicense({ licenseKey });
|
||||||
|
|
||||||
const { openedFile, isCommentsOpen, comments } = storeToRefs(useDialogStore());
|
const { openedFile, isCommentsOpen, comments, draftComment } = storeToRefs(
|
||||||
|
useDialogStore()
|
||||||
const draftComment = ref(null);
|
);
|
||||||
|
|
||||||
const isViewerDisabled = ref(false);
|
|
||||||
|
|
||||||
watch(openedFile, () => {
|
|
||||||
removeCommentMarkers();
|
|
||||||
setCommentMarkers();
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(isCommentsOpen, (newVal) => {
|
|
||||||
if (newVal) {
|
|
||||||
setCommentMarkers();
|
|
||||||
} else {
|
|
||||||
removeCommentMarkers();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(openedFile, (newVal, oldVal) => {
|
|
||||||
if (newVal.url === oldVal.url) return;
|
|
||||||
|
|
||||||
isViewerDisabled.value = true;
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
isViewerDisabled.value = false;
|
|
||||||
removeCommentMarkers();
|
|
||||||
if (newVal.comments) {
|
|
||||||
setCommentMarkers();
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
const currentPageIndex = ref(1);
|
const currentPageIndex = ref(1);
|
||||||
|
|
||||||
|
|
@ -107,60 +78,6 @@ const onPdfLoaded = () => {
|
||||||
|
|
||||||
observePages();
|
observePages();
|
||||||
};
|
};
|
||||||
|
|
||||||
function setCommentMarkers() {
|
|
||||||
if (!comments.value) return;
|
|
||||||
comments.value.forEach((comment) => {
|
|
||||||
const bubble = document.createElement("a");
|
|
||||||
|
|
||||||
bubble.classList.add("comment-marker");
|
|
||||||
bubble.style.left = comment.position.x + "%";
|
|
||||||
bubble.style.top = comment.position.y + "%";
|
|
||||||
bubble.href = "#comment-" + comment.id;
|
|
||||||
|
|
||||||
const container = document.querySelector(
|
|
||||||
`.vpv-page-inner-container[aria-label="page ${comment.position.pageIndex}"] .page-inner-container`
|
|
||||||
);
|
|
||||||
|
|
||||||
container.appendChild(bubble);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
bubble.addEventListener("mouseenter", () => highlight(comment));
|
|
||||||
bubble.addEventListener("mouseleave", () => unhighlight(comment));
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function highlight(comment) {
|
|
||||||
const target = document.querySelector("#comment-" + comment.id);
|
|
||||||
target.classList.add("highlight");
|
|
||||||
}
|
|
||||||
function unhighlight(comment) {
|
|
||||||
const target = document.querySelector("#comment-" + comment.id);
|
|
||||||
target.classList.remove("highlight");
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeCommentMarkers() {
|
|
||||||
document.querySelectorAll(".comment-marker").forEach((bubble) => {
|
|
||||||
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>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
<span class="label">Verre parachevé</span>
|
<span class="label">Verre parachevé</span>
|
||||||
</button>
|
</button>
|
||||||
</header>
|
</header>
|
||||||
<div class="dialog__inner" id="verre-brut">
|
<div id="vpv-container" class="dialog__inner">
|
||||||
<PdfViewer />
|
<PdfViewer />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed, watch } from "vue";
|
||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
|
|
||||||
export const useDialogStore = defineStore("dialog", () => {
|
export const useDialogStore = defineStore("dialog", () => {
|
||||||
const content = ref(null);
|
const content = ref(null);
|
||||||
const openedFile = ref(null);
|
const openedFile = ref(null);
|
||||||
|
|
||||||
const comments = computed(() => {
|
const comments = computed(() => {
|
||||||
return openedFile.value.comments;
|
return openedFile.value.comments;
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateFile(newFile) {
|
function updateFile(newFile) {
|
||||||
|
console.log(newFile);
|
||||||
openedFile.value = newFile;
|
openedFile.value = newFile;
|
||||||
|
|
||||||
if (!content.value.files) return;
|
// if (!content.value.files) return;
|
||||||
content.value.files = content.value.files.map((file) =>
|
// content.value.files = content.value.files.map((file) =>
|
||||||
file.id === newFile.id ? newFile : file
|
// file.id === newFile.id ? newFile : file
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
@ -23,5 +25,114 @@ export const useDialogStore = defineStore("dialog", () => {
|
||||||
route.query.hasOwnProperty("comments") ? true : false
|
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) {
|
||||||
|
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 = draftComment.position.pageIndex
|
||||||
|
? document.querySelector(
|
||||||
|
`.vpv-page-inner-container[aria-label="page ${draftComment.position.pageIndex}"] .page-inner-container`
|
||||||
|
)
|
||||||
|
: document.querySelector(".track");
|
||||||
|
|
||||||
|
container.appendChild(bubble);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isViewerDisabled = ref(false);
|
||||||
|
watch(isCommentsOpen, (newVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
setCommentMarkers();
|
||||||
|
} else {
|
||||||
|
removeCommentMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
watch(openedFile, () => {
|
||||||
|
removeCommentMarkers();
|
||||||
|
if (isCommentsOpen.value) {
|
||||||
|
setCommentMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
watch(openedFile, (newVal, oldVal) => {
|
||||||
|
if (!isCommentsOpen.value || !oldVal || newVal.url == oldVal.url) return;
|
||||||
|
|
||||||
|
isViewerDisabled.value = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
isViewerDisabled.value = false;
|
||||||
|
removeCommentMarkers();
|
||||||
|
if (newVal.comments) {
|
||||||
|
setCommentMarkers();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
function setCommentMarkers() {
|
||||||
|
if (!comments.value) return;
|
||||||
|
comments.value.forEach((comment) => {
|
||||||
|
const bubble = document.createElement("a");
|
||||||
|
|
||||||
|
bubble.classList.add("comment-marker");
|
||||||
|
bubble.style.left = comment.position.x + "%";
|
||||||
|
bubble.style.top = comment.position.y + "%";
|
||||||
|
bubble.href = "#comment-" + comment.id;
|
||||||
|
|
||||||
|
let container = comment.position?.pageIndex
|
||||||
|
? document.querySelector(
|
||||||
|
`.vpv-page-inner-container[aria-label="page ${comment.position.pageIndex}"] .page-inner-container`
|
||||||
|
)
|
||||||
|
: document.querySelector(".track");
|
||||||
|
|
||||||
|
const timeOut = container ? 0 : 500;
|
||||||
|
setTimeout(() => {
|
||||||
|
container = comment.position?.pageIndex
|
||||||
|
? document.querySelector(
|
||||||
|
`.vpv-page-inner-container[aria-label="page ${comment.position.pageIndex}"] .page-inner-container`
|
||||||
|
)
|
||||||
|
: document.querySelector(".track");
|
||||||
|
|
||||||
|
container.appendChild(bubble);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
bubble.addEventListener("mouseenter", () => highlight(comment));
|
||||||
|
bubble.addEventListener("mouseleave", () => unhighlight(comment));
|
||||||
|
}, 100);
|
||||||
|
}, timeOut);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeCommentMarkers() {
|
||||||
|
document.querySelectorAll(".comment-marker").forEach((bubble) => {
|
||||||
|
bubble.parentNode.removeChild(bubble);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function highlight(comment) {
|
||||||
|
const target = document.querySelector("#comment-" + comment.id);
|
||||||
|
target.classList.add("highlight");
|
||||||
|
}
|
||||||
|
function unhighlight(comment) {
|
||||||
|
const target = document.querySelector("#comment-" + comment.id);
|
||||||
|
target.classList.remove("highlight");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
openedFile,
|
||||||
|
comments,
|
||||||
|
draftComment,
|
||||||
|
isCommentsOpen,
|
||||||
|
updateFile,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue