comments / notifications : improve abstraction
This commit is contained in:
parent
f467012241
commit
32c026acfe
11 changed files with 92 additions and 65 deletions
|
|
@ -13,11 +13,23 @@ Template: document
|
|||
Comments:
|
||||
|
||||
-
|
||||
page:
|
||||
uri: projects/miss-dior-blooming-bouquet
|
||||
title: Miss Dior Blooming Bouquet
|
||||
file:
|
||||
uuid: file://s0lNtRA0Z7ybTCWG
|
||||
location:
|
||||
page:
|
||||
uri: >
|
||||
projects/miss-dior-blooming-bouquet/client-brief
|
||||
title: Brief client
|
||||
href: >
|
||||
/projects/miss-dior-blooming-bouquet?dialog=client-brief
|
||||
project:
|
||||
title: Miss Dior Blooming Bouquet
|
||||
uri: projects/miss-dior-blooming-bouquet
|
||||
file:
|
||||
uuid: file://s0lNtRA0Z7ybTCWG
|
||||
url: file://s0lNtRA0Z7ybTCWG
|
||||
position:
|
||||
pageIndex: 1
|
||||
x: '32.518325137231'
|
||||
y: '20.46332046332'
|
||||
replies: [ ]
|
||||
text: test
|
||||
author:
|
||||
|
|
@ -25,10 +37,7 @@ Comments:
|
|||
email: adrien.payet@outlook.com
|
||||
uuid: user://WWjXgPWk
|
||||
role: admin
|
||||
position:
|
||||
pageIndex: 1
|
||||
x: '25.96184356358'
|
||||
y: '22.393822393822'
|
||||
date: 2024-11-17T12:13:39+01:00
|
||||
id: m3li0uhb
|
||||
type: comment
|
||||
date: 2024-11-18T11:59:06+01:00
|
||||
id: m3mwxzuo
|
||||
type: comment
|
||||
isRead: false
|
||||
|
|
@ -28,6 +28,7 @@ class ProjectPage extends Page {
|
|||
return [
|
||||
'label' => $child->title()->value(),
|
||||
'id' => $child->stepName()->value(),
|
||||
'slug' => $child->slug(),
|
||||
'index' => intval($child->stepIndex()->value()),
|
||||
'modified' => $child->modified('Y-MM-dd'),
|
||||
'uri' => $uri,
|
||||
|
|
@ -44,13 +45,13 @@ class ProjectPage extends Page {
|
|||
}
|
||||
|
||||
if ($child->pdf()->isNotEmpty()) {
|
||||
$uri = $child->parent()->uri() . '?dialog=' . $child->stepName()->value();
|
||||
$uri = $child->parent()->uri() . '?dialog=' . $child->slug();
|
||||
$files[] = getFileData($child->pdf()->toFile());
|
||||
}
|
||||
}
|
||||
|
||||
private function handleVirtualSampleStep($child, &$files, &$uri) {
|
||||
$uri = $child->parent()->uri() . '?dialog=' . $child->stepName()->value();
|
||||
$uri = $child->parent()->uri() . '?dialog=' . $child->slug();
|
||||
foreach ($child->views()->toFiles() as $file) {
|
||||
$files[] = getFileData($file);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,14 @@ return [
|
|||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$page = page($data->pageUri);
|
||||
$parsedUrl = parse_url($data->path);
|
||||
$query = $parsedUrl['query'] ?? null;
|
||||
parse_str($query, $queryParams);
|
||||
$stepSlug = $queryParams['dialog'] ?? null;
|
||||
|
||||
$targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path'];
|
||||
|
||||
$page = page($targetPageUri);
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
|
|
@ -17,6 +24,7 @@ return [
|
|||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$data = [
|
||||
'href' => $data->path,
|
||||
'page' => $page,
|
||||
'file' => $file,
|
||||
'position' => [
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ return [
|
|||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$page = page($data->page->uri);
|
||||
$file = $page->file($data->file->uuid);
|
||||
$page = page($data->location->page->uri);
|
||||
$project = page($data->location->project->uri);
|
||||
$file = $page->file($data->location->file->uuid);
|
||||
$isReply = $data->parentId ?? false;
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
|
@ -38,7 +39,7 @@ return [
|
|||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
kirby()->user()->deleteNotification($page->managers()->toUsers(), $data->id);
|
||||
kirby()->user()->deleteNotification($project->managers()->toUsers(), $data->id);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
namespace adrienpayet\comments;
|
||||
|
||||
class BaseComment {
|
||||
protected $page;
|
||||
protected $file;
|
||||
protected $href;
|
||||
protected $location;
|
||||
protected $position;
|
||||
protected $replies;
|
||||
protected $text;
|
||||
|
|
@ -16,6 +16,7 @@ class BaseComment {
|
|||
|
||||
public function __construct($data) {
|
||||
$page = $data['page'];
|
||||
$project = $page->template() == 'project' ? $page : $page->parent();
|
||||
$file = $data['file'];
|
||||
$position = $data['position'];
|
||||
$replies = $data['replies'] ?? [];
|
||||
|
|
@ -25,13 +26,22 @@ class BaseComment {
|
|||
$id = $data['id'];
|
||||
$type = $data['type'] ?? 'comment';
|
||||
|
||||
$this->page = [
|
||||
'uri' => (string) $page->parent()->uri(),
|
||||
'title' => (string) $page->parent()->title(),
|
||||
];
|
||||
$this->file = [
|
||||
$this->location = [
|
||||
'page' => [
|
||||
'uri' => (string) $page->uri(),
|
||||
'title' => (string) $page->title(),
|
||||
],
|
||||
'href' => (string) $data['href'],
|
||||
'project' => [
|
||||
'title' => (string) $project->title(),
|
||||
'uri' => (string) $project->uri(),
|
||||
],
|
||||
'file' => $file ? [
|
||||
'uuid' => (string) $file->uuid(),
|
||||
'url' => (string) $file->uuid()
|
||||
] : false,
|
||||
];
|
||||
|
||||
$this->replies = $replies ?? [];
|
||||
$this->text = $text;
|
||||
$this->author = [
|
||||
|
|
@ -47,12 +57,12 @@ class BaseComment {
|
|||
$this->position = $position;
|
||||
}
|
||||
|
||||
public function page() {
|
||||
return $this->page;
|
||||
public function location() {
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function file() {
|
||||
return $this->file;
|
||||
return $this->location['file'];
|
||||
}
|
||||
|
||||
public function replies() {
|
||||
|
|
@ -99,12 +109,11 @@ class BaseComment {
|
|||
|
||||
public function toArray() {
|
||||
return [
|
||||
'page' => $this->page,
|
||||
'file' => $this->file,
|
||||
'location' => $this->location,
|
||||
'position' => $this->position,
|
||||
'replies' => $this->replies,
|
||||
'text' => $this->text,
|
||||
'author' => $this->author,
|
||||
'position' => $this->position,
|
||||
'date' => $this->date,
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
|
|
|
|||
|
|
@ -1,22 +1,23 @@
|
|||
<?php
|
||||
|
||||
return function($notificationId) {
|
||||
$user = kirby()->user();
|
||||
try {
|
||||
$notifications = $user->notifications()->isNotEmpty()
|
||||
? Yaml::decode($user->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
if ($notification['id'] === $notificationId) {
|
||||
unset($notifications[$key]);
|
||||
return function($projectManagers, $notificationId) {
|
||||
foreach ($projectManagers as $projectManager) {
|
||||
try {
|
||||
$notifications = $projectManager->notifications()->isNotEmpty()
|
||||
? Yaml::decode($projectManager->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
if ($notification['id'] === $notificationId) {
|
||||
unset($notifications[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$projectManager->update([
|
||||
'notifications' => Yaml::encode(array_values($notifications))
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
|
||||
$user->update([
|
||||
'notifications' => Yaml::encode(array_values($notifications))
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<span class="comment__id">#{{ commentIndex }}</span>
|
||||
•
|
||||
</template>
|
||||
<span class="comment__page">Page {{ comment.file.pageIndex }}</span>
|
||||
<span class="comment__page">Page {{ comment.position.pageIndex }}</span>
|
||||
<time
|
||||
class="comment__date"
|
||||
:datetime="dayjs(comment.date).format('YYYY-MM-DD')"
|
||||
|
|
@ -55,7 +55,6 @@ import { useUserStore } from "../../stores/user";
|
|||
import { useApiStore } from "../../stores/api";
|
||||
import { useDialogStore } from "../../stores/dialog";
|
||||
import { computed } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
dayjs.locale("fr");
|
||||
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ import { useApiStore } from "../../stores/api";
|
|||
import { useDialogStore } from "../../stores/dialog";
|
||||
import Comment from "./Comment.vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
dayjs.locale("fr");
|
||||
|
||||
|
|
@ -129,6 +130,7 @@ const newCommentPageIndex = ref(null);
|
|||
const newCommentPosition = ref(null);
|
||||
const newCommentText = ref("");
|
||||
const isAddOpen = ref(false);
|
||||
const route = useRoute();
|
||||
|
||||
const sortedComments = computed(() => comments.value.reverse());
|
||||
const sortedReplies = ref(null);
|
||||
|
|
@ -162,8 +164,8 @@ function handleSubmit(event = null) {
|
|||
}
|
||||
const date = dayjs().format();
|
||||
const newComment = {
|
||||
pageUri: page.uri + "/client-brief",
|
||||
fileName: openedFile.value.name,
|
||||
path: route.fullPath,
|
||||
fileName: openedFile ? openedFile.value.name : false,
|
||||
userUuid: user.uuid,
|
||||
text: newCommentText.value,
|
||||
date,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<PdfViewer v-if="dialog.content.id === 'clientBrief'" />
|
||||
<PdfViewer v-if="dialog.content.slug === 'client-brief'" />
|
||||
</template>
|
||||
<script setup>
|
||||
import PdfViewer from "./client-brief/PdfViewer.vue";
|
||||
|
|
|
|||
|
|
@ -5,12 +5,7 @@
|
|||
<DialogWrapper v-if="dialog.content" />
|
||||
|
||||
<div class="kanban">
|
||||
<ProjectStep
|
||||
v-for="step in page.steps"
|
||||
:key="step"
|
||||
:step="step"
|
||||
@update:dialog="updateDialog"
|
||||
>
|
||||
<ProjectStep v-for="step in page.steps" :key="step" :step="step">
|
||||
</ProjectStep>
|
||||
</div>
|
||||
</main>
|
||||
|
|
@ -37,10 +32,10 @@ if (route.query.dialog) {
|
|||
|
||||
watch(
|
||||
() => route.query.dialog,
|
||||
(targetStepId) => {
|
||||
if (targetStepId) {
|
||||
(targetStepSlug) => {
|
||||
if (targetStepSlug) {
|
||||
const targetStep = page.value.steps.find(
|
||||
(step) => step.id === targetStepId
|
||||
(step) => step.slug === targetStepSlug
|
||||
);
|
||||
dialog.content = targetStep;
|
||||
} else {
|
||||
|
|
@ -49,8 +44,10 @@ watch(
|
|||
}
|
||||
);
|
||||
|
||||
function openDialog(stepId) {
|
||||
const targetStep = page.value.steps.find((step) => step.id === stepId);
|
||||
function openDialog(targetStepSlug) {
|
||||
const targetStep = page.value.steps.find(
|
||||
(step) => step.slug === targetStepSlug
|
||||
);
|
||||
dialog.content = targetStep;
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
>
|
||||
<router-link
|
||||
v-if="currentTab === 'all' || !notification.isRead"
|
||||
:to="notification.page.uri + '?notificationId=' + notification.id"
|
||||
:to="notification.location.href"
|
||||
>
|
||||
<article
|
||||
class="notification | bg-white rounded-lg | p-16 | flow"
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
}}</strong
|
||||
>
|
||||
<span class="notification__client | text-grey-700">{{
|
||||
notification.page.title
|
||||
notification.location.project.title
|
||||
}}</span>
|
||||
<time
|
||||
datetime=""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue