project creation request notification working
This commit is contained in:
parent
c750001a2c
commit
c75c5e1d8a
7 changed files with 93 additions and 13 deletions
|
|
@ -7,6 +7,8 @@ return [
|
||||||
$json = file_get_contents('php://input');
|
$json = file_get_contents('php://input');
|
||||||
$data = json_decode($json);
|
$data = json_decode($json);
|
||||||
|
|
||||||
|
$user = kirby()->user();
|
||||||
|
|
||||||
$client = kirby()->user()->client()->toPage()->uuid();
|
$client = kirby()->user()->client()->toPage()->uuid();
|
||||||
|
|
||||||
$projectData = [
|
$projectData = [
|
||||||
|
|
@ -23,7 +25,24 @@ return [
|
||||||
|
|
||||||
$projects = page("projects");
|
$projects = page("projects");
|
||||||
try {
|
try {
|
||||||
$projects->createChild($projectData);
|
$newProject = $projects->createChild($projectData);
|
||||||
|
|
||||||
|
$date = new DateTime();
|
||||||
|
$formattedDate = $date->format(DateTime::ISO8601);
|
||||||
|
|
||||||
|
$notificationData = [
|
||||||
|
"location" => [
|
||||||
|
"page" => $newProject
|
||||||
|
],
|
||||||
|
"date" => (string) $formattedDate,
|
||||||
|
"text" => nl2br(esc($data->details)),
|
||||||
|
"author" => $user,
|
||||||
|
"id" => Str::uuid(),
|
||||||
|
"type" => "project-request",
|
||||||
|
];
|
||||||
|
|
||||||
|
$newProject->createNotification($notificationData);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"status" => "success",
|
"status" => "success",
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,12 @@ namespace adrienpayet\D2P\data\location;
|
||||||
class Location
|
class Location
|
||||||
{
|
{
|
||||||
protected PageDetails $page;
|
protected PageDetails $page;
|
||||||
// protected ?string $dialogUri = null;
|
|
||||||
// protected ProjectDetails $project;
|
|
||||||
protected ?FileDetails $file = null;
|
protected ?FileDetails $file = null;
|
||||||
protected ?array $parent = null;
|
protected ?array $parent = null;
|
||||||
|
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->page = new PageDetails($data["page"]);
|
$this->page = new PageDetails($data["page"]);
|
||||||
// $this->dialogUri = $data["dialogUri"];
|
|
||||||
// $this->project = new ProjectDetails($data["project"]);
|
|
||||||
|
|
||||||
if (isset($data['file'])) {
|
if (isset($data['file'])) {
|
||||||
$this->file = new FileDetails($data["file"]);
|
$this->file = new FileDetails($data["file"]);
|
||||||
|
|
@ -33,13 +29,8 @@ class Location
|
||||||
public function toArray() {
|
public function toArray() {
|
||||||
$array = [
|
$array = [
|
||||||
"page" => $this->page->toArray(),
|
"page" => $this->page->toArray(),
|
||||||
// "project" => $this->project->toArray(),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// if ($this->dialogUri) {
|
|
||||||
// $array["dialogUri"] = $this->dialogUri;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if ($this->file) {
|
if ($this->file) {
|
||||||
$array["file"] = $this->file;
|
$array["file"] = $this->file;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class PageDetails
|
||||||
return [
|
return [
|
||||||
"uuid" => (string) $this->page->uuid(),
|
"uuid" => (string) $this->page->uuid(),
|
||||||
"template" => (string) $this->page->template(),
|
"template" => (string) $this->page->template(),
|
||||||
|
"panelUrl" => (string) $this->page->panel()->url(),
|
||||||
"uri" => (string) $this->page->uri(),
|
"uri" => (string) $this->page->uri(),
|
||||||
"title" => (string) $this->page->title(),
|
"title" => (string) $this->page->title(),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ function getProjectData($project) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$children = $kirby->user()->role() == "admin" ? $page->children()->map(fn($project) => getProjectData($project))->values() : $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values();
|
$children = $kirby->user()->role() == "admin" ? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project))->values() : $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
throw new Exception($th->getMessage() . " line " . $th->getLine(), 1);
|
throw new Exception($th->getMessage() . " line " . $th->getLine(), 1);
|
||||||
$children = [];
|
$children = [];
|
||||||
|
|
|
||||||
46
src/components/notifications/ProjectRequest.vue
Normal file
46
src/components/notifications/ProjectRequest.vue
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
<template>
|
||||||
|
<article
|
||||||
|
v-if="useUserStore.role !== 'client'"
|
||||||
|
class="notification | bg-white rounded-lg | p-16 | flow"
|
||||||
|
data-type="project-request"
|
||||||
|
>
|
||||||
|
<header>
|
||||||
|
<p class="flex">
|
||||||
|
<strong
|
||||||
|
class="notification__type | font-medium text-primary"
|
||||||
|
data-icon="comment"
|
||||||
|
>Demande de création de projet</strong
|
||||||
|
>
|
||||||
|
<span class="notification__client | text-grey-700"
|
||||||
|
>{{ notification.project.title }} (brouillon)</span
|
||||||
|
>
|
||||||
|
<time
|
||||||
|
datetime=""
|
||||||
|
class="notification__date | text-grey-700 | ml-auto"
|
||||||
|
>{{ formatDate(notification) }}</time
|
||||||
|
>
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
<p
|
||||||
|
v-if="notification.type"
|
||||||
|
class="notification__body | text-md font-medium | line-clamp"
|
||||||
|
v-html="
|
||||||
|
'Auteur de la demande : ' +
|
||||||
|
(notification.author.name
|
||||||
|
? notification.author.name + ' (' + notification.author.email + ')'
|
||||||
|
: notification.author.email) +
|
||||||
|
'<br>Demande : ' +
|
||||||
|
notification.text
|
||||||
|
"
|
||||||
|
></p>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { useNotificationsStore } from "../../stores/notifications";
|
||||||
|
import { useUserStore } from "../../stores/user";
|
||||||
|
|
||||||
|
const { notification } = defineProps({ notification: Object });
|
||||||
|
const { formatDate } = useNotificationsStore();
|
||||||
|
const { user } = useUserStore();
|
||||||
|
</script>
|
||||||
|
|
@ -8,6 +8,9 @@ export const useProjectsStore = defineStore("projects", () => {
|
||||||
const currentProjects = computed(() => {
|
const currentProjects = computed(() => {
|
||||||
return projects.value.filter((project) => project.status === "listed");
|
return projects.value.filter((project) => project.status === "listed");
|
||||||
});
|
});
|
||||||
|
const draftProjects = computed(() => {
|
||||||
|
return projects.value.filter((project) => project.status === "draft");
|
||||||
|
});
|
||||||
const archivedProjects = computed(() => {
|
const archivedProjects = computed(() => {
|
||||||
return projects.value.filter((project) => project.status === "unlisted");
|
return projects.value.filter((project) => project.status === "unlisted");
|
||||||
});
|
});
|
||||||
|
|
@ -23,5 +26,11 @@ export const useProjectsStore = defineStore("projects", () => {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { projects, currentProjects, archivedProjects, getProjectByUuid };
|
return {
|
||||||
|
projects,
|
||||||
|
currentProjects,
|
||||||
|
archivedProjects,
|
||||||
|
draftProjects,
|
||||||
|
getProjectByUuid,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
:is="notificationComponents[notification.type]"
|
:is="notificationComponents[notification.type]"
|
||||||
:notification="notification"
|
:notification="notification"
|
||||||
:data-status="notification.isRead ? 'read' : 'unread'"
|
:data-status="notification.isRead ? 'read' : 'unread'"
|
||||||
@click="router.push(getHref(notification))"
|
@click="handleNotificationClick(notification)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -64,6 +64,7 @@ import Comment from "../components/notifications/Comment.vue";
|
||||||
import Reply from "../components/notifications/Reply.vue";
|
import Reply from "../components/notifications/Reply.vue";
|
||||||
import Content from "../components/notifications/Content.vue";
|
import Content from "../components/notifications/Content.vue";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
|
import ProjectRequest from "../components/notifications/ProjectRequest.vue";
|
||||||
|
|
||||||
dayjs.locale("fr");
|
dayjs.locale("fr");
|
||||||
|
|
||||||
|
|
@ -95,6 +96,7 @@ const notificationComponents = {
|
||||||
comment: Comment,
|
comment: Comment,
|
||||||
"comment-reply": Reply,
|
"comment-reply": Reply,
|
||||||
content: Content,
|
content: Content,
|
||||||
|
"project-request": ProjectRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
const sortedNotifications = computed(() => {
|
const sortedNotifications = computed(() => {
|
||||||
|
|
@ -123,6 +125,14 @@ function readAll() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
|
function handleNotificationClick(notification) {
|
||||||
|
const href = getHref(notification);
|
||||||
|
if (href.startsWith("http")) {
|
||||||
|
window.open(href, "_blank");
|
||||||
|
} else {
|
||||||
|
router.push(href);
|
||||||
|
}
|
||||||
|
}
|
||||||
function getHref(notification) {
|
function getHref(notification) {
|
||||||
const uri = notification.location.page.uri;
|
const uri = notification.location.page.uri;
|
||||||
|
|
||||||
|
|
@ -138,6 +148,10 @@ function getHref(notification) {
|
||||||
return notification.project.uri + "?dialog=virtual-sample&comments=true";
|
return notification.project.uri + "?dialog=virtual-sample&comments=true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notification.location.page.panelurl) {
|
||||||
|
return notification.location.page.panelurl;
|
||||||
|
}
|
||||||
|
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue