diff --git a/public/site/blueprints/users/admin.yml b/public/site/blueprints/users/admin.yml
index 16ff498..691d29c 100644
--- a/public/site/blueprints/users/admin.yml
+++ b/public/site/blueprints/users/admin.yml
@@ -4,4 +4,18 @@ home: /panel/pages/projects
fields:
notifications:
- type: hidden
+ label: Notifications
+ type: structure
+ fields:
+ location:
+ type: object
+ fields:
+ page:
+ type: object
+ fields:
+ uri:
+ type: text
+ href:
+ type: url
+ type:
+ type: text
diff --git a/public/site/config/routes/validate-brief.php b/public/site/config/routes/validate-brief.php
index fb21587..d9d7e32 100644
--- a/public/site/config/routes/validate-brief.php
+++ b/public/site/config/routes/validate-brief.php
@@ -7,12 +7,12 @@ return [
$json = file_get_contents('php://input');
$data = json_decode($json);
- $brief = page($data->briefUri);
- $project = $brief->parent();
- $href = $data->dialogUri ? $data->dialogUri : $brief->url();
+ $page = page($data->briefUri);
+ $project = $page->parent();
+ $dialogUri = $data->dialogUri ? $data->dialogUri : null;
try {
- $newPage = $brief->update([
+ $newPage = $page->update([
'isValidated' => 'true'
]);
@@ -21,20 +21,13 @@ return [
$notification = [
'location' => [
- 'href' => (string) $href,
- 'project' => [
- 'title' => (string) $project->title(),
- 'uri' => (string) $project->url()
- ]
+ 'page' => $page,
+ 'project' => $project,
+ 'dialogUri' => (string) $dialogUri,
],
'date' => $dateTime->format('Y-m-d\TH:i:sP'),
'text' => "Brief (" . $project->title()->value() . ")",
- 'author' => [
- 'name' => (string) kirby()->user()->name(),
- 'email' => (string) kirby()->user()->email(),
- 'uuid' => (string) kirby()->user()->uuid(),
- 'role' => (string) kirby()->user()->role(),
- ],
+ 'author' => kirby()->user(),
'id' => Str::uuid(),
'type' => 'content'
];
@@ -46,7 +39,7 @@ return [
];
} catch (\Throwable $th) {
return [
- "error" => "Can't validate '" . $brief->title()->value() . "' brief.",
+ "error" => "Can't validate '" . $page->title()->value() . "' brief.",
'details' => $th->getMessage()
];
}
diff --git a/public/site/plugins/classes/Author.php b/public/site/plugins/classes/Author.php
new file mode 100644
index 0000000..1df1b9d
--- /dev/null
+++ b/public/site/plugins/classes/Author.php
@@ -0,0 +1,27 @@
+name = (string) $author->name();
+ $this->email = (string) $author->email();
+ $this->uuid = (string) $author->uuid();
+ $this->role = (string) $author->role();
+ }
+
+ public function toArray() {
+ return [
+ "name" => $this->name,
+ "email" => $this->email,
+ "uuid" => $this->uuid,
+ "role" => $this->role,
+ ];
+ }
+}
\ No newline at end of file
diff --git a/public/site/plugins/notifications/index.php b/public/site/plugins/notifications/index.php
index 6a0219e..1a5c6ea 100644
--- a/public/site/plugins/notifications/index.php
+++ b/public/site/plugins/notifications/index.php
@@ -4,6 +4,17 @@ load([
'ProjectPage' => 'models/ProjectPage.php',
], __DIR__);
+F::loadClasses([
+ 'adrienpayet\\notifications\\Notification' => __DIR__ . '/src/Notification.php',
+ 'adrienpayet\\notifications\\location\\Location' => __DIR__ . '/src/location/Location.php',
+ 'adrienpayet\\notifications\\location\\PageDetails' => __DIR__ . '/src/location/PageDetails.php',
+ 'adrienpayet\\notifications\\location\\ProjectDetails' => __DIR__ . '/src/location/ProjectDetails.php',
+ 'adrienpayet\\notifications\\location\\FileDetails' => __DIR__ . '/src/location/FileDetails.php',
+ 'adrienpayet\\notifications\\Position' => __DIR__ . '/src/Position.php',
+ 'adrienpayet\\Author' => __DIR__ . '/../classes/Author.php'
+]);
+
+
Kirby::plugin('adrienpayet/pdc-notifications', [
'routes' => [
require(__DIR__ . '/routes/readAll.php'),
diff --git a/public/site/plugins/notifications/src/Notification.php b/public/site/plugins/notifications/src/Notification.php
new file mode 100644
index 0000000..b9f040b
--- /dev/null
+++ b/public/site/plugins/notifications/src/Notification.php
@@ -0,0 +1,50 @@
+type = $data["type"];
+ $this->location = new Location($data["location"]);
+ $this->text = $data["text"];
+ $this->author = new Author($data["author"]);
+ $this->date = $data["date"];
+ $this->id = $data["id"];
+ $this->isRead = $data["isRead"];
+
+ if ($data["type"] === "comment") {
+ $this->position = new Position($data["position"]);
+ }
+ }
+
+ public function toArray() {
+ $array = [
+ "type" => $this->type,
+ "location" => $this->location->toArray(),
+ "text" => $this->text,
+ "author" => $this->author->toArray(),
+ "date" => $this->date,
+ "id" => $this->id,
+ "isRead" => $this->isRead,
+ ];
+ if ($this->type === "comment") {
+ $array["position"] = $this->position->toArray();
+ }
+
+ return $array;
+ }
+
+}
diff --git a/public/site/plugins/notifications/src/Position.php b/public/site/plugins/notifications/src/Position.php
new file mode 100644
index 0000000..01f319c
--- /dev/null
+++ b/public/site/plugins/notifications/src/Position.php
@@ -0,0 +1,25 @@
+pageIndex = $data['pageIndex'];
+ $this->x = (float) $data['x'];
+ $this->y = (float) $data['y'];
+ }
+
+ public function toArray() {
+ return [
+ "pageIndex" => $this->pageIndex,
+ "x" => $this->x,
+ "y" => $this->y,
+ ];
+ }
+}
diff --git a/public/site/plugins/notifications/src/location/FileDetails.php b/public/site/plugins/notifications/src/location/FileDetails.php
new file mode 100644
index 0000000..8d1ba42
--- /dev/null
+++ b/public/site/plugins/notifications/src/location/FileDetails.php
@@ -0,0 +1,22 @@
+uuid = (string) $data->uuid();
+ $this->url = (string) $data->url();
+ }
+
+ public function toArray() {
+ return [
+ "uuid" => $this->uuid,
+ "url" => $this->url
+ ];
+ }
+}
diff --git a/public/site/plugins/notifications/src/location/Location.php b/public/site/plugins/notifications/src/location/Location.php
new file mode 100644
index 0000000..619945f
--- /dev/null
+++ b/public/site/plugins/notifications/src/location/Location.php
@@ -0,0 +1,36 @@
+page = new PageDetails($data["page"]);
+ $this->dialogUri = $data["dialogUri"];
+ $this->project = new ProjectDetails($data["project"]);
+
+ if (isset($data['file'])) {
+ $this->file = new FileDetails($data["file"]);
+ }
+ }
+
+ public function toArray() {
+ $array = [
+ "page" => $this->page->toArray(),
+ "project" => $this->project->toArray(),
+ ];
+
+ if ($this->dialogUri) {
+ $array["dialogUri"] = $this->dialogUri;
+ $array["file"] = $this->file;
+ }
+
+ return $array;
+ }
+}
diff --git a/public/site/plugins/notifications/src/location/PageDetails.php b/public/site/plugins/notifications/src/location/PageDetails.php
new file mode 100644
index 0000000..e9b9ddc
--- /dev/null
+++ b/public/site/plugins/notifications/src/location/PageDetails.php
@@ -0,0 +1,21 @@
+page = $page;
+ }
+
+ public function toArray() {
+ return [
+ "uri" => (string) $this->page->uri(),
+ "title" => (string) $this->page->title(),
+ ];
+ }
+}
\ No newline at end of file
diff --git a/public/site/plugins/notifications/src/location/ProjectDetails.php b/public/site/plugins/notifications/src/location/ProjectDetails.php
new file mode 100644
index 0000000..822491c
--- /dev/null
+++ b/public/site/plugins/notifications/src/location/ProjectDetails.php
@@ -0,0 +1,23 @@
+title = (string) $page->title();
+ $this->uri = (string) $page->uri();
+ }
+
+ public function toArray() {
+ return [
+ "title" => $this->title,
+ "uri" => $this->uri
+ ];
+ }
+}
diff --git a/public/site/plugins/notifications/user-methods/send.php b/public/site/plugins/notifications/user-methods/send.php
index 589f6be..28f145f 100644
--- a/public/site/plugins/notifications/user-methods/send.php
+++ b/public/site/plugins/notifications/user-methods/send.php
@@ -1,5 +1,7 @@
notifications()->value())
: [];
- $notifications[] = $notificationData;
+ $newNotification = new Notification($notificationData);
+ $notifications[] = $newNotification->toArray();
$otherUser->update([
'notifications' => $notifications
diff --git a/src/views/Brief.vue b/src/views/Brief.vue
index a50cdc2..dd5cbc9 100644
--- a/src/views/Brief.vue
+++ b/src/views/Brief.vue
@@ -9,11 +9,7 @@
>
Retour au projet
-