New apps notification hide feature..

This commit is contained in:
Cüneyt Şentürk 2021-06-27 16:29:01 +03:00
parent 584c23834b
commit 7589a22dbb
3 changed files with 156 additions and 15 deletions

View File

@ -34,7 +34,19 @@ class Notifications extends Controller
$notification->markAsRead();
}
$message = trans('messages.success.duplicated', ['type' => trans_choice('general.items', 1)]);
// Hide New Apps Notifications
$module_notifications = $this->getNotifications('new-apps' );
foreach ($module_notifications as $module_notification) {
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.name', $module_notification->name);
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.message', $module_notification->alias);
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.date', Date::now());
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.status', '0');
}
setting()->save();
$message = trans('messages.success.duplicated', ['type' => trans_choice('general.notificatinos', 1)]);
flash($message)->success();

View File

@ -2,6 +2,7 @@
namespace App\Http\Livewire\Common\Notifications;
use Date;
use App\Traits\Modules;
use Livewire\Component;
@ -9,10 +10,91 @@ class NewApps extends Component
{
use Modules;
public function markRead($alias)
{
$notifications = $this->getNotifications('new-apps' );
foreach ($notifications as $notification) {
if ($notification->alias != $alias) {
continue;
}
$readed = $notification;
}
setting()->set('notifications.'. user()->id . '.' . $alias . '.name', $readed->name);
setting()->set('notifications.'. user()->id . '.' . $alias . '.message', $readed->alias);
setting()->set('notifications.'. user()->id . '.' . $alias . '.date', Date::now());
setting()->set('notifications.'. user()->id . '.' . $alias . '.status', '0');
setting()->save();
$this->dispatchBrowserEvent('mark-read', [
'type' => 'new-apps',
'message' => trans('notifications.messages.mark_read', ['type' => $notification->name]),
]);
}
public function markReadAll()
{
$notifications = $this->getNotifications('new-apps' );
foreach ($notifications as $notification) {
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.name', $notification->name);
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.message', $notification->alias);
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.date', Date::now());
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.status', '0');
}
setting()->save();
$this->dispatchBrowserEvent('mark-read-all', [
'type' => 'new-apps',
'message' => trans('notifications.messages.mark_read_all', ['type' => trans_choice('notifications.new_apps', 2)]),
]);
}
public function render()
{
$notifications = $this->getNotifications('new-apps');
$this->clearReadNotifications($notifications);
return view('livewire.common.notifications.new-apps', compact('notifications'));
}
protected function clearReadNotifications(&$notifications)
{
$hide_notifications = setting('notifications.' . user()->id);
if (!$hide_notifications) {
return;
}
if (!$notifications) {
return;
}
$aliases = [];
// MarkRead app notification
foreach ($notifications as $index => $notification) {
$aliases[] = $notification->alias;
if (setting('notifications.' . user()->id . '.' . $notification->alias)) {
unset($notifications[$index]);
}
}
// Clear setting table missing notification
foreach ($hide_notifications as $alias => $hide_notification) {
if (in_array($alias, $aliases)) {
continue;
}
setting()->forget('notifications.' . user()->id . '.' . $alias);
setting()->save();
}
}
}

View File

@ -1,29 +1,76 @@
@if ($notifications)
<div class="accordion" id="new-apps">
<div class="card">
<div class="card-header" id="heading-new-apps" data-toggle="collapse" data-target="#collapse-new-apps" aria-expanded="true" aria-controls="collapse-new-apps">
<div class="align-items-center">
<h3 class="mb-0">
{{ trans_choice('notifications.new_apps', 2) }}
</h3>
</div>
</div>
<div class="accordion" id="new-apps">
<div class="card">
<div class="card-header" id="heading-new-apps" data-toggle="collapse" data-target="#collapse-new-apps"
aria-expanded="{{ ($notifications) ? 'true' : 'false' }}" aria-controls="collapse-new-apps">
<div class="align-items-center">
<h3 class="mb-0">
{{ trans_choice('notifications.new_apps', 2) }}
<div id="collapse-new-apps" class="collapse show" aria-labelledby="heading-new-apps" data-parent="#new-apps">
@if ($notifications)
<button type="button" class="btn btn-outline-success rounded-circle btn-icon-only btn-sm ml-2"
data-toggle="tooltip"
data-placement="right"
title="{{ trans('notifications.mark_read_all') }}"
wire:click="markReadAll()"
>
<span class="btn-inner--icon"><i class="fas fa-check-double"></i></span>
</button>
@endif
</h3>
</div>
</div>
<div id="collapse-new-apps" class="collapse{{ ($notifications) ? ' show' : '' }}" aria-labelledby="heading-new-apps" data-parent="#new-apps">
@if ($notifications)
<div class="table-responsive">
<table class="table table-flush table-hover" id="tbl-export">
<tbody>
@foreach ($notifications as $notification)
<tr class="row align-items-center border-top-1">
<td class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 text-left">
<td class="col-xs-8 col-sm-10 col-md-10 col-lg-11 col-xl-11 text-left text-wrap">
{!! $notification->message !!}
</td>
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-1 col-xl-1 text-center">
<button type="button" class="btn btn-outline-success rounded-circle btn-icon-only btn-sm"
data-toggle="tooltip"
data-placement="right"
title="{{ trans('notifications.mark_read') }}"
wire:click="markRead('{{ $notification->alias }}')"
>
<span class="btn-inner--icon"><i class="fa fa-check"></i></span>
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@else
<div class="col-xs-12 col-sm-12 mt-4 mb-4 text-center">
<small>{{ trans('general.no_records') }}</small>
</div>
@endif
</div>
</div>
@endif
</div>
@push('body_js')
<script type="text/javascript">
window.addEventListener('mark-read', event => {
if (event.detail.type == 'new-apps') {
$.notify(event.detail.message, {
type: 'success',
});
}
});
window.addEventListener('mark-read-all', event => {
if (event.detail.type == 'new-apps') {
$.notify(event.detail.message, {
type: 'success',
});
}
});
</script>
@endpush