New notification page..

This commit is contained in:
Cüneyt Şentürk
2021-06-19 18:16:09 +03:00
parent 856e10a2dd
commit 4687185f4a
34 changed files with 2652 additions and 43 deletions

View File

@ -18,9 +18,7 @@ class Notifications extends Controller
*/
public function index()
{
$notifications = setting('notifications');
return view('common.notifications.index', compact('notifications'));
return view('common.notifications.index');
}
/**
@ -28,11 +26,19 @@ class Notifications extends Controller
*
* @return Response
*/
public function show($path, $id)
public function readAll()
{
$notification = setting('notifications.' . $path . '.' . $id);
$notifications = user()->unreadNotifications;
return view('common.notifications.show', compact('notification'));
foreach ($notifications as $notification) {
$notification->markAsRead();
}
$message = trans('messages.success.duplicated', ['type' => trans_choice('general.items', 1)]);
flash($message)->success();
return redirect()->route('dashboard');
}
/**

View File

@ -0,0 +1,87 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Exports extends Component
{
use WithPagination;
protected $listeners = [
'refreshParent' => '$notifications',
];
public function markRead($notification_id)
{
$notification = DatabaseNotification::find($notification_id);
$data = $notification->getAttribute('data');
$notification->markAsRead();
$this->dispatchBrowserEvent('mark-read', [
'type' => 'export',
'message' => trans('notifications.messages.mark_read', ['type' => $data['file_name']]),
]);
}
public function markReadAll()
{
$notifications = $this->getNotifications();
foreach ($notifications as $notification) {
$notification->markAsRead();
}
$this->dispatchBrowserEvent('mark-read-all', [
'type' => 'export',
'message' => trans('notifications.messages.mark_read_all', ['type' => trans('general.export')]),
]);
}
public function render()
{
$limit = 5;
$notifications = $this->getNotifications($limit);
return view('livewire.common.notifications.exports', compact('notifications'));
}
protected function getNotifications($limit = false)
{
$query = user()->notifications()->unread()
->where('type', 'App\Notifications\Common\ExportCompleted')
->orWhere('type', 'App\Notifications\Common\ExportFailed');
if ($limit) {
$notifications = $query->paginate($limit);
} else {
$notifications = $query->get();
}
if ($notifications->items()) {
$items = [];
foreach ($notifications->items() as $key => $notification) {
$data = (object) $notification->getAttribute('data');
$data->notification_id = $notification->getAttribute('id');
$items[] = $data;
}
$notifications->setCollection(Collection::make($items));
}
return $notifications;
}
public function paginationView()
{
return 'vendor.livewire.default';
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use Livewire\Component;
use Livewire\WithPagination;
class Imports extends Component
{
use WithPagination;
public function render()
{
$limit = 5;
$notifications = user()->notifications()->unread()
->where('type', 'App\Notifications\Common\ImportCompleted')
->orWhere('type', 'App\Notifications\Common\ImportFailed')
->paginate($limit);
return view('livewire.common.notifications.imports', compact('notifications'));
}
public function paginationView()
{
return 'vendor.livewire.default';
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use Livewire\Component;
class NewApps extends Component
{
public function render()
{
return view('livewire.common.notifications.new-apps');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use App\Abstracts\Livewire\Document as Component;
use Livewire\WithPagination;
use Illuminate\Support\Collection;
class Recurring extends Component
{
use WithPagination;
public function render()
{
$limit = 5;
$documents = user()->notifications()->unread()->where('type', 'App\Notifications\Sale\Invoice')->paginate($limit);
$documents->setCollection(Collection::make([]));
return view('livewire.common.notifications.recurring', compact('documents'));
}
public function paginationView()
{
return 'vendor.livewire.default';
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use App\Abstracts\Livewire\Document as Component;
use App\Models\Document\Document;
use Livewire\WithPagination;
use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Reminder extends Component
{
use WithPagination;
public function markRead($notification_id)
{
$notification = DatabaseNotification::find($notification_id);
$data = $notification->getAttribute('data');
$notification->markAsRead();
$this->dispatchBrowserEvent('mark-read', [
'type' => $this->type,
'message' => trans('notifications.messages.mark_read', ['type' => $data[$this->type . '_number']]),
]);
}
public function markReadAll()
{
$type = config('type.' . $this->type . '.notification.class');
$notifications = user()->notifications()->unread()
->where('type', $type)
->get();
foreach ($notifications as $notification) {
$notification->markAsRead();
}
$this->dispatchBrowserEvent('mark-read-all', [
'type' => $this->type,
'message' => trans('notifications.messages.mark_read', ['type' => trans_choice('general.' . Str::plural($this->type) , 2)]),
]);
}
public function render()
{
$limit = 10;
$type = config('type.' . $this->type . '.notification.class');
$documents = user()->notifications()->unread()
->where('type', $type)
->paginate($limit);
$items = [];
foreach ($documents->items() as $key => $document) {
$data = $document->getAttribute('data');
$item = Document::invoice()->where('id', $data['invoice_id'])->first();
$item->notification_id = $document->getAttribute('id');
$items[] = $item;
}
$documents->setCollection(Collection::make($items));
return view('livewire.common.notifications.reminder', compact('documents'));
}
public function paginationView()
{
return 'vendor.livewire.default';
}
}

View File

@ -20,7 +20,7 @@ class Header
{
$user = user();
$invoices = $bills = [];
$invoices = $bills = $exports = $imports = [];
$updates = $notifications = 0;
$company = null;
@ -42,6 +42,22 @@ class Header
$data = $unread->getAttribute('data');
switch ($unread->getAttribute('type')) {
case 'App\Notifications\Common\ExportCompleted':
$exports['completed'][$data['file_name']] = $data['download_url'];
$notifications++;
break;
case 'App\Notifications\Common\ExportFailed':
$exports['failed'][] = $data['message'];
$notifications++;
break;
case 'App\Notifications\Common\ImportCompleted':
$import_completed[$data['bill_id']] = $data['amount'];
$notifications++;
break;
case 'App\Notifications\Common\ImportFailed':
$import_failed[$data['bill_id']] = $data['amount'];
$notifications++;
break;
case 'App\Notifications\Purchase\Bill':
$bills[$data['bill_id']] = $data['amount'];
$notifications++;
@ -64,6 +80,8 @@ class Header
$view->with([
'user' => $user,
'notifications' => $notifications,
'exports' => $exports,
'imports' => $imports,
'bills' => $bills,
'invoices' => $invoices,
'company' => $company,