#68 - create comment create working (notification to adapt)

This commit is contained in:
isUnknown 2024-12-18 16:26:55 +01:00
parent 3d4ddc12fc
commit cf83edc1e6
11 changed files with 106 additions and 158 deletions

View file

@ -6,112 +6,56 @@ Comments:
uri: > uri: >
projects/miss-dior-blooming-bouquet/proposal projects/miss-dior-blooming-bouquet/proposal
title: Offre commerciale title: Offre commerciale
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
project: project:
title: Miss Dior Blooming Bouquet title: Miss Dior Blooming Bouquet
uri: projects/miss-dior-blooming-bouquet uri: projects/miss-dior-blooming-bouquet
dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
file: file:
uuid: file://3vTh1tMFeFM2JxaN uuid: file://3vTh1tMFeFM2JxaN
url: file://3vTh1tMFeFM2JxaN url: >
position: http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf
pageIndex: 1
x: "60.110185093015"
y: "44.594594594595"
replies: [ ]
text: test text: test
author: author:
name: Adrien Payet name: Adrien Payet
email: adrien.payet@outlook.com email: adrien.payet@outlook.com
uuid: user://WWjXgPWk uuid: user://WWjXgPWk
role: admin role: admin
date: 2024-11-28T16:30:56+01:00 date: 2024-12-18T16:20:04+01:00
id: m41h238q id: 6dbb6d56-a6b7-467b-8341-3d8112a73684
position:
pageIndex: 1
x: "73.3181571571"
y: "27.272727272727"
type: comment type: comment
isRead: false replies: [ ]
- -
location: location:
page: page:
uri: > uri: >
projects/miss-dior-blooming-bouquet/proposal projects/miss-dior-blooming-bouquet/proposal
title: Offre commerciale title: Offre commerciale
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
project: project:
title: Miss Dior Blooming Bouquet title: Miss Dior Blooming Bouquet
uri: projects/miss-dior-blooming-bouquet uri: projects/miss-dior-blooming-bouquet
dialogUri: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
file: file:
uuid: file://3vTh1tMFeFM2JxaN uuid: file://3vTh1tMFeFM2JxaN
url: file://3vTh1tMFeFM2JxaN url: >
http://localhost:8888/media/pages/projects/miss-dior-blooming-bouquet/proposal/788ddebfe3-1731941917/des-textos-revelent-comment-bfm-sest-mise-au-service-de-sarkozy-le-boss.pdf
text: est
author:
name: Adrien Payet
email: adrien.payet@outlook.com
uuid: user://WWjXgPWk
role: admin
date: 2024-12-18T16:23:42+01:00
id: 5b2d93f9-fc44-4a69-955a-bf282fba8966
position: position:
pageIndex: 1 pageIndex: 1
x: "26.098441098196" x: '43.56742057598'
y: "64.864864864865" y: '65.340909090909'
replies: [ ]
text: Nouveau commentaire
author:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-12-04T15:00:15+01:00
id: m49ygks2
type: comment type: comment
isRead: false
-
location:
page:
uri: >
projects/miss-dior-blooming-bouquet/proposal
title: Offre commerciale
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
project:
title: Miss Dior Blooming Bouquet
uri: projects/miss-dior-blooming-bouquet
file:
uuid: file://3vTh1tMFeFM2JxaN
url: file://3vTh1tMFeFM2JxaN
position:
pageIndex: 1
x: "64.481172808783"
y: "76.447876447876"
replies: [ ] replies: [ ]
text: encore un commentaire
author:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-12-04T15:03:53+01:00
id: m49yl8zc
type: comment
isRead: false
-
location:
page:
uri: >
projects/miss-dior-blooming-bouquet/proposal
title: Offre commerciale
href: '/projects/miss-dior-blooming-bouquet?dialog=proposal&fileIndex=0'
project:
title: Miss Dior Blooming Bouquet
uri: projects/miss-dior-blooming-bouquet
file:
uuid: file://3vTh1tMFeFM2JxaN
url: file://3vTh1tMFeFM2JxaN
position:
pageIndex: 1
x: '29.786457814876'
y: '83.397683397683'
replies: [ ]
text: et encore un
author:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-12-04T15:05:10+01:00
id: m49ymwuw
type: comment
isRead: false
---- ----

View file

@ -1,13 +1,14 @@
<?php <?php
namespace adrienpayet\D2P\data\location; namespace adrienpayet\D2P\data\location;
use Kirby;
class FileDetails class FileDetails
{ {
public string $uuid; public string $uuid;
public string $url; public string $url;
public function __construct(array $data) public function __construct(Kirby\Cms\File $data)
{ {
$this->uuid = (string) $data->uuid(); $this->uuid = (string) $data->uuid();
$this->url = (string) $data->url(); $this->url = (string) $data->url();

View file

@ -3,7 +3,14 @@
F::loadClasses([ F::loadClasses([
'adrienpayet\\comments\\BaseComment' => __DIR__ . '/src/BaseComment.php', 'adrienpayet\\comments\\BaseComment' => __DIR__ . '/src/BaseComment.php',
'adrienpayet\\comments\\Comment' => __DIR__ . '/src/Comment.php', 'adrienpayet\\comments\\Comment' => __DIR__ . '/src/Comment.php',
'adrienpayet\\comments\\Reply' => __DIR__ . '/src/Reply.php' 'adrienpayet\\comments\\Reply' => __DIR__ . '/src/Reply.php',
'adrienpayet\\D2P\\data\\Position' => __DIR__ . '/../classes/Position.php',
'adrienpayet\\D2P\data\Author' => __DIR__ . '/../classes/Author.php',
'adrienpayet\\D2P\\data\\location\\Location' => __DIR__ . '/../classes/location/Location.php',
'adrienpayet\\D2P\\data\\location\\PageDetails' => __DIR__ . '/../classes/location/PageDetails.php',
'adrienpayet\\D2P\\data\\location\\ProjectDetails' => __DIR__ . '/../classes/location/ProjectDetails.php',
'adrienpayet\\D2P\\data\\location\\FileDetails' => __DIR__ . '/../classes/location/FileDetails.php',
]); ]);
Kirby::plugin('adrienpayet/kirby4-comments', [ Kirby::plugin('adrienpayet/kirby4-comments', [

View file

@ -9,38 +9,42 @@ return [
$json = file_get_contents('php://input'); $json = file_get_contents('php://input');
$data = json_decode($json); $data = json_decode($json);
$parsedUrl = parse_url($data->path); $parsedUrl = parse_url($data->dialogUri);
$query = $parsedUrl['query'] ?? null; $query = $parsedUrl['query'] ?? null;
parse_str($query, $queryParams); parse_str($query, $queryParams);
$stepSlug = $queryParams['dialog'] ?? null; $stepSlug = $queryParams['dialog'] ?? null;
$targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path']; $targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path'];
$project = page($parsedUrl['path']);
$page = page($targetPageUri); $page = page($targetPageUri);
$file = $page->file($data->fileName); $file = $page->file($data->fileName);
$user = kirby()->user($data->userUuid); $user = kirby()->user($data->userUuid);
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
$data = [ $commentData = [
'href' => $data->path, "location" => [
'page' => $page, "page" => $page,
'file' => $file, "project" => $project,
'position' => [ "dialogUri" => $data->dialogUri,
'pageIndex' => $data->position->pageIndex, "file" => $file
'x' => $data->position->x,
'y' => $data->position->y
], ],
'replies' => [], "position" => [
'text' => $data->text, "pageIndex" => $data->position->pageIndex,
'author' => $user, "x" => $data->position->x,
'date' => (string) $data->date, "y" => $data->position->y
'id' => $data->id, ],
'type' => 'comment' "date" => (string) $data->date,
"text" => $data->text,
"author" => kirby()->user(),
"id" => Str::uuid(),
"type" => "comment",
]; ];
$newComment = new Comment($data); $user->sendNotification($project, $commentData);
$newComment = new Comment($commentData);
$comments[] = $newComment->toArray(); $comments[] = $newComment->toArray();
@ -51,7 +55,7 @@ return [
echo json_encode(getFileData($newFile)); echo json_encode(getFileData($newFile));
try { try {
$user->sendNotification($page->parent(), $newComment->toArray()); $user->sendNotification($project, $commentData);
} catch (\Throwable $th) { } catch (\Throwable $th) {
echo json_encode([ echo json_encode([
"error" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(), "error" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(),

View file

@ -1,40 +1,32 @@
<?php <?php
namespace adrienpayet\comments; namespace adrienpayet\comments;
use adrienpayet\D2P\data\location\Location;
use adrienpayet\D2P\data\Author;
class BaseComment { class BaseComment {
protected $href; protected string $type;
protected $location; protected Location $location;
protected $position; protected string $text;
protected $replies; protected Author $author;
protected $text; protected string $date;
protected $author; protected string $id;
protected $date;
protected $id;
protected $type;
protected $isRead;
public function __construct($data) { public function __construct($data) {
$this->type = $data["type"];
$this->location = new Location($data["location"]); $this->location = new Location($data["location"]);
$this->text = $data["text"]; $this->text = $data["text"];
$this->author = new Author($data["author"]); $this->author = new Author($data["author"]);
$this->date = $data["date"]; $this->date = $data["date"];
$this->id = $data["id"]; $this->id = $data["id"];
$this->isRead = "false";
} }
public function toArray() { public function toArray() {
return [ return [
'location' => $this->location, "location" => $this->location->toArray(),
'position' => $this->position, "text" => $this->text,
'replies' => $this->replies, "author" => $this->author->toArray(),
'text' => $this->text, "date" => $this->date,
'author' => $this->author, "id" => $this->id,
'date' => $this->date,
'id' => $this->id,
'type' => $this->type,
'isRead' => $this->isRead
]; ];
} }
} }

View file

@ -1,23 +1,26 @@
<?php <?php
namespace adrienpayet\comments; namespace adrienpayet\comments;
use adrienpayet\D2P\data\Position;
class Comment extends BaseComment class Comment extends BaseComment
{ {
protected $position; protected ?Position $position = null;
protected string $type = "comment";
protected array $replies = [];
public function __construct($data) { public function __construct($data) {
parent::__construct($data); parent::__construct($data);
$this->position = $data['position'] ?? null; if (isset($data["position"])) {
} $this->position = new Position($data['position']);
}
public function position() {
return $this->position;
} }
public function toArray() { public function toArray() {
$array = parent::toArray(); $array = parent::toArray();
$array['position'] = $this->position; $array['position'] = $this->position;
$array['type'] = $this->type;
$array['replies'] = $this->replies;
return $array; return $array;
} }

View file

@ -12,7 +12,7 @@ class Notification
protected Author $author; protected Author $author;
protected string $date; protected string $date;
protected string $id; protected string $id;
protected string $isRead; protected string $isRead = "false";
protected ?Position $position = null; protected ?Position $position = null;
@ -23,11 +23,6 @@ class Notification
$this->author = new Author($data["author"]); $this->author = new Author($data["author"]);
$this->date = $data["date"]; $this->date = $data["date"];
$this->id = $data["id"]; $this->id = $data["id"];
$this->isRead = "false";
if ($data["type"] === "comment") {
$this->position = new Position($data["position"]);
}
} }
public function toArray() { public function toArray() {
@ -40,9 +35,6 @@ class Notification
"id" => $this->id, "id" => $this->id,
"isRead" => $this->isRead, "isRead" => $this->isRead,
]; ];
if ($this->type === "comment") {
$array["position"] = $this->position->toArray();
}
return $array; return $array;
} }

View file

@ -16,27 +16,26 @@ use adrienpayet\notifications\Notification;
*/ */
return function ($project, $notificationData) { return function ($project, $notificationData) {
$recipients = $project->managers()->without($this); $recipients = $project->managers()->without($this);
if ($recipients->isEmpty()) return; if ($recipients->isEmpty()) return;
$notificationData['isRead'] = false; $newNotification = new Notification($notificationData);
foreach ($recipients as $otherUser) { foreach ($recipients as $otherUser) {
try { try {
$notifications = $otherUser->notifications()->isNotEmpty() $notifications = $otherUser->notifications()->isNotEmpty()
? Yaml::decode($otherUser->notifications()->value()) ? Yaml::decode($otherUser->notifications()->value())
: []; : [];
$newNotification = new Notification($notificationData); $notifications[] = $newNotification->toArray();
$notifications[] = $newNotification->toArray();
$otherUser->update([ $otherUser->update([
'notifications' => $notifications 'notifications' => $notifications
]); ]);
} catch (\Throwable $th) { } catch (\Throwable $th) {
error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage()); error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage());
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
} }
} }
}; };

View file

@ -178,7 +178,7 @@ function handleSubmit(event = null) {
} }
const date = dayjs().format(); const date = dayjs().format();
const newComment = { const newComment = {
path: route.fullPath, dialogUri: route.fullPath,
fileName: openedFile ? openedFile.value.name : false, fileName: openedFile ? openedFile.value.name : false,
userUuid: user.uuid, userUuid: user.uuid,
text: draftComment.value.text, text: draftComment.value.text,

View file

@ -45,6 +45,8 @@ watch(isCommentsOpen, (newVal) => {
}); });
watch(openedFile, (newVal) => { watch(openedFile, (newVal) => {
if (!location.href.includes("virtual-sample")) return;
isViewerDisabled.value = true; isViewerDisabled.value = true;
setTimeout(() => { setTimeout(() => {

View file

@ -9,7 +9,11 @@
> >
<span id="back-to-project">Retour au projet</span> <span id="back-to-project">Retour au projet</span>
</router-link> </router-link>
<button class="btn | ml-auto" @click="validate"> <button
class="btn | ml-auto"
@click="validate"
v-if="page.content.isvalidated != 'true'"
>
Valider et envoyer le brief Valider et envoyer le brief
</button> </button>
</header> </header>