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

@ -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';
}
}