Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suport for a new navbar notification menu item. (#888)
* [MenuItems/NotificationLink]: Add suport for a new navbar notification link item. * [Components/Layout]: Fix code style. * [NavbarNotificationLink]: Add improvements to use update-cfg attribute and setup update url with route. * Fix code style * [NavbarNotificationLink]: Be more strict when parsing the url for notification updates. * [NavbarNotificationLink]: Fix code style. * [NavbarNotification]: Change component name and add support to dropdown mode. * [NavbarNotification]: Rename the menu item type and add some minor fixes. * [NavbarNotification]: Fix comment.
- Loading branch information
Showing
6 changed files
with
592 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
resources/views/components/layout/navbar-notification.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
{{-- Navbar notification --}} | ||
|
||
<li class="{{ $makeListItemClass() }}" id="{{ $id }}"> | ||
|
||
{{-- Link --}} | ||
<a @if($enableDropdownMode) href="" @endif {{ $attributes->merge($makeAnchorDefaultAttrs()) }}> | ||
|
||
{{-- Icon --}} | ||
<i class="{{ $makeIconClass() }}"></i> | ||
|
||
{{-- Badge --}} | ||
<span class="{{ $makeBadgeClass() }}">{{ $badgeLabel }}</span> | ||
|
||
</a> | ||
|
||
{{-- Dropdown Menu --}} | ||
@if($enableDropdownMode) | ||
|
||
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right"> | ||
|
||
{{-- Custom dropdown content provided by external source --}} | ||
<div class="adminlte-dropdown-content"></div> | ||
|
||
{{-- Dropdown divider --}} | ||
<div class="dropdown-divider"></div> | ||
|
||
{{-- Dropdown footer with link --}} | ||
<a href="{{ $attributes->get('href') }}" class="dropdown-item dropdown-footer"> | ||
@isset($dropdownFooterLabel) | ||
{{ $dropdownFooterLabel }} | ||
@else | ||
<i class="fas fa-lg fa-search-plus"></i> | ||
@endisset | ||
</a> | ||
|
||
</div> | ||
|
||
@endif | ||
|
||
</li> | ||
|
||
{{-- If required, update the notification periodically --}} | ||
|
||
@if (! is_null($makeUpdateUrl()) && $makeUpdatePeriod() > 0) | ||
@push('js') | ||
<script> | ||
$(() => { | ||
// Method to get new notification data from the configured url. | ||
let updateNotification = (nLink) => | ||
{ | ||
// Make an ajax call to the configured url. The response should be | ||
// an object with the new data. The supported properties are: | ||
// 'label', 'label_color', 'icon_color' and 'dropdown'. | ||
$.ajax({ | ||
url: "{{ $makeUpdateUrl() }}" | ||
}) | ||
.done((data) => { | ||
nLink.update(data); | ||
}) | ||
.fail(function(jqXHR, textStatus, errorThrown) { | ||
console.log(jqXHR, textStatus, errorThrown); | ||
}); | ||
}; | ||
// First load of the notification data. | ||
let nLink = new _AdminLTE_NavbarNotification("{{ $id }}"); | ||
updateNotification(nLink); | ||
// Periodically update the notification. | ||
setInterval(updateNotification, {{ $makeUpdatePeriod() }}, nLink); | ||
}) | ||
</script> | ||
@endpush | ||
@endif | ||
|
||
{{-- Register Javascript utility class for this component --}} | ||
|
||
@once | ||
@push('js') | ||
<script> | ||
class _AdminLTE_NavbarNotification { | ||
/** | ||
* Constructor. | ||
* | ||
* target: The id of the target notification link. | ||
*/ | ||
constructor(target) | ||
{ | ||
this.target = target; | ||
} | ||
/** | ||
* Update the notification link. | ||
* | ||
* data: An object with the new data. | ||
*/ | ||
update(data) | ||
{ | ||
// Check if target and data exists. | ||
let t = $(`li#${this.target}`); | ||
if (t.length <= 0 || ! data) { | ||
return; | ||
} | ||
let badge = t.find(".navbar-badge"); | ||
let icon = t.find(".nav-link > i"); | ||
let dropdown = t.find(".adminlte-dropdown-content"); | ||
// Update the badge label. | ||
if (data.label && data.label > 0) { | ||
badge.html(data.label); | ||
} else { | ||
badge.empty(); | ||
} | ||
// Update the badge color. | ||
if (data.label_color) { | ||
badge.removeClass((idx, classes) => { | ||
return (classes.match(/(^|\s)badge-\S+/g) || []).join(' '); | ||
}).addClass(`badge-${data.label_color} badge-pill`); | ||
} | ||
// Update the icon color. | ||
if (data.icon_color) { | ||
icon.removeClass((idx, classes) => { | ||
return (classes.match(/(^|\s)text-\S+/g) || []).join(' '); | ||
}).addClass(`text-${data.icon_color}`); | ||
} | ||
// Update the dropdown content. | ||
if (data.dropdown && dropdown.length > 0) { | ||
dropdown.html(data.dropdown); | ||
} | ||
} | ||
} | ||
</script> | ||
@endpush | ||
@endonce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.