new: [layout:sidebar] Notifications in the sidebar
parent
d1cf408163
commit
a77e29fa38
|
@ -559,7 +559,6 @@ class ACLComponent extends Component
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$menu[$group][$subMenuElementName]['children'] = array_values($menu[$group][$subMenuElementName]['children']);
|
|
||||||
if (empty($menu[$group][$subMenuElementName]['children'])) {
|
if (empty($menu[$group][$subMenuElementName]['children'])) {
|
||||||
unset($subMenu[$subMenuElementName]);
|
unset($subMenu[$subMenuElementName]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,13 +78,13 @@ class Sidemenu {
|
||||||
'icon' => $this->iconTable['Inbox'],
|
'icon' => $this->iconTable['Inbox'],
|
||||||
'url' => '/inbox/index',
|
'url' => '/inbox/index',
|
||||||
'children' => [
|
'children' => [
|
||||||
'index' => [
|
'inbox' => [
|
||||||
'url' => '/inbox/index',
|
'url' => '/inbox/index',
|
||||||
'label' => __('Inbox')
|
'label' => __('Inbox'),
|
||||||
],
|
],
|
||||||
'outbox' => [
|
'outbox' => [
|
||||||
'url' => '/outbox/index',
|
'url' => '/outbox/index',
|
||||||
'label' => __('Outbox')
|
'label' => __('Outbox'),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
|
@ -111,6 +111,7 @@ class InboxTable extends AppTable
|
||||||
'datetime' => $notification->created,
|
'datetime' => $notification->created,
|
||||||
'variant' => 'warning',
|
'variant' => 'warning',
|
||||||
'_useModal' => true,
|
'_useModal' => true,
|
||||||
|
'_sidebarId' => 'inbox',
|
||||||
]))->get();
|
]))->get();
|
||||||
}
|
}
|
||||||
return $allNotifications;
|
return $allNotifications;
|
||||||
|
|
|
@ -14,6 +14,8 @@ class Notification
|
||||||
public $icon = 'exclamation-circle';
|
public $icon = 'exclamation-circle';
|
||||||
public $variant = 'primary';
|
public $variant = 'primary';
|
||||||
public $datetime = null;
|
public $datetime = null;
|
||||||
|
public $_useModal = false;
|
||||||
|
public $_sidebarId = null;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $text, array $router, $options = [])
|
public function __construct(string $text, array $router, $options = [])
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
<?= $this->element('layouts/sidebar/category', ['label' => $category]) ?>
|
<?= $this->element('layouts/sidebar/category', ['label' => $category]) ?>
|
||||||
<?php foreach ($categorized as $parentName => $parent) : ?>
|
<?php foreach ($categorized as $parentName => $parent) : ?>
|
||||||
<?= $this->element('layouts/sidebar/entry', [
|
<?= $this->element('layouts/sidebar/entry', [
|
||||||
|
'parentName' => $parentName,
|
||||||
'parent' => $parent,
|
'parent' => $parent,
|
||||||
])
|
])
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -26,23 +26,70 @@
|
||||||
$hasActiveChild = true;
|
$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' : '' ?>">
|
<li class="<?= !empty($children) ? 'parent collapsed' : '' ?>">
|
||||||
<a
|
<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) ?>"
|
href="<?= h($url) ?>"
|
||||||
<?= !empty($children) ? 'data-bs-toggle="collapse"' : '' ?>
|
<?= !empty($children) ? 'data-bs-toggle="collapse"' : '' ?>
|
||||||
<?= $hasActiveChild ? 'aria-expanded="true"' : '' ?>
|
<?= $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>
|
<span class="text"><?= h($label) ?></span>
|
||||||
|
<?php
|
||||||
|
if (empty($children) && $hasNotification) {
|
||||||
|
echo $this->Bootstrap->badge([
|
||||||
|
'text' => $notificationAmount,
|
||||||
|
'class' => 'ms-auto',
|
||||||
|
'variant' => $notificationVariant,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
</a>
|
</a>
|
||||||
<?php if (!empty($children)): ?>
|
<?php if (!empty($children)): ?>
|
||||||
<?= $this->element('layouts/sidebar/sub-menu', [
|
<?= $this->element('layouts/sidebar/sub-menu', [
|
||||||
'seed' => $seed,
|
'seed' => $seed,
|
||||||
'children' => $children,
|
'children' => $children,
|
||||||
'open' => $hasActiveChild
|
'open' => $hasActiveChild,
|
||||||
]);
|
]);
|
||||||
?>
|
?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<ul id="<?= $seed ?>" class="sub-menu collapse <?= !empty($open) ? 'show' : '' ?>">
|
<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', [
|
<?= $this->element('layouts/sidebar/entry', [
|
||||||
|
'parentName' => $childName,
|
||||||
'parent' => $child,
|
'parent' => $child,
|
||||||
])
|
])
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -354,6 +354,8 @@ ul.sidebar-elements li.parent > a.sidebar-link::before {
|
||||||
font-family: 'Font Awesome 5 Free';
|
font-family: 'Font Awesome 5 Free';
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
|
order: 6 !important;
|
||||||
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul.sidebar-elements li.parent > a.sidebar-link:not(.collapsed)::before {
|
ul.sidebar-elements li.parent > a.sidebar-link:not(.collapsed)::before {
|
||||||
|
|
Loading…
Reference in New Issue