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

@@ -91,6 +91,6 @@ abstract class Export implements FromCollection, HasLocalePreference, ShouldAuto
public function failed(\Throwable $exception): void
{
$this->user->notify(new ExportFailed($exception));
$this->user->notify(new ExportFailed($exception->getMessage()));
}
}

File diff suppressed because it is too large Load Diff

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,

View File

@@ -15,16 +15,19 @@ class CreateMediableForExport extends JobShouldQueue
protected $file_name;
protected $translation;
/**
* Create a new job instance.
*
* @param $user
* @param $file_name
*/
public function __construct($user, $file_name)
public function __construct($user, $file_name, $translation)
{
$this->user = $user;
$this->file_name = $file_name;
$this->translation = $translation;
$this->onQueue('jobs');
}
@@ -42,7 +45,7 @@ class CreateMediableForExport extends JobShouldQueue
$download_url = route('uploads.download', ['id' => $media->id, 'company_id' => company_id()]);
$this->user->notify(new ExportCompleted($download_url));
$this->user->notify(new ExportCompleted($this->translation, $this->file_name, $download_url));
}
public function getQueuedMedia()

View File

@@ -11,6 +11,10 @@ class ExportCompleted extends Notification implements ShouldQueue
{
use Queueable;
protected $translation;
protected $file_name;
protected $download_url;
/**
@@ -18,8 +22,10 @@ class ExportCompleted extends Notification implements ShouldQueue
*
* @param string $download_url
*/
public function __construct($download_url)
public function __construct($translation, $file_name, $download_url)
{
$this->translation = $translation;
$this->file_name = $file_name;
$this->download_url = $download_url;
$this->onQueue('notifications');
@@ -33,7 +39,7 @@ class ExportCompleted extends Notification implements ShouldQueue
*/
public function via($notifiable)
{
return ['mail'];
return ['mail', 'database'];
}
/**
@@ -49,4 +55,19 @@ class ExportCompleted extends Notification implements ShouldQueue
->line(trans('notifications.export.completed.description'))
->action(trans('general.download'), $this->download_url);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'translation' => $this->translation,
'file_name' => $this->file_name,
'download_url' => $this->download_url,
];
}
}

View File

@@ -14,18 +14,18 @@ class ExportFailed extends Notification implements ShouldQueue
/**
* The error exception.
*
* @var object
* @var string
*/
public $exception;
public $message;
/**
* Create a notification instance.
*
* @param object $exception
* @param string $message
*/
public function __construct($exception)
public function __construct($message)
{
$this->exception = $exception;
$this->message = $message;
$this->onQueue('notifications');
}
@@ -38,7 +38,7 @@ class ExportFailed extends Notification implements ShouldQueue
*/
public function via($notifiable)
{
return ['mail'];
return ['mail', 'database'];
}
/**
@@ -52,6 +52,19 @@ class ExportFailed extends Notification implements ShouldQueue
return (new MailMessage)
->subject(trans('notifications.export.failed.subject'))
->line(trans('notifications.export.failed.description'))
->line($this->exception->getMessage());
->line($this->message);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'message' => $this->message,
];
}
}

View File

@@ -86,8 +86,14 @@ class PaymentReceived extends Notification
public function toArray($notifiable)
{
return [
'template_alias' => $this->template->alias,
'invoice_id' => $this->invoice->id,
'invoice_number' => $this->invoice->document_number,
'customer_name' => $this->invoice->contact_name,
'amount' => $this->invoice->amount,
'invoice_at' => $this->invoice->issued_at,
'due_at' => $this->invoice->due_at,
'status' => $this->invoice->status,
];
}

View File

@@ -57,8 +57,14 @@ class Bill extends Notification
public function toArray($notifiable)
{
return [
'template_alias' => $this->template->alias,
'bill_id' => $this->bill->id,
'bill_number' => $this->bill->document_number,
'vendor_name' => $this->bill->contact_name,
'amount' => $this->bill->amount,
'billed_date' => company_date($this->bill->issued_at),
'bill_due_date' => company_date($this->bill->due_at),
'status' => $this->bill->status,
];
}
@@ -68,6 +74,7 @@ class Bill extends Notification
'{bill_number}',
'{bill_total}',
'{bill_amount_due}',
'{billed_date}',
'{bill_due_date}',
'{bill_admin_link}',
'{vendor_name}',

View File

@@ -77,8 +77,14 @@ class Invoice extends Notification
public function toArray($notifiable)
{
return [
'template_alias' => $this->template->alias,
'invoice_id' => $this->invoice->id,
'invoice_number' => $this->invoice->document_number,
'customer_name' => $this->invoice->contact_name,
'amount' => $this->invoice->amount,
'invoiced_date' => company_date($this->invoice->issued_at),
'invoice_due_date' => company_date($this->invoice->due_at),
'status' => $this->invoice->status,
];
}
@@ -88,6 +94,7 @@ class Invoice extends Notification
'{invoice_number}',
'{invoice_total}',
'{invoice_amount_due}',
'{invoiced_date}',
'{invoice_due_date}',
'{invoice_guest_link}',
'{invoice_admin_link}',

View File

@@ -31,7 +31,7 @@ class Export
}
$class->queue($file_name, $disk)->onQueue('exports')->chain([
new CreateMediableForExport(user(), $file_name),
new CreateMediableForExport(user(), $file_name, $translation),
]);
$message = trans('messages.success.export_queued', ['type' => $translation]);