New apps, version and all notification count and read issue solved. #2yrpaz9
This commit is contained in:
parent
2f99a5e5a0
commit
00f2a607e6
@ -27,12 +27,25 @@ class Notifications extends Component
|
|||||||
return view('livewire.menu.notifications');
|
return view('livewire.menu.notifications');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function markRead($notification_id)
|
public function markRead($type, $notification_id, $message = true)
|
||||||
{
|
{
|
||||||
$notification = DatabaseNotification::find($notification_id);
|
switch ($type) {
|
||||||
$data = $notification->getAttribute('data');
|
case 'updates':
|
||||||
|
$this->markUpdateRead($notification_id);
|
||||||
|
break;
|
||||||
|
case 'new-apps':
|
||||||
|
$this->markNewAppRead($notification_id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$notification = DatabaseNotification::find($notification_id);
|
||||||
|
$data = $notification->getAttribute('data');
|
||||||
|
|
||||||
$notification->markAsRead();
|
$notification->markAsRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $message) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$type = isset($data['file_name']) ?: trans('general.export');
|
$type = isset($data['file_name']) ?: trans('general.export');
|
||||||
|
|
||||||
@ -44,10 +57,10 @@ class Notifications extends Component
|
|||||||
|
|
||||||
public function markReadAll()
|
public function markReadAll()
|
||||||
{
|
{
|
||||||
$notifications = user()->unreadNotifications;
|
$notifications = $this->getNotifications();
|
||||||
|
|
||||||
foreach ($notifications as $notification) {
|
foreach ($notifications as $notification) {
|
||||||
$notification->markAsRead();
|
$this->markRead($notification->type, $notification->id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dispatchBrowserEvent('mark-read-all', [
|
$this->dispatchBrowserEvent('mark-read-all', [
|
||||||
@ -56,6 +69,25 @@ class Notifications extends Component
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function markUpdateRead($notification_id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function markNewAppRead($notification_id)
|
||||||
|
{
|
||||||
|
$notifications = $this->getNotifications();
|
||||||
|
|
||||||
|
foreach ($notifications as $notification) {
|
||||||
|
if ($notification->id == $notification_id) {
|
||||||
|
setting()->set('notifications.' . $notification->notifiable_id . '.' . $notification->data['alias'], '1');
|
||||||
|
|
||||||
|
setting()->save();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getNotifications(): array
|
public function getNotifications(): array
|
||||||
{
|
{
|
||||||
$notifications = new \stdClass();
|
$notifications = new \stdClass();
|
||||||
|
@ -65,7 +65,8 @@ class ShowInNotifications
|
|||||||
$new->notifiable_id = user()->id;
|
$new->notifiable_id = user()->id;
|
||||||
$new->data = [
|
$new->data = [
|
||||||
'title' => $new_app->name,
|
'title' => $new_app->name,
|
||||||
'description' => $new_app->alias,
|
'description' => '', // $new_app->message,
|
||||||
|
'alias' => $new_app->alias,
|
||||||
];
|
];
|
||||||
$new->created_at = $new_app->started_at->date;
|
$new->created_at = $new_app->started_at->date;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace App\View\Components\Layouts\Admin;
|
namespace App\View\Components\Layouts\Admin;
|
||||||
|
|
||||||
use App\Abstracts\View\Component;
|
use App\Abstracts\View\Component;
|
||||||
use App\Utilities\Versions;
|
use App\Events\Menu\NotificationsCreated;
|
||||||
|
|
||||||
class Menu extends Component
|
class Menu extends Component
|
||||||
{
|
{
|
||||||
@ -21,10 +21,7 @@ class Menu extends Component
|
|||||||
{
|
{
|
||||||
$this->companies = $this->getCompanies();
|
$this->companies = $this->getCompanies();
|
||||||
|
|
||||||
$version_update = Versions::getUpdates();
|
$this->notification_count = $this->getNotificationCount();
|
||||||
|
|
||||||
$this->notification_count = user()->unreadNotifications->count();
|
|
||||||
$this->notification_count += count($version_update);
|
|
||||||
|
|
||||||
return view('components.layouts.admin.menu');
|
return view('components.layouts.admin.menu');
|
||||||
}
|
}
|
||||||
@ -39,4 +36,16 @@ class Menu extends Component
|
|||||||
|
|
||||||
return $companies;
|
return $companies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNotificationCount()
|
||||||
|
{
|
||||||
|
// Get nofitications
|
||||||
|
$notifications = new \stdClass();
|
||||||
|
$notifications->notifications = [];
|
||||||
|
$notifications->keyword = '';
|
||||||
|
|
||||||
|
event(new NotificationsCreated($notifications));
|
||||||
|
|
||||||
|
return $notifications->notifications->count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,15 +63,16 @@
|
|||||||
'flex items-center menu-button justify-center w-8 h-8 mb-2.5 relative cursor-pointer js-menu-toggles',
|
'flex items-center menu-button justify-center w-8 h-8 mb-2.5 relative cursor-pointer js-menu-toggles',
|
||||||
'animate-vibrate' => $notification_count,
|
'animate-vibrate' => $notification_count,
|
||||||
])
|
])
|
||||||
data-menu="notifications-menu">
|
data-menu="notifications-menu"
|
||||||
|
>
|
||||||
<span id="menu-notification-icon" name="notifications" class="material-icons-outlined text-purple text-2xl">notifications</span>
|
<span id="menu-notification-icon" name="notifications" class="material-icons-outlined text-purple text-2xl">notifications</span>
|
||||||
|
|
||||||
@if ($notification_count)
|
|
||||||
<span data-notification-count class="w-2 h-2 absolute top-2 right-2 inline-flex items-center justify-center p-2.5 text-xs text-white font-bold leading-none transform translate-x-1/2 -translate-y-1/2 bg-orange rounded-full">
|
|
||||||
{{ $notification_count }}
|
|
||||||
</span>
|
|
||||||
@endif
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@if ($notification_count)
|
||||||
|
<span data-notification-count class="w-2 h-2 absolute top-2 right-2 inline-flex items-center justify-center p-2.5 text-xs text-white font-bold leading-none transform translate-x-1/2 -translate-y-1/2 bg-orange rounded-full">
|
||||||
|
{{ $notification_count }}
|
||||||
|
</span>
|
||||||
|
@endif
|
||||||
</x-tooltip>
|
</x-tooltip>
|
||||||
@endcan
|
@endcan
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($notifications)
|
@if ($notifications)
|
||||||
<div class="flex justify-end mt-1">
|
<div class="flex justify-end mt-1 mb-3">
|
||||||
<x-tooltip id="notification-all" placement="right" message="Mark as All Read">
|
<x-tooltip id="notification-all" placement="top" message="Mark as All Read">
|
||||||
<button type="button" wire:click="markReadAll()">
|
<button type="button" wire:click="markReadAll()">
|
||||||
<span id="menu-notification-read-all" class="material-icons text-lg text-purple">done_all</span>
|
<span id="menu-notification-read-all" class="material-icons text-lg text-purple">done_all</span>
|
||||||
</button>
|
</button>
|
||||||
@ -30,9 +30,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if ($notification->type != 'updates')
|
@if ($notification->type != 'updates')
|
||||||
<button type="button" wire:click="markRead('{{ $notification->id }}')">
|
<x-tooltip id="notification-{{ $notification->id }}" placement="top" message="Clear Notification">
|
||||||
<span id="menu-notification-mark-read" class="material-icons text-lg text-purple">check_circle_outline</span>
|
<button type="button" wire:click="markRead('{{ $notification->type }}', '{{ $notification->id }}')">
|
||||||
</button>
|
<span id="menu-notification-mark-read" class="material-icons text-lg text-purple">check_circle_outline</span>
|
||||||
|
</button>
|
||||||
|
</x-tooltip>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user