send notification user method working
This commit is contained in:
parent
14f409abec
commit
9752fffae6
7 changed files with 67 additions and 18 deletions
|
|
@ -7,3 +7,30 @@ Uuid: s0lNtRA0Z7ybTCWG
|
||||||
----
|
----
|
||||||
|
|
||||||
Template: document
|
Template: document
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Comments:
|
||||||
|
|
||||||
|
m2vpa4tb:
|
||||||
|
page:
|
||||||
|
uri: >
|
||||||
|
projects/miss-dior-blooming-bouquet/client-brief
|
||||||
|
title: Brief client
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
pageIndex: 1
|
||||||
|
replies: [ ]
|
||||||
|
text: test
|
||||||
|
user:
|
||||||
|
name: Utilisateur Dior
|
||||||
|
email: utilisateur@dior.com
|
||||||
|
uuid: user://HfuumN8s
|
||||||
|
role: client
|
||||||
|
date: 2024-10-30T10:54:49+01:00
|
||||||
|
id: m2vpa4tb
|
||||||
|
type: comment
|
||||||
|
isRead: false
|
||||||
|
position:
|
||||||
|
x: null
|
||||||
|
y: null
|
||||||
|
|
@ -40,7 +40,7 @@ return [
|
||||||
'comments' => $comments
|
'comments' => $comments
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user->sendNotification('comments', $newComment->toArray());
|
$user->sendNotification('comments', $newComment);
|
||||||
|
|
||||||
return getFileData($newFile);
|
return getFileData($newFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class BaseComment {
|
||||||
protected $date;
|
protected $date;
|
||||||
protected $id;
|
protected $id;
|
||||||
protected $type;
|
protected $type;
|
||||||
|
protected $isRead;
|
||||||
|
|
||||||
public function __construct($data) {
|
public function __construct($data) {
|
||||||
$page = $data['page'];
|
$page = $data['page'];
|
||||||
|
|
@ -44,6 +45,7 @@ class BaseComment {
|
||||||
$this->date = $date;
|
$this->date = $date;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
$this->isRead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function page() {
|
public function page() {
|
||||||
|
|
@ -78,6 +80,20 @@ class BaseComment {
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRead() {
|
||||||
|
return $this->isRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function read() {
|
||||||
|
$this->isRead = true;
|
||||||
|
return $this->isRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unread() {
|
||||||
|
$this->isRead = false;
|
||||||
|
return $this->isRead;
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray() {
|
public function toArray() {
|
||||||
return [
|
return [
|
||||||
'page' => $this->page,
|
'page' => $this->page,
|
||||||
|
|
@ -88,6 +104,7 @@ class BaseComment {
|
||||||
'date' => $this->date,
|
'date' => $this->date,
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
|
'isRead' => $this->isRead
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,8 @@
|
||||||
Kirby::plugin('adrienpayet/pdc-notifications', [
|
Kirby::plugin('adrienpayet/pdc-notifications', [
|
||||||
'routes' => [
|
'routes' => [
|
||||||
require(__DIR__ . '/routes/mark-as-read.php'),
|
require(__DIR__ . '/routes/mark-as-read.php'),
|
||||||
|
],
|
||||||
|
'userMethods' => [
|
||||||
|
'sendNotification' => require(__DIR__ . '/user-methods/send.php')
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return function ($group, $data) {
|
return function ($group, $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()
|
||||||
|
|
@ -11,10 +11,7 @@ return function ($group, $data) {
|
||||||
$notifications[$group] = [];
|
$notifications[$group] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notifications[$group][$item->id()] = $item->toArray();
|
||||||
$data['isRead'] = false;
|
|
||||||
|
|
||||||
$notifications[$group][$data['id']] = $data;
|
|
||||||
|
|
||||||
$otherUser->update([
|
$otherUser->update([
|
||||||
'notifications' => $notifications
|
'notifications' => $notifications
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref } from "vue";
|
import { ref, computed } from "vue";
|
||||||
|
|
||||||
export const useUserStore = defineStore("user", () => {
|
export const useUserStore = defineStore("user", () => {
|
||||||
const user = ref(null);
|
const user = ref(null);
|
||||||
|
|
||||||
return { user };
|
const notifications = computed(() => {
|
||||||
|
return user.value.notifications;
|
||||||
|
});
|
||||||
|
|
||||||
|
return { user, notifications };
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,15 @@
|
||||||
<main class="wrapper">
|
<main class="wrapper">
|
||||||
<h2 id="tabslist" class="sr-only">Status</h2>
|
<h2 id="tabslist" class="sr-only">Status</h2>
|
||||||
<Tabs :tabs="tabs" @update:currentTab="changeTab" />
|
<Tabs :tabs="tabs" @update:currentTab="changeTab" />
|
||||||
<button class="btn | absolute top-0 right-gutter" disabled>
|
<button
|
||||||
|
class="btn | absolute top-0 right-gutter"
|
||||||
|
:disabled="!notifications.length"
|
||||||
|
>
|
||||||
Marquer tout come lu
|
Marquer tout come lu
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="comments.length === 0"
|
v-if="notifications.length === 0"
|
||||||
class="flex flex-col justify-center | text-grey-700 | absolute inset-0 -z-1"
|
class="flex flex-col justify-center | text-grey-700 | absolute inset-0 -z-1"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
|
|
@ -108,7 +111,7 @@ import { storeToRefs } from "pinia";
|
||||||
dayjs.locale("fr");
|
dayjs.locale("fr");
|
||||||
|
|
||||||
const { page } = storeToRefs(usePageStore());
|
const { page } = storeToRefs(usePageStore());
|
||||||
const user = useUserStore().user;
|
const { notifications } = storeToRefs(useUserStore());
|
||||||
const currentTab = ref("all");
|
const currentTab = ref("all");
|
||||||
const tabs = computed(() => {
|
const tabs = computed(() => {
|
||||||
return [
|
return [
|
||||||
|
|
@ -129,18 +132,16 @@ const tabs = computed(() => {
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
const comments = user?.notifications?.comments
|
const allNotifications = computed(() => {
|
||||||
? Object.values(user.notifications.comments)
|
return Object.values(notifications.value);
|
||||||
: [];
|
});
|
||||||
|
|
||||||
const notifications = [...comments];
|
|
||||||
|
|
||||||
function changeTab(newValue) {
|
function changeTab(newValue) {
|
||||||
currentTab.value = newValue;
|
currentTab.value = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isEmpty = computed(() => {
|
const isEmpty = computed(() => {
|
||||||
return comments.length === 0;
|
return notifications.value.length === 0;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue