reply comment on 360 working

This commit is contained in:
isUnknown 2024-12-20 12:36:21 +01:00
parent d727f1a1af
commit f790653fcf
8 changed files with 38 additions and 18 deletions

View file

@ -9,19 +9,11 @@ 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());
foreach ($comments as &$comment) { foreach ($comments as &$comment) {
@ -36,7 +28,7 @@ return [
"parent" => $comment "parent" => $comment
], ],
"position" => [ "position" => [
"pageIndex" => $data->position->pageIndex, "pageIndex" => $data->position->pageIndex ?? null,
], ],
"date" => (string) $data->date, "date" => (string) $data->date,
"text" => $data->text, "text" => $data->text,

View file

@ -11,7 +11,7 @@ class BaseComment {
protected string $text; protected string $text;
protected string $date; protected string $date;
protected string $id; protected string $id;
protected Position $position; protected ?Position $position = null;
public function __construct($data) { public function __construct($data) {
$this->location = new Location($data["location"]); $this->location = new Location($data["location"]);

View file

@ -121,7 +121,9 @@ dayjs.locale("fr");
const { user } = useUserStore(); const { user } = useUserStore();
const { page } = usePageStore(); const { page } = usePageStore();
const dialog = useDialogStore(); const dialog = useDialogStore();
const { comments, openedFile, draftComment } = storeToRefs(useDialogStore()); const { comments, openedFile, draftComment, activeTracks } = storeToRefs(
useDialogStore()
);
const api = useApiStore(); const api = useApiStore();
const openedComment = ref(null); const openedComment = ref(null);
@ -170,7 +172,7 @@ function handleSubmit(event = null) {
const date = dayjs().format(); const date = dayjs().format();
const newComment = { const newComment = {
dialogUri: route.fullPath, dialogUri: route.fullPath,
fileName: openedFile ? openedFile.value.name : false, fileName: openedFile.value ? openedFile.value.name : false,
userUuid: user.uuid, userUuid: user.uuid,
text: draftComment.value.text, text: draftComment.value.text,
date, date,
@ -192,6 +194,10 @@ function handleSubmit(event = null) {
async function replyComment(newComment) { async function replyComment(newComment) {
newComment.parentId = openedComment.value.id; newComment.parentId = openedComment.value.id;
const matchFileParentUri = openedComment.value.location.file.url.match(
/projects\/.*?(?=\/[^/]+\/[^/]+$)/
);
newComment.fileParentUri = matchFileParentUri ? matchFileParentUri[0] : null;
const newFile = await api.replyComment(newComment); const newFile = await api.replyComment(newComment);
resetDraftComment(); resetDraftComment();
isAddOpen.value = false; isAddOpen.value = false;
@ -292,6 +298,12 @@ function prepareDraftCommentInImage(event) {
function openComment(comment) { function openComment(comment) {
openedComment.value = comment; openedComment.value = comment;
if (activeTracks?.value.length === 1) {
openedFile.value = activeTracks.value[0].files.find(
(file) => file.uuid === openedComment.value.location.file.uuid
);
}
} }
</script> </script>

View file

@ -53,7 +53,9 @@ import Interactive360 from "./Interactive360.vue";
import { useDialogStore } from "../../../stores/dialog"; import { useDialogStore } from "../../../stores/dialog";
const { page } = storeToRefs(usePageStore()); const { page } = storeToRefs(usePageStore());
const { isCommentsOpen, isCommentPanelEnabled } = storeToRefs(useDialogStore()); const { isCommentsOpen, isCommentPanelEnabled, activeTracks } = storeToRefs(
useDialogStore()
);
const tracks = computed( const tracks = computed(
() => () =>
@ -75,7 +77,7 @@ watch(isCompareModeEnabled, (newValue) => {
} }
}); });
const activeTracks = ref([tracks.value[0]]); activeTracks.value = [tracks.value[0]];
function getFrontViewUrl(track) { function getFrontViewUrl(track) {
if (track.files.length > 1) { if (track.files.length > 1) {

View file

@ -5,7 +5,7 @@
class="drag-zone" class="drag-zone"
:class="{ grabbing: isDragToRotateEnabled }" :class="{ grabbing: isDragToRotateEnabled }"
></div> ></div>
<img :src="currentFile.url" alt="" width="500" height="500" /> <img :src="openedFile.url" alt="" width="500" height="500" />
</figure> </figure>
<div <div
id="helper" id="helper"

View file

@ -37,9 +37,11 @@ import { storeToRefs } from "pinia";
import { useDialogStore } from "../../../stores/dialog"; import { useDialogStore } from "../../../stores/dialog";
const { step } = useVirtualSampleStore(); const { step } = useVirtualSampleStore();
const { openedFile } = storeToRefs(useDialogStore()); const { openedFile, activeTracks } = storeToRefs(useDialogStore());
const activeTab = ref(Object.keys(step.files.static)[0]); const activeTab = ref(Object.keys(step.files.static)[0]);
activeTracks.value = [];
watch( watch(
activeTab, activeTab,
(newVal) => { (newVal) => {

View file

@ -127,6 +127,8 @@ export const useApiStore = defineStore("api", () => {
body: JSON.stringify(comment), body: JSON.stringify(comment),
}; };
console.log("Commentaire à enregistrer :", comment);
try { try {
const response = await fetch("/create-comment.json", headers); const response = await fetch("/create-comment.json", headers);
if (!response.ok) { if (!response.ok) {
@ -172,6 +174,8 @@ export const useApiStore = defineStore("api", () => {
body: JSON.stringify(comment), body: JSON.stringify(comment),
}; };
console.log("Réponse à enregistrer :", comment);
try { try {
const response = await fetch("/reply-comment.json", headers); const response = await fetch("/reply-comment.json", headers);
if (!response.ok) { if (!response.ok) {

View file

@ -5,8 +5,14 @@ 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 activeTracks = ref(null);
const comments = computed(() => { const comments = computed(() => {
if (activeTracks.value?.length > 0) {
return activeTracks.value[0].files.flatMap((file) =>
file.comments ? file.comments : []
);
}
return openedFile.value.comments; return openedFile.value.comments;
}); });
@ -81,6 +87,7 @@ export const useDialogStore = defineStore("dialog", () => {
function setCommentMarkers() { function setCommentMarkers() {
if (!comments.value) return; if (!comments.value) return;
comments.value.forEach((comment) => { comments.value.forEach((comment) => {
if (comment.location.file.uuid !== openedFile.value.uuid) return;
const bubble = document.createElement("a"); const bubble = document.createElement("a");
bubble.classList.add("comment-marker"); bubble.classList.add("comment-marker");
@ -129,6 +136,7 @@ export const useDialogStore = defineStore("dialog", () => {
return { return {
content, content,
activeTracks,
openedFile, openedFile,
comments, comments,
draftComment, draftComment,