Import notification file and updated other file..

This commit is contained in:
Cüneyt Şentürk 2021-06-19 22:30:14 +03:00
parent 4687185f4a
commit 5c5b890942
12 changed files with 182 additions and 27 deletions

View File

@ -4,23 +4,82 @@ namespace App\Http\Livewire\Common\Notifications;
use Livewire\Component; use Livewire\Component;
use Livewire\WithPagination; use Livewire\WithPagination;
use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Imports extends Component class Imports extends Component
{ {
use WithPagination; 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' => 'import',
'message' => trans('notifications.messages.mark_read', ['type' => $data['translation']]),
]);
}
public function markReadAll()
{
$notifications = $this->getNotifications();
foreach ($notifications as $notification) {
$notification->markAsRead();
}
$this->dispatchBrowserEvent('mark-read-all', [
'type' => 'import',
'message' => trans('notifications.messages.mark_read_all', ['type' => trans('import.import')]),
]);
}
public function render() public function render()
{ {
$limit = 5; $limit = 5;
$notifications = user()->notifications()->unread() $notifications = $this->getNotifications($limit);
->where('type', 'App\Notifications\Common\ImportCompleted')
->orWhere('type', 'App\Notifications\Common\ImportFailed')
->paginate($limit);
return view('livewire.common.notifications.imports', compact('notifications')); return view('livewire.common.notifications.imports', compact('notifications'));
} }
protected function getNotifications($limit = false)
{
$query = user()->notifications()->unread()
->where('type', 'App\Notifications\Common\ImportCompleted')
->orWhere('type', 'App\Notifications\Common\ImportFailed');
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() public function paginationView()
{ {
return 'vendor.livewire.default'; return 'vendor.livewire.default';

View File

@ -2,12 +2,17 @@
namespace App\Http\Livewire\Common\Notifications; namespace App\Http\Livewire\Common\Notifications;
use App\Traits\Modules;
use Livewire\Component; use Livewire\Component;
class NewApps extends Component class NewApps extends Component
{ {
use Modules;
public function render() public function render()
{ {
return view('livewire.common.notifications.new-apps'); $notifications = $this->getNotifications('new-apps');
return view('livewire.common.notifications.new-apps', compact('notifications'));
} }
} }

View File

@ -46,12 +46,13 @@ class Reminder extends Component
public function render() public function render()
{ {
$limit = 10; $limit = 5;
$type = config('type.' . $this->type . '.notification.class'); $type = config('type.' . $this->type . '.notification.class');
$documents = user()->notifications()->unread() $documents = user()->notifications()->unread()
->where('type', $type) ->where('type', $type)
->where('data', 'like', '%template_alias:{$this->type}_remind_admin%')
->paginate($limit); ->paginate($limit);
$items = []; $items = [];

View File

@ -20,7 +20,7 @@ class Header
{ {
$user = user(); $user = user();
$invoices = $bills = $exports = $imports = []; $new_apps = $invoices = $bills = $exports = $imports = [];
$updates = $notifications = 0; $updates = $notifications = 0;
$company = null; $company = null;
@ -51,11 +51,11 @@ class Header
$notifications++; $notifications++;
break; break;
case 'App\Notifications\Common\ImportCompleted': case 'App\Notifications\Common\ImportCompleted':
$import_completed[$data['bill_id']] = $data['amount']; $imports['completed'][] = $data['translation'];
$notifications++; $notifications++;
break; break;
case 'App\Notifications\Common\ImportFailed': case 'App\Notifications\Common\ImportFailed':
$import_failed[$data['bill_id']] = $data['amount']; $imports['failed'][] = '';
$notifications++; $notifications++;
break; break;
case 'App\Notifications\Purchase\Bill': case 'App\Notifications\Purchase\Bill':
@ -68,6 +68,12 @@ class Header
break; break;
} }
} }
$new_apps = $this->getNotifications('new-apps');
foreach ($new_apps as $new_app) {
$notifications++;
}
} }
if ($user->can('read-install-updates')) { if ($user->can('read-install-updates')) {
@ -80,6 +86,7 @@ class Header
$view->with([ $view->with([
'user' => $user, 'user' => $user,
'notifications' => $notifications, 'notifications' => $notifications,
'new_apps' => $new_apps,
'exports' => $exports, 'exports' => $exports,
'imports' => $imports, 'imports' => $imports,
'bills' => $bills, 'bills' => $bills,

View File

@ -11,11 +11,18 @@ class ImportCompleted extends Notification implements ShouldQueue
{ {
use Queueable; use Queueable;
protected $translation;
protected $total_rows;
/** /**
* Create a notification instance. * Create a notification instance.
*/ */
public function __construct() public function __construct($translation, $total_rows)
{ {
$this->translation = $translation;
$this->total_rows = $total_rows;
$this->onQueue('notifications'); $this->onQueue('notifications');
} }
@ -27,7 +34,7 @@ class ImportCompleted extends Notification implements ShouldQueue
*/ */
public function via($notifiable) public function via($notifiable)
{ {
return ['mail']; return ['mail', 'database'];
} }
/** /**
@ -45,4 +52,18 @@ class ImportCompleted extends Notification implements ShouldQueue
->line(trans('notifications.import.completed.description')) ->line(trans('notifications.import.completed.description'))
->action(trans_choice('general.dashboards', 1), $dashboard_url); ->action(trans_choice('general.dashboards', 1), $dashboard_url);
} }
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'translation' => $this->translation,
'total_rows' => $this->total_rows,
];
}
} }

View File

@ -38,7 +38,7 @@ class ImportFailed extends Notification implements ShouldQueue
*/ */
public function via($notifiable) public function via($notifiable)
{ {
return ['mail']; return ['mail', 'database'];
} }
/** /**
@ -59,4 +59,17 @@ class ImportFailed extends Notification implements ShouldQueue
return $message; return $message;
} }
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'errors' => $this->errors,
];
}
} }

View File

@ -24,8 +24,15 @@ class Import
$file = $request->file('import'); $file = $request->file('import');
if (should_queue()) { if (should_queue()) {
$rows = $class->toArray($file);
$total_rows = 0;
if (!empty($rows[0])) {
$total_rows = count($rows[0]);
}
$class->queue($file)->onQueue('imports')->chain([ $class->queue($file)->onQueue('imports')->chain([
new NotifyUser(user(), new ImportCompleted), new NotifyUser(user(), new ImportCompleted($translation, $total_rows)),
]); ]);
$message = trans('messages.success.import_queued', ['type' => $translation]); $message = trans('messages.success.import_queued', ['type' => $translation]);

View File

@ -7,6 +7,7 @@ return [
'notifications' => [ 'notifications' => [
'counter' => '{0} You have no notification|{1} You have :count notification|[2,*] You have :count notifications', 'counter' => '{0} You have no notification|{1} You have :count notification|[2,*] You have :count notifications',
'new_apps' => '{1} :count published app|[2,*] :count published apps',
'overdue_invoices' => '{1} :count overdue invoice|[2,*] :count overdue invoices', 'overdue_invoices' => '{1} :count overdue invoice|[2,*] :count overdue invoices',
'upcoming_bills' => '{1} :count upcoming bill|[2,*] :count upcoming bills', 'upcoming_bills' => '{1} :count upcoming bill|[2,*] :count upcoming bills',
'view_all' => 'View All', 'view_all' => 'View All',

View File

@ -10,6 +10,7 @@ return [
'read_all' => 'Read All', 'read_all' => 'Read All',
'mark_read' => 'Mark Read', 'mark_read' => 'Mark Read',
'mark_read_all' => 'Mark Read All', 'mark_read_all' => 'Mark Read All',
'new_apps' => 'New App|New Apps',
'upcoming_bills' => 'Upcoming Bills', 'upcoming_bills' => 'Upcoming Bills',
'recurring_invoices' => 'Recurring Invoices', 'recurring_invoices' => 'Recurring Invoices',
'recurring_bills' => 'Recurring Bills', 'recurring_bills' => 'Recurring Bills',
@ -61,6 +62,8 @@ return [
'messages' => [ 'messages' => [
'mark_read' => ':type is read this notification!', 'mark_read' => ':type is read this notification!',
'mark_read_all' => ':type is read all notification!', 'mark_read_all' => ':type is read all notification!',
'export' => ':type export is ready! The export file is ready to download from the following <a href=":url" target="_blank">:file_name</a>' 'new_app' => ':type app published.',
'export' => ':type export is ready! The export file is ready to download from the following <a href=":url" target="_blank">:file_name</a>',
'import' => ':type import finished! Added :count :type rows.'
], ],
]; ];

View File

@ -1,9 +1,9 @@
@if ($notifications->total()) @if ($notifications->total())
<div class="card" id="export"> <div class="card" id="import">
<div class="card-header"> <div class="card-header">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-8"> <div class="col-8">
<h5 class="h3 mb-0">{{ trans('general.export') }}</h5> <h5 class="h3 mb-0">{{ trans('import.import') }}</h5>
</div> </div>
<div class="col-4 text-right"> <div class="col-4 text-right">
@ -20,16 +20,15 @@
</div> </div>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-flush table-hover" id="tbl-export"> <table class="table table-flush table-hover" id="tbl-import">
<tbody> <tbody>
@foreach ($notifications as $notification) @foreach ($notifications as $notification)
<tr class="row align-items-center border-top-1"> <tr class="row align-items-center border-top-1">
<td class="col-xs-8 col-sm-10 col-md-10 col-lg-11 col-xl-11 text-left"> <td class="col-xs-8 col-sm-10 col-md-10 col-lg-11 col-xl-11 text-left">
@if (empty($notification->message)) @if (empty($notification->message))
{!! trans('notifications.messages.export', [ {!! trans('notifications.messages.import', [
'type' => $notification->translation, 'type' => $notification->translation,
'file_name' => $notification->file_name, 'count' => $notification->total_rows
'url' => $notification->download_url
]) !!} ]) !!}
@else @else
{!! $notification->message !!} {!! $notification->message !!}

View File

@ -1,7 +1,27 @@
<div class="card"> @if ($notifications)
<div class="card-header"></div> <div class="accordion" id="new-apps">
<div class="card">
<div class="card-body"> <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">
<h4 class="mb-0">{{ trans_choice('notifications.new_apps', 2) }}</h4>
</div> </div>
</div> </div>
<div id="collapse-new-apps" class="collapse show" aria-labelledby="heading-new-apps" data-parent="#new-apps">
<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">
{!! $notification->message !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
@endif

View File

@ -127,6 +127,25 @@
@endif @endif
<div class="list-group list-group-flush"> <div class="list-group list-group-flush">
@stack('notification_new_apps_start')
@if (!empty($new_apps) && count($new_apps))
<a href="{{ route('notifications.index') . '#new-apps' }}" class="list-group-item list-group-item-action">
<div class="row align-items-center">
<div class="col-auto">
<i class="fa fa-rocket"></i>
</div>
<div class="col ml--2">
<div class="d-flex justify-content-between align-items-center">
<h4 class="mb-0 text-sm">{{ trans_choice('header.notifications.new_apps', count($new_apps), ['count' => count($new_apps)]) }}</h4>
</div>
</div>
</div>
</a>
@endif
@stack('notification_new_apps_end')
@stack('notification_exports_completed_start') @stack('notification_exports_completed_start')
@if (!empty($exports['completed']) && count($exports['completed'])) @if (!empty($exports['completed']) && count($exports['completed']))