show only authorized projects

This commit is contained in:
isUnknown 2024-11-11 17:12:26 +01:00
parent 7d2343fc4d
commit 0fad9cf1d2
8 changed files with 152 additions and 31 deletions

View file

@ -25,22 +25,42 @@ Comments:
email: adrien.payet@outlook.com email: adrien.payet@outlook.com
uuid: user://WWjXgPWk uuid: user://WWjXgPWk
role: admin role: admin
date: 2024-11-11T14:30:48+01:00
id: m3d2a41o
type: comment
isRead: false
position: position:
pageIndex: 1 pageIndex: 1
x: "225.5333404541" x: "33.337885333938"
y: 181 y: "22.007722007722"
date: 2024-11-11T16:47:45+01:00
id: m3d768ay
type: comment
isRead: false
- -
page: page:
uri: projects/miss-dior-blooming-bouquet uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet title: Miss Dior Blooming Bouquet
file: file:
uuid: file://s0lNtRA0Z7ybTCWG uuid: file://s0lNtRA0Z7ybTCWG
replies: [ ] replies:
text: autre test -
page:
uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet
file:
uuid: file://s0lNtRA0Z7ybTCWG
replies: [ ]
text: réponse
author:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
position:
pageIndex: 1
date: 2024-11-11T16:47:58+01:00
id: m3d76io7
type: comment
isRead: false
parentId: m3d76dn1
text: test 2
author: author:
name: Adrien Payet name: Adrien Payet
email: adrien.payet@outlook.com email: adrien.payet@outlook.com
@ -48,9 +68,30 @@ Comments:
role: admin role: admin
position: position:
pageIndex: 1 pageIndex: 1
x: '69.533340454102' x: "77.594135956086"
y: 117 y: "61.776061776062"
date: 2024-11-11T14:40:41+01:00 date: 2024-11-11T16:47:52+01:00
id: m3d2mtm8 id: m3d76dn1
type: comment
isRead: false
-
page:
uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet
file:
uuid: file://s0lNtRA0Z7ybTCWG
replies: [ ]
text: 3e com
author:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
position:
pageIndex: 1
x: '31.698764940525'
y: '51.544401544402'
date: 2024-11-11T16:48:12+01:00
id: m3d76sxu
type: comment type: comment
isRead: false isRead: false

View file

@ -20,7 +20,9 @@ return [
'page' => $page, 'page' => $page,
'parentId' => $data->parentId, 'parentId' => $data->parentId,
'file' => $file, 'file' => $file,
'filePageIndex' => $data->filePageIndex, 'position' => [
'pageIndex' => $data->position->pageIndex,
],
'text' => $data->text, 'text' => $data->text,
'author' => $user, 'author' => $user,
'date' => (string) $data->date, 'date' => (string) $data->date,

View file

@ -1,9 +1,10 @@
<?php <?php
$children = $page->children()->map(function ($child) { $children = $page->children()->filter(function ($child) {
return kirby()->user()->role() === 'admin' || $child->managers()->toUsers()->has(kirby()->user());
})->map(function ($child) {
return [ return [
'title' => $child->title()->value(), 'title' => $child->title()->value(),
'url' => $child->url(), 'url' => $child->url(),
'uri' => $child->uri(),
'uri' => '/' . $child->uri(), 'uri' => '/' . $child->uri(),
'modified' => $child->modified('Y-MM-d'), 'modified' => $child->modified('Y-MM-d'),
'currentStep' => $child->currentStep()->value(), 'currentStep' => $child->currentStep()->value(),
@ -12,6 +13,7 @@ $children = $page->children()->map(function ($child) {
]; ];
})->values(); })->values();
$specificData = [ $specificData = [
"children" => $children, "children" => $children,
]; ];

View file

@ -48,7 +48,7 @@
}}</span> }}</span>
</li> </li>
</ul> </ul>
<details open> <details v-if="currentProjects.length" open>
<summary>Projets en cours</summary> <summary>Projets en cours</summary>
<ul> <ul>
<li v-for="project in currentProjects"> <li v-for="project in currentProjects">
@ -58,7 +58,7 @@
</li> </li>
</ul> </ul>
</details> </details>
<details> <details v-if="archivedProjects.length">
<summary>Projets archivés</summary> <summary>Projets archivés</summary>
<ul> <ul>
<li v-for="project in archivedProjects"> <li v-for="project in archivedProjects">

View file

@ -1,5 +1,9 @@
<template> <template>
<article class="comment | flow" :data-status="setStatus(comment)"> <article
:id="`comment-${comment.id}`"
class="comment | flow"
:data-status="setStatus(comment)"
>
<header> <header>
<p> <p>
<strong>{{ comment.author.name ?? comment.author.email }}</strong> <strong>{{ comment.author.name ?? comment.author.email }}</strong>
@ -126,7 +130,12 @@ async function deleteComment(event, comment) {
border-radius: var(--rounded-lg); border-radius: var(--rounded-lg);
padding: var(--space-12); padding: var(--space-12);
color: var(--color-grey-400); color: var(--color-grey-400);
transition: border-color 0.1s ease-in-out;
} }
.comment.highlight {
border-color: #fff;
}
.comment header p { .comment header p {
display: flex; display: flex;
gap: var(--space-8); gap: var(--space-8);

View file

@ -137,19 +137,44 @@ const sortedReplies = ref(null);
watch(openedComment, (newVal) => { watch(openedComment, (newVal) => {
sortedReplies.value = newVal ? newVal.replies.slice().reverse() : null; sortedReplies.value = newVal ? newVal.replies.slice().reverse() : null;
}); });
watch(
() => file,
(newVal) => {
if (newVal.comments) {
sortedComments.value = newVal.comments;
}
}
);
watch( watch(
() => comments, () => comments,
(newVal) => { (newVal) => {
sortedComments.value = newVal.reverse(); sortedComments.value = newVal.reverse();
} }
); );
watch(isAddOpen, (newVal) => {
if (newVal) {
setTimeout(() => {
document.querySelector("textarea#comment").focus();
}, 100);
}
});
const viewContainer = document.querySelector(".vpv-pages-inner-container"); const viewContainer = document.querySelector(".vpv-pages-inner-container");
window.addEventListener("keydown", (event) => {
if (
isAddOpen.value &&
event.key === "Enter" &&
(event.metaKey || event.ctrlKey)
) {
handleSubmit();
}
});
// Functions // Functions
function handleSubmit(event) { function handleSubmit(event = null) {
event.preventDefault(); if (event) {
event.preventDefault();
}
const date = dayjs().format(); const date = dayjs().format();
const newComment = { const newComment = {
pageUri: page.uri + "/client-brief", pageUri: page.uri + "/client-brief",
@ -160,8 +185,8 @@ function handleSubmit(event) {
position: position:
{ {
pageIndex: newCommentPageIndex.value, pageIndex: newCommentPageIndex.value,
x: newCommentPosition.value.x, x: newCommentPosition.value?.x,
y: newCommentPosition.value.y, y: newCommentPosition.value?.y,
} ?? false, } ?? false,
id: uniqid(), id: uniqid(),
}; };
@ -192,7 +217,6 @@ async function addComment(newComment) {
} }
function changeFile(newFile) { function changeFile(newFile) {
console.log(newFile);
emits("update:file", newFile); emits("update:file", newFile);
} }
@ -229,9 +253,12 @@ function handleCommentPositionClick(event) {
const y = mouseTop - viewRect.top + pageScroll; const y = mouseTop - viewRect.top + pageScroll;
const x = event.clientX - pageRect.left; const x = event.clientX - pageRect.left;
const relativeX = (x / pageRect.width) * 100;
const relativeY = (y / pageRect.height) * 100;
newCommentPosition.value = { newCommentPosition.value = {
x, x: relativeX,
y, y: relativeY,
}; };
isAddOpen.value = true; isAddOpen.value = true;
toggleCommentPositionMode(false); toggleCommentPositionMode(false);
@ -256,6 +283,7 @@ function handleCommentPositionClick(event) {
padding: var(--space-24) var(--space-32); padding: var(--space-24) var(--space-32);
} }
.comments { .comments {
scroll-behavior: smooth;
overflow-y: auto; overflow-y: auto;
height: calc(100% - 3.5rem); height: calc(100% - 3.5rem);
margin-bottom: 1rem; margin-bottom: 1rem;

View file

@ -67,9 +67,21 @@ const currentPageIndex = ref(1);
watch(isCommentsOpen, (newVal) => { watch(isCommentsOpen, (newVal) => {
if (newVal) { if (newVal) {
setCommentBubbles(); setCommentBubbles();
} else {
removeCommentBubbles();
} }
}); });
watch(
() => file,
(newVal) => {
removeCommentBubbles();
if (newVal.comments) {
setCommentBubbles();
}
}
);
// Functions // Functions
const onPdfLoaded = () => { const onPdfLoaded = () => {
const wrapper = document.querySelector(".vpv-pages-inner-container"); const wrapper = document.querySelector(".vpv-pages-inner-container");
@ -116,26 +128,54 @@ function changeFile(newFile) {
} }
function setCommentBubbles() { function setCommentBubbles() {
console.log(file.comments);
if (!file.comments) return;
file.comments.forEach((comment) => { file.comments.forEach((comment) => {
const bubble = document.createElement("button"); const bubble = document.createElement("a");
bubble.classList.add("comment-bubble"); bubble.classList.add("comment-bubble");
bubble.style.left = comment.position.x + "px"; bubble.style.left = comment.position.x + "%";
bubble.style.top = comment.position.y + "px"; bubble.style.top = comment.position.y + "%";
bubble.href = "#comment-" + comment.id;
const container = document.querySelector( const container = document.querySelector(
`.vpv-page-inner-container[aria-label="page ${comment.position.pageIndex}"] .page-inner-container` `.vpv-page-inner-container[aria-label="page ${comment.position.pageIndex}"] .page-inner-container`
); );
container.appendChild(bubble); 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 removeCommentBubbles() {
document.querySelectorAll(".comment-bubble").forEach((bubble) => {
bubble.parentNode.removeChild(bubble);
}); });
} }
</script> </script>
<style> <style>
button.comment-bubble { .comment-bubble {
position: absolute; position: absolute;
display: block;
width: 1.2rem; width: 1.2rem;
height: 1.2rem; height: 1.2rem;
background: url("/assets/svg/comment-bubble.svg") no-repeat !important; background: url("/assets/svg/comment-bubble.svg") no-repeat !important;
cursor: pointer !important;
z-index: 999;
} }
#vpv-container { #vpv-container {
width: var(--dialog-max-w); width: var(--dialog-max-w);

View file

@ -209,7 +209,6 @@ function updateFile(newFile) {
page.value.files.push(newFile); page.value.files.push(newFile);
file.value = page.value.files[0]; file.value = page.value.files[0];
console.log(file.value);
} }
</script> </script>