Revert "Revert "kaban : fix comments count for virtual sample step""
This reverts commit 37b0175941.
This commit is contained in:
parent
37b0175941
commit
f47886ccf0
4 changed files with 78 additions and 51 deletions
|
|
@ -12,7 +12,6 @@ permissions:
|
||||||
inspirations: false
|
inspirations: false
|
||||||
materials: false
|
materials: false
|
||||||
creations: false
|
creations: false
|
||||||
pages: false
|
|
||||||
user:
|
user:
|
||||||
changeRole: false
|
changeRole: false
|
||||||
delete: false
|
delete: false
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,15 @@ use adrienpayet\comments\Comment;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'pattern' => '(:all)create-comment.json',
|
'pattern' => '(:all)create-comment.json',
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'action' => function () {
|
'action' => function () {
|
||||||
$json = file_get_contents('php://input');
|
$json = file_get_contents('php://input');
|
||||||
$data = json_decode($json);
|
$data = json_decode($json);
|
||||||
|
|
||||||
|
// kirby()->impersonate('kirby');
|
||||||
|
|
||||||
$page = page($data->fileParentUri);
|
$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);
|
$file = $page->file($data->fileName);
|
||||||
$user = kirby()->user($data->userUuid);
|
$user = kirby()->user($data->userUuid);
|
||||||
|
|
||||||
|
|
@ -18,24 +20,24 @@ return [
|
||||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||||
|
|
||||||
$commentData = [
|
$commentData = [
|
||||||
"location" => [
|
'location' => [
|
||||||
"page" => $page,
|
'page' => $page,
|
||||||
"project" => $project,
|
'project' => $project,
|
||||||
"file" => $file
|
'file' => $file,
|
||||||
],
|
],
|
||||||
"position" => [
|
'position' => [
|
||||||
"x" => $data->position->x,
|
'x' => $data->position->x,
|
||||||
"y" => $data->position->y
|
'y' => $data->position->y,
|
||||||
],
|
],
|
||||||
"date" => (string) $data->date,
|
'date' => (string) $data->date,
|
||||||
"text" => $data->text,
|
'text' => $data->text,
|
||||||
"author" => kirby()->user(),
|
'author' => kirby()->user(),
|
||||||
"id" => Str::uuid(),
|
'id' => Str::uuid(),
|
||||||
"type" => "comment",
|
'type' => 'comment',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isset($data->position->pageIndex)) {
|
if (isset($data->position->pageIndex)) {
|
||||||
$commentData["position"]["pageIndex"] = $data->position->pageIndex;
|
$commentData['position']['pageIndex'] = $data->position->pageIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newComment = new Comment($commentData);
|
$newComment = new Comment($commentData);
|
||||||
|
|
@ -43,17 +45,17 @@ return [
|
||||||
$comments[] = $newComment->toArray();
|
$comments[] = $newComment->toArray();
|
||||||
|
|
||||||
$newFile = $file->update([
|
$newFile = $file->update([
|
||||||
'comments' => $comments
|
'comments' => $comments,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
echo json_encode(getFileData($newFile));
|
echo json_encode(getFileData($newFile));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$project->createNotification($commentData);
|
$project->createNotification($commentData);
|
||||||
} catch (\Throwable $th) {
|
} 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;
|
exit;
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'pattern' => '(:all)delete-comment.json',
|
'pattern' => '(:all)delete-comment.json',
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'action' => function () {
|
'action' => function () {
|
||||||
$json = file_get_contents('php://input');
|
$json = file_get_contents('php://input');
|
||||||
$data = json_decode($json);
|
$data = json_decode($json);
|
||||||
|
// kirby()->impersonate('kirby');
|
||||||
|
|
||||||
$page = page($data->location->page->uri);
|
$page = page($data->location->page->uri);
|
||||||
|
|
||||||
|
|
@ -14,33 +15,33 @@ return [
|
||||||
|
|
||||||
$isReply = $data->location->parent->id ?? false;
|
$isReply = $data->location->parent->id ?? false;
|
||||||
foreach ($comments as $key => &$comment) {
|
foreach ($comments as $key => &$comment) {
|
||||||
if ($isReply) {
|
if ($isReply) {
|
||||||
if ($comment['id'] === $data->location->parent->id) {
|
if ($comment['id'] === $data->location->parent->id) {
|
||||||
foreach ($comment['replies'] as $replyKey => $reply) {
|
foreach ($comment['replies'] as $replyKey => $reply) {
|
||||||
if ($reply['id'] === $data->id) {
|
if ($reply['id'] === $data->id) {
|
||||||
unset($comment['replies'][$replyKey]);
|
unset($comment['replies'][$replyKey]);
|
||||||
$comment['replies'] = array_values($comment['replies']);
|
$comment['replies'] = array_values($comment['replies']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($comment['id'] === $data->id) {
|
||||||
|
unset($comments[$key]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if ($comment['id'] === $data->id) {
|
|
||||||
unset($comments[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$comments = array_values($comments);
|
$comments = array_values($comments);
|
||||||
|
|
||||||
$newFile = $file->update([
|
$newFile = $file->update([
|
||||||
'comments' => $comments
|
'comments' => $comments,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
echo json_encode(getFileData($newFile));
|
echo json_encode(getFileData($newFile));
|
||||||
|
|
||||||
$project = $page->parents()->findBy("template", "project");
|
$project = $page->parents()->findBy('template', 'project');
|
||||||
$project->deleteNotification($data->id);
|
$project->deleteNotification($data->id);
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,10 @@
|
||||||
</template>
|
</template>
|
||||||
</figure>
|
</figure>
|
||||||
<footer
|
<footer
|
||||||
v-if="images[0]?.comments?.length > 0"
|
v-if="commentsCount > 0"
|
||||||
class="order-last | text-sm text-primary font-medium"
|
class="order-last | text-sm text-primary font-medium"
|
||||||
>
|
>
|
||||||
{{ images[0].comments.length }} commentaire{{
|
{{ commentsCount }} commentaire{{ commentsCount > 1 ? 's' : '' }}
|
||||||
images[0].comments.length > 1 ? 's' : ''
|
|
||||||
}}
|
|
||||||
</footer>
|
</footer>
|
||||||
<div
|
<div
|
||||||
class="btn btn--xs btn--dtl | mt-16"
|
class="btn btn--xs btn--dtl | mt-16"
|
||||||
|
|
@ -37,6 +35,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import DateTime from './DateTime.vue';
|
import DateTime from './DateTime.vue';
|
||||||
import { useDesignToLightStore } from '../../../stores/designToLight';
|
import { useDesignToLightStore } from '../../../stores/designToLight';
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
const { images, step, uri } = defineProps({
|
const { images, step, uri } = defineProps({
|
||||||
images: Array,
|
images: Array,
|
||||||
|
|
@ -45,4 +44,30 @@ const { images, step, uri } = defineProps({
|
||||||
});
|
});
|
||||||
|
|
||||||
const { isDesignToLightStep } = useDesignToLightStore();
|
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>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue