change notifications structure from object to array
This commit is contained in:
parent
0d25794b87
commit
20824983a6
8 changed files with 64 additions and 50 deletions
|
|
@ -12,23 +12,43 @@ Template: document
|
||||||
|
|
||||||
Comments:
|
Comments:
|
||||||
|
|
||||||
m2vpa4tb:
|
-
|
||||||
page:
|
page:
|
||||||
uri: >
|
uri: projects/miss-dior-blooming-bouquet
|
||||||
projects/miss-dior-blooming-bouquet/client-brief
|
title: Miss Dior Blooming Bouquet
|
||||||
title: Brief client
|
|
||||||
file:
|
file:
|
||||||
uuid: file://s0lNtRA0Z7ybTCWG
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
pageIndex: 1
|
pageIndex: 1
|
||||||
replies: [ ]
|
replies: [ ]
|
||||||
text: test
|
text: Premier commentaire
|
||||||
user:
|
author:
|
||||||
name: Utilisateur Dior
|
name: Utilisateur Dior
|
||||||
email: utilisateur@dior.com
|
email: utilisateur@dior.com
|
||||||
uuid: user://HfuumN8s
|
uuid: user://HfuumN8s
|
||||||
role: client
|
role: client
|
||||||
date: 2024-10-30T10:54:49+01:00
|
date: 2024-10-30T12:08:36+01:00
|
||||||
id: m2vpa4tb
|
id: m2vrx0ls
|
||||||
|
type: comment
|
||||||
|
isRead: false
|
||||||
|
position:
|
||||||
|
x: null
|
||||||
|
y: null
|
||||||
|
-
|
||||||
|
page:
|
||||||
|
uri: projects/miss-dior-blooming-bouquet
|
||||||
|
title: Miss Dior Blooming Bouquet
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
pageIndex: 1
|
||||||
|
replies: [ ]
|
||||||
|
text: Deuxième commentaire
|
||||||
|
author:
|
||||||
|
name: Utilisateur Dior
|
||||||
|
email: utilisateur@dior.com
|
||||||
|
uuid: user://HfuumN8s
|
||||||
|
role: client
|
||||||
|
date: 2024-10-30T12:08:41+01:00
|
||||||
|
id: m2vrx4zz
|
||||||
type: comment
|
type: comment
|
||||||
isRead: false
|
isRead: false
|
||||||
position:
|
position:
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ return [
|
||||||
],
|
],
|
||||||
'replies' => [],
|
'replies' => [],
|
||||||
'text' => $data->text,
|
'text' => $data->text,
|
||||||
'user' => $user,
|
'author' => $user,
|
||||||
'date' => (string) $data->date,
|
'date' => (string) $data->date,
|
||||||
'id' => $data->id,
|
'id' => $data->id,
|
||||||
'type' => 'comment'
|
'type' => 'comment'
|
||||||
|
|
@ -34,13 +34,13 @@ return [
|
||||||
|
|
||||||
$newComment = new Comment($data);
|
$newComment = new Comment($data);
|
||||||
|
|
||||||
$comments[$newComment->id()] = $newComment->toArray();
|
$comments[] = $newComment->toArray();
|
||||||
|
|
||||||
$newFile = $file->update([
|
$newFile = $file->update([
|
||||||
'comments' => $comments
|
'comments' => $comments
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user->sendNotification('comments', $newComment);
|
$user->sendNotification($newComment);
|
||||||
|
|
||||||
return getFileData($newFile);
|
return getFileData($newFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class BaseComment {
|
||||||
protected $position;
|
protected $position;
|
||||||
protected $replies;
|
protected $replies;
|
||||||
protected $text;
|
protected $text;
|
||||||
protected $user;
|
protected $author;
|
||||||
protected $date;
|
protected $date;
|
||||||
protected $id;
|
protected $id;
|
||||||
protected $type;
|
protected $type;
|
||||||
|
|
@ -21,7 +21,7 @@ class BaseComment {
|
||||||
$filePageIndex = $data['filePageIndex'];
|
$filePageIndex = $data['filePageIndex'];
|
||||||
$replies = $data['replies'] ?? [];
|
$replies = $data['replies'] ?? [];
|
||||||
$text = $data['text'];
|
$text = $data['text'];
|
||||||
$user = $data['user'];
|
$author = $data['author'];
|
||||||
$date = $data['date'];
|
$date = $data['date'];
|
||||||
$id = $data['id'];
|
$id = $data['id'];
|
||||||
$type = $data['type'] ?? 'comment';
|
$type = $data['type'] ?? 'comment';
|
||||||
|
|
@ -36,11 +36,11 @@ class BaseComment {
|
||||||
];
|
];
|
||||||
$this->replies = $replies ?? [];
|
$this->replies = $replies ?? [];
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
$this->user = [
|
$this->author = [
|
||||||
'name' => (string) $user->name(),
|
'name' => (string) $author->name(),
|
||||||
'email' => (string) $user->email(),
|
'email' => (string) $author->email(),
|
||||||
'uuid' => (string) $user->uuid(),
|
'uuid' => (string) $author->uuid(),
|
||||||
'role' => (string) $user->role(),
|
'role' => (string) $author->role(),
|
||||||
];
|
];
|
||||||
$this->date = $date;
|
$this->date = $date;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
|
@ -64,8 +64,8 @@ class BaseComment {
|
||||||
return $this->text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function user() {
|
public function author() {
|
||||||
return $this->user;
|
return $this->author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function date() {
|
public function date() {
|
||||||
|
|
@ -100,7 +100,7 @@ class BaseComment {
|
||||||
'file' => $this->file,
|
'file' => $this->file,
|
||||||
'replies' => $this->replies,
|
'replies' => $this->replies,
|
||||||
'text' => $this->text,
|
'text' => $this->text,
|
||||||
'user' => $this->user,
|
'author' => $this->author,
|
||||||
'date' => $this->date,
|
'date' => $this->date,
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return function ($group, $item) {
|
return function ($item) {
|
||||||
foreach (kirby()->users()->not($this) as $otherUser) {
|
foreach (kirby()->users()->not($this) as $otherUser) {
|
||||||
try {
|
try {
|
||||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
$notifications = $otherUser->notifications()->isNotEmpty()
|
||||||
? Yaml::decode($otherUser->notifications()->value())
|
? Yaml::decode($otherUser->notifications()->value())
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
if (!isset($notifications[$group])) {
|
|
||||||
$notifications[$group] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$notifications[$group][$item->id()] = $item->toArray();
|
$notifications[] = $item->toArray();
|
||||||
|
|
||||||
$otherUser->update([
|
$otherUser->update([
|
||||||
'notifications' => $notifications
|
'notifications' => $notifications
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<article class="comment | flow" :data-status="setStatus(comment)">
|
<article class="comment | flow" :data-status="setStatus(comment)">
|
||||||
<header>
|
<header>
|
||||||
<p>
|
<p>
|
||||||
<strong>{{ comment.user.name ?? comment.user.email }}</strong>
|
<strong>{{ comment.author.name ?? comment.author.email }}</strong>
|
||||||
<template v-if="commentIndex">
|
<template v-if="commentIndex">
|
||||||
<span class="comment__id">#{{ commentIndex }}</span>
|
<span class="comment__id">#{{ commentIndex }}</span>
|
||||||
•
|
•
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
<template v-if="comments">
|
<template v-if="comments">
|
||||||
<template v-if="!openedComment">
|
<template v-if="!openedComment">
|
||||||
<Comment
|
<Comment
|
||||||
v-for="(comment, commentIndex) in Object.values(comments).reverse()"
|
v-for="(comment, commentIndex) in sortedComments"
|
||||||
:comment="comment"
|
:comment="comment"
|
||||||
:commentIndex="commentIndex + 1"
|
:commentIndex="comments.length - commentIndex"
|
||||||
:key="comment.id"
|
:key="comment.id"
|
||||||
@click="openedComment = comment"
|
@click="openedComment = comment"
|
||||||
/>
|
/>
|
||||||
|
|
@ -88,7 +88,7 @@
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import "dayjs/locale/fr";
|
import "dayjs/locale/fr";
|
||||||
import uniqid from "uniqid";
|
import uniqid from "uniqid";
|
||||||
import { ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
import { useUserStore } from "../../stores/user";
|
import { useUserStore } from "../../stores/user";
|
||||||
import { usePageStore } from "../../stores/page";
|
import { usePageStore } from "../../stores/page";
|
||||||
import { useApiStore } from "../../stores/api";
|
import { useApiStore } from "../../stores/api";
|
||||||
|
|
@ -99,7 +99,7 @@ dayjs.locale("fr");
|
||||||
const { currentPageIndex, file, comments } = defineProps({
|
const { currentPageIndex, file, comments } = defineProps({
|
||||||
currentPageIndex: Number,
|
currentPageIndex: Number,
|
||||||
file: Object,
|
file: Object,
|
||||||
comments: Object,
|
comments: Array,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { user } = useUserStore();
|
const { user } = useUserStore();
|
||||||
|
|
@ -111,6 +111,9 @@ const openedComment = ref(null);
|
||||||
const newCommentText = ref("");
|
const newCommentText = ref("");
|
||||||
const isAddOpen = ref(false);
|
const isAddOpen = ref(false);
|
||||||
const emits = defineEmits(["update:file"]);
|
const emits = defineEmits(["update:file"]);
|
||||||
|
const sortedComments = computed(() => {
|
||||||
|
return comments.reverse();
|
||||||
|
});
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
function handleSubmit(event) {
|
function handleSubmit(event) {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
>
|
>
|
||||||
<router-link
|
<router-link
|
||||||
v-if="currentTab === 'all' || !notification.isRead"
|
v-if="currentTab === 'all' || !notification.isRead"
|
||||||
:to="notification.page.uri + '?fileUuid=' + notification.file.uuid"
|
:to="notification.page.uri + '?notificationId=' + notification.id"
|
||||||
>
|
>
|
||||||
<article
|
<article
|
||||||
class="notification | bg-white rounded-lg | p-16 | flow"
|
class="notification | bg-white rounded-lg | p-16 | flow"
|
||||||
|
|
@ -136,13 +136,7 @@ const tabs = computed(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const sortedNotifications = computed(() => {
|
const sortedNotifications = computed(() => {
|
||||||
const allNotifications = [
|
const sortedNotifications = notifications.value.sort((a, b) => {
|
||||||
...Object.values(notifications.value.comments || {}),
|
|
||||||
...Object.values(notifications.value.content || {}),
|
|
||||||
...Object.values(notifications.value.meetings || {}),
|
|
||||||
];
|
|
||||||
|
|
||||||
const sortedNotifications = allNotifications.sort((a, b) => {
|
|
||||||
dayjs(b.date).diff(dayjs(a.date));
|
dayjs(b.date).diff(dayjs(a.date));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -179,17 +179,18 @@ const user = useUserStore().user;
|
||||||
|
|
||||||
const file = ref(null);
|
const file = ref(null);
|
||||||
|
|
||||||
const route = useRoute();
|
// const route = useRoute();
|
||||||
|
|
||||||
if (route.query.fileUuid) {
|
// if (route.query.notificationId) {
|
||||||
page.value.steps.forEach((step) => {
|
// page.value.steps.forEach((step) => {
|
||||||
step.files.forEach((item) => {
|
// const srcNotification = user.notifications;
|
||||||
if (item.uuid === route.query.fileUuid) {
|
// step.files.forEach((item) => {
|
||||||
file.value = item;
|
// if (item.uuid === route.query.notificationId) {
|
||||||
}
|
// file.value = item;
|
||||||
});
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
function setStepStatus(stepName) {
|
function setStepStatus(stepName) {
|
||||||
const stepIndex = steps.indexOf(stepName);
|
const stepIndex = steps.indexOf(stepName);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue