Revert "Revert "kaban : fix comments count for virtual sample step""

This reverts commit 37b0175941.
This commit is contained in:
isUnknown 2025-02-09 10:57:25 +01:00
parent 37b0175941
commit f47886ccf0
4 changed files with 78 additions and 51 deletions

View file

@ -12,7 +12,6 @@ permissions:
inspirations: false
materials: false
creations: false
pages: false
user:
changeRole: false
delete: false

View file

@ -9,8 +9,10 @@ return [
$json = file_get_contents('php://input');
$data = json_decode($json);
// kirby()->impersonate('kirby');
$page = page($data->fileParentUri);
$project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent();
$project = $page->parent()->template() == 'project' ? $page->parent() : $page->parent()->parent();
$file = $page->file($data->fileName);
$user = kirby()->user($data->userUuid);
@ -18,24 +20,24 @@ return [
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
$commentData = [
"location" => [
"page" => $page,
"project" => $project,
"file" => $file
'location' => [
'page' => $page,
'project' => $project,
'file' => $file,
],
"position" => [
"x" => $data->position->x,
"y" => $data->position->y
'position' => [
'x' => $data->position->x,
'y' => $data->position->y,
],
"date" => (string) $data->date,
"text" => $data->text,
"author" => kirby()->user(),
"id" => Str::uuid(),
"type" => "comment",
'date' => (string) $data->date,
'text' => $data->text,
'author' => kirby()->user(),
'id' => Str::uuid(),
'type' => 'comment',
];
if (isset($data->position->pageIndex)) {
$commentData["position"]["pageIndex"] = $data->position->pageIndex;
$commentData['position']['pageIndex'] = $data->position->pageIndex;
}
$newComment = new Comment($commentData);
@ -43,7 +45,7 @@ return [
$comments[] = $newComment->toArray();
$newFile = $file->update([
'comments' => $comments
'comments' => $comments,
]);
echo json_encode(getFileData($newFile));
@ -51,9 +53,9 @@ return [
try {
$project->createNotification($commentData);
} catch (\Throwable $th) {
throw new Exception($th->getMessage() . ". line " . $th->getLine() . " in file " . $th->getFile(), 1);
throw new Exception($th->getMessage() . '. line ' . $th->getLine() . ' in file ' . $th->getFile(), 1);
}
exit;
}
},
];

View file

@ -6,6 +6,7 @@ return [
'action' => function () {
$json = file_get_contents('php://input');
$data = json_decode($json);
// kirby()->impersonate('kirby');
$page = page($data->location->page->uri);
@ -33,14 +34,14 @@ return [
$comments = array_values($comments);
$newFile = $file->update([
'comments' => $comments
'comments' => $comments,
]);
echo json_encode(getFileData($newFile));
$project = $page->parents()->findBy("template", "project");
$project = $page->parents()->findBy('template', 'project');
$project->deleteNotification($data->id);
exit;
}
},
];

View file

@ -17,12 +17,10 @@
</template>
</figure>
<footer
v-if="images[0]?.comments?.length > 0"
v-if="commentsCount > 0"
class="order-last | text-sm text-primary font-medium"
>
{{ images[0].comments.length }} commentaire{{
images[0].comments.length > 1 ? 's' : ''
}}
{{ commentsCount }} commentaire{{ commentsCount > 1 ? 's' : '' }}
</footer>
<div
class="btn btn--xs btn--dtl | mt-16"
@ -37,6 +35,7 @@
<script setup>
import DateTime from './DateTime.vue';
import { useDesignToLightStore } from '../../../stores/designToLight';
import { computed } from 'vue';
const { images, step, uri } = defineProps({
images: Array,
@ -45,4 +44,30 @@ const { images, step, uri } = defineProps({
});
const { isDesignToLightStep } = useDesignToLightStore();
const commentsCount = computed(() => {
let count = 0;
if (Array.isArray(step.files)) {
for (const file of step.files) {
count += file?.comments?.length || 0;
}
} else {
if (step.files?.dynamic) {
for (const track of step.files.dynamic) {
for (const file of track.files) {
count += file?.comments?.length || 0;
}
}
}
if (step.files?.static) {
for (const element of Object.values(step.files.static)) {
count += element?.comments?.length || 0;
}
}
}
return count;
});
</script>