new: [layout:sidebar] Notifications in the sidebar

pull/93/head
Sami Mokaddem 2022-02-08 17:58:30 +01:00
parent d1cf408163
commit a77e29fa38
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
8 changed files with 61 additions and 8 deletions

View File

@ -559,7 +559,6 @@ class ACLComponent extends Component
continue;
}
}
$menu[$group][$subMenuElementName]['children'] = array_values($menu[$group][$subMenuElementName]['children']);
if (empty($menu[$group][$subMenuElementName]['children'])) {
unset($subMenu[$subMenuElementName]);
}

View File

@ -78,13 +78,13 @@ class Sidemenu {
'icon' => $this->iconTable['Inbox'],
'url' => '/inbox/index',
'children' => [
'index' => [
'inbox' => [
'url' => '/inbox/index',
'label' => __('Inbox')
'label' => __('Inbox'),
],
'outbox' => [
'url' => '/outbox/index',
'label' => __('Outbox')
'label' => __('Outbox'),
],
]
],

View File

@ -111,6 +111,7 @@ class InboxTable extends AppTable
'datetime' => $notification->created,
'variant' => 'warning',
'_useModal' => true,
'_sidebarId' => 'inbox',
]))->get();
}
return $allNotifications;

View File

@ -14,6 +14,8 @@ class Notification
public $icon = 'exclamation-circle';
public $variant = 'primary';
public $datetime = null;
public $_useModal = false;
public $_sidebarId = null;
public function __construct(string $text, array $router, $options = [])

View File

@ -18,6 +18,7 @@
<?= $this->element('layouts/sidebar/category', ['label' => $category]) ?>
<?php foreach ($categorized as $parentName => $parent) : ?>
<?= $this->element('layouts/sidebar/entry', [
'parentName' => $parentName,
'parent' => $parent,
])
?>

View File

@ -26,23 +26,70 @@
$hasActiveChild = true;
}
}
$severity = [
'primary' => -1,
'info' => 0,
'warning' => 1,
'danger' => 2,
];
$hasNotification = false;
$childHasNotification = false;
$maxSeverity = -1;
$childMaxSeverity = -1;
$notificationAmount = 0;
foreach ($children as $childName => $child) { // children notification
foreach ($notifications as $notification) {
if (!empty($notification['_sidebarId']) && $notification['_sidebarId'] == $childName) {
$childHasNotification = true;
$childMaxSeverity = max($childMaxSeverity, $severity[$notification['variant']] ?? 0);
}
}
}
foreach ($notifications as $notification) { // leaf notification
if (!empty($notification['_sidebarId']) && $notification['_sidebarId'] == $parentName) {
$hasNotification = true;
$maxSeverity = max($maxSeverity, $severity[$notification['variant']] ?? 0);
$notificationAmount += 1;
}
}
$notificationVariant = array_flip($severity)[$maxSeverity];
$childNotificationVariant = array_flip($severity)[$childMaxSeverity];
?>
<li class="<?= !empty($children) ? 'parent collapsed' : '' ?>">
<a
class="sidebar-link <?= !empty($children) ? 'collapsed' : '' ?> <?= $active ? 'active' : '' ?> <?= $hasActiveChild ? 'have-active-child' : '' ?>"
class="d-flex align-items-center sidebar-link <?= !empty($children) ? 'collapsed' : '' ?> <?= $active ? 'active' : '' ?> <?= $hasActiveChild ? 'have-active-child' : '' ?>"
href="<?= h($url) ?>"
<?= !empty($children) ? 'data-bs-toggle="collapse"' : '' ?>
<?= $hasActiveChild ? 'aria-expanded="true"' : '' ?>
>
<i class="sidebar-icon <?= $this->FontAwesome->getClass($icon) ?>"></i>
<i class="position-relative sidebar-icon <?= $this->FontAwesome->getClass($icon) ?>">
<?php
if ($childHasNotification || ($hasNotification && !empty($children))) {
echo $this->Bootstrap->notificationBubble([
'variant' => $childHasNotification ? $childNotificationVariant : $notificationVariant,
]);
}
?>
</i>
<span class="text"><?= h($label) ?></span>
<?php
if (empty($children) && $hasNotification) {
echo $this->Bootstrap->badge([
'text' => $notificationAmount,
'class' => 'ms-auto',
'variant' => $notificationVariant,
]);
}
?>
</a>
<?php if (!empty($children)): ?>
<?= $this->element('layouts/sidebar/sub-menu', [
'seed' => $seed,
'children' => $children,
'open' => $hasActiveChild
'open' => $hasActiveChild,
]);
?>
<?php endif; ?>

View File

@ -3,8 +3,9 @@
?>
<ul id="<?= $seed ?>" class="sub-menu collapse <?= !empty($open) ? 'show' : '' ?>">
<?php foreach ($children as $child): ?>
<?php foreach ($children as $childName => $child): ?>
<?= $this->element('layouts/sidebar/entry', [
'parentName' => $childName,
'parent' => $child,
])
?>

View File

@ -354,6 +354,8 @@ ul.sidebar-elements li.parent > a.sidebar-link::before {
font-family: 'Font Awesome 5 Free';
font-weight: 900;
font-size: 1rem;
order: 6 !important;
margin-left: auto;
}
ul.sidebar-elements li.parent > a.sidebar-link:not(.collapsed)::before {