Toggle favorite working
This commit is contained in:
parent
5e3f4ec621
commit
4ea2871c6d
13 changed files with 300 additions and 169 deletions
|
|
@ -1,3 +1,11 @@
|
|||
Alt:
|
||||
|
||||
----
|
||||
|
||||
Favoriteforusers:
|
||||
|
||||
----
|
||||
|
||||
Description:
|
||||
|
||||
----
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
Alt:
|
||||
|
||||
----
|
||||
|
||||
Favoriteforusers: - user://WWjXgPWk
|
||||
|
||||
----
|
||||
|
||||
Favoriteforclients:
|
||||
|
||||
- page://G418qZ4ABsoWFx4i
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ accept:
|
|||
type: image
|
||||
|
||||
fields:
|
||||
alt:
|
||||
label: Texte alternatif
|
||||
type: text
|
||||
favoriteForUsers:
|
||||
label: |
|
||||
Dans les favoris des utilisateurs :
|
||||
type: users
|
||||
disabled: true
|
||||
|
|
|
|||
|
|
@ -16,89 +16,10 @@ return [
|
|||
'language' => 'fr',
|
||||
'css' => 'assets/css/panel.css',
|
||||
'favicon' => 'assets/favicons/favicon.svg',
|
||||
'menu' => [
|
||||
'site' => [
|
||||
'label' => 'Dashboard',
|
||||
'icon' => 'dashboard',
|
||||
'current' => function (string $current): bool {
|
||||
// the links of all your custom menu entries
|
||||
$links = [
|
||||
'pages/clients',
|
||||
'pages/projects',
|
||||
'pages/inspirations',
|
||||
'pages/notifications',
|
||||
'pages/events'
|
||||
];
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return
|
||||
$current === 'site' &&
|
||||
A::every($links, fn ($link) => Str::contains($path, $link) === false);
|
||||
}
|
||||
],
|
||||
'clients' => [
|
||||
'label' => 'Clients',
|
||||
'icon' => 'account',
|
||||
'link' => 'pages/clients',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/clients');
|
||||
}
|
||||
],
|
||||
'projects' => [
|
||||
'label' => 'Projets',
|
||||
'icon' => 'folder',
|
||||
'link' => 'pages/projects',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/projects');
|
||||
}
|
||||
],
|
||||
'inspirations' => [
|
||||
'label' => 'Inspirations',
|
||||
'icon' => 'images',
|
||||
'link' => 'pages/inspirations',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/inspirations');
|
||||
}
|
||||
],
|
||||
'-',
|
||||
'notifications' => [
|
||||
'label' => 'Notifications',
|
||||
'icon' => 'bell',
|
||||
'link' => 'pages/notifications',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/notifications');
|
||||
}
|
||||
],
|
||||
'events' => [
|
||||
'label' => 'Événements',
|
||||
'icon' => 'calendar',
|
||||
'link' => 'pages/events',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/events');
|
||||
}
|
||||
],
|
||||
'-',
|
||||
'users',
|
||||
'system'
|
||||
]
|
||||
'menu' => require(__DIR__ . '/menu.php'),
|
||||
],
|
||||
'routes' => [
|
||||
[
|
||||
'pattern' => '(:all)logout.php',
|
||||
'action' => function () {
|
||||
$kirby = kirby();
|
||||
$user = $kirby->user();
|
||||
$user->logout();
|
||||
session_start();
|
||||
|
||||
go($_SESSION['redirect_url']);
|
||||
|
||||
return '<html><body>logout</body></html>';
|
||||
}
|
||||
]
|
||||
require(__DIR__ . '/routes/logout.php'),
|
||||
require(__DIR__ . '/routes/toggle-favorite.php'),
|
||||
]
|
||||
];
|
||||
|
|
|
|||
71
public/site/config/menu.php
Normal file
71
public/site/config/menu.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'site' => [
|
||||
'label' => 'Dashboard',
|
||||
'icon' => 'dashboard',
|
||||
'current' => function (string $current): bool {
|
||||
// the links of all your custom menu entries
|
||||
$links = [
|
||||
'pages/clients',
|
||||
'pages/projects',
|
||||
'pages/inspirations',
|
||||
'pages/notifications',
|
||||
'pages/events'
|
||||
];
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return
|
||||
$current === 'site' &&
|
||||
A::every($links, fn ($link) => Str::contains($path, $link) === false);
|
||||
}
|
||||
],
|
||||
'clients' => [
|
||||
'label' => 'Clients',
|
||||
'icon' => 'account',
|
||||
'link' => 'pages/clients',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/clients');
|
||||
}
|
||||
],
|
||||
'projects' => [
|
||||
'label' => 'Projets',
|
||||
'icon' => 'folder',
|
||||
'link' => 'pages/projects',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/projects');
|
||||
}
|
||||
],
|
||||
'inspirations' => [
|
||||
'label' => 'Inspirations',
|
||||
'icon' => 'images',
|
||||
'link' => 'pages/inspirations',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/inspirations');
|
||||
}
|
||||
],
|
||||
'-',
|
||||
'notifications' => [
|
||||
'label' => 'Notifications',
|
||||
'icon' => 'bell',
|
||||
'link' => 'pages/notifications',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/notifications');
|
||||
}
|
||||
],
|
||||
'events' => [
|
||||
'label' => 'Événements',
|
||||
'icon' => 'calendar',
|
||||
'link' => 'pages/events',
|
||||
'current' => function (string $current): bool {
|
||||
$path = Kirby\Cms\App::instance()->path();
|
||||
return Str::contains($path, 'pages/events');
|
||||
}
|
||||
],
|
||||
'-',
|
||||
'users',
|
||||
'system'
|
||||
];
|
||||
13
public/site/config/routes/logout.php
Normal file
13
public/site/config/routes/logout.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)logout.php',
|
||||
'action' => function () {
|
||||
$kirby = kirby();
|
||||
$user = $kirby->user();
|
||||
$user->logout();
|
||||
session_start();
|
||||
|
||||
go(site()->url());
|
||||
}
|
||||
];
|
||||
33
public/site/config/routes/toggle-favorite.php
Normal file
33
public/site/config/routes/toggle-favorite.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)toggle-favorite.json',
|
||||
'method' => 'post',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$fileName = $data->fileName;
|
||||
|
||||
$page = page($data->inspirationUri);
|
||||
$file = $page->files()->find($fileName);
|
||||
|
||||
$user = Find::user($data->userUuid);
|
||||
$favoriteForUsers = $file->favoriteForUsers()->toUsers();
|
||||
|
||||
if ($favoriteForUsers->has($user)) {
|
||||
$favoriteForUsers->remove($user);
|
||||
} else {
|
||||
$favoriteForUsers->add($user);
|
||||
}
|
||||
|
||||
$array = $favoriteForUsers->toArray();
|
||||
$yaml = Data::encode($array, 'yaml');
|
||||
|
||||
$file->update([
|
||||
'favoriteForUsers' => $yaml
|
||||
]);
|
||||
|
||||
return $favoriteForUsers->toJson();
|
||||
}
|
||||
];
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
<script>
|
||||
<?php if ($kirby->user()): ?>
|
||||
const kirbyData = {
|
||||
user: {
|
||||
role: '<?= $kirby->user()->role() ?>',
|
||||
uuid: '<?= $kirby->user()->uuid() ?>',
|
||||
<?php if ($kirby->user()->role() == 'client'): ?>
|
||||
client: {
|
||||
name: '<?= $kirby->user()->client()->toPage()->title() ?>',
|
||||
|
|
@ -10,6 +12,7 @@
|
|||
<?php endif ?>
|
||||
}
|
||||
}
|
||||
<?php endif ?>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,3 +1,9 @@
|
|||
<?php snippet('header') ?>
|
||||
<div id="app"></div>
|
||||
<?php
|
||||
if ($kirby->user()) {
|
||||
echo '<div id="app"></div>';
|
||||
} else {
|
||||
go($site->panel()->url());
|
||||
}
|
||||
?>
|
||||
<?php snippet('footer') ?>
|
||||
|
|
@ -7,12 +7,16 @@ $inspirations = $page->children()->map(function ($child) {
|
|||
'new' => $child->new()->value() === "true" ? true : false,
|
||||
'date' => $child->date()->toDate('Y-MM-d'),
|
||||
'url' => $child->url(),
|
||||
'uri' => $child->uri(),
|
||||
'modified' => $child->modified('Y-MM-d'),
|
||||
'status' => $child->status(),
|
||||
'cover' => $child->cover()->toFile()->url(),
|
||||
'media' => $child->media()->toFiles()->map(function ($file) {
|
||||
return [
|
||||
'url' => $file->url()
|
||||
'url' => $file->url(),
|
||||
'ald' => $file->alt()->value(),
|
||||
'favoriteForUsers' => $file->favoriteForUsers()->value(),
|
||||
'name' => $file->filename()
|
||||
];
|
||||
})->values()
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue