Import notification file and updated other file..
This commit is contained in:
@@ -4,23 +4,82 @@ 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 Imports 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' => '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()
|
||||
{
|
||||
$limit = 5;
|
||||
|
||||
$notifications = user()->notifications()->unread()
|
||||
->where('type', 'App\Notifications\Common\ImportCompleted')
|
||||
->orWhere('type', 'App\Notifications\Common\ImportFailed')
|
||||
->paginate($limit);
|
||||
$notifications = $this->getNotifications($limit);
|
||||
|
||||
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()
|
||||
{
|
||||
return 'vendor.livewire.default';
|
||||
|
@@ -2,12 +2,17 @@
|
||||
|
||||
namespace App\Http\Livewire\Common\Notifications;
|
||||
|
||||
use App\Traits\Modules;
|
||||
use Livewire\Component;
|
||||
|
||||
class NewApps extends Component
|
||||
{
|
||||
use Modules;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.common.notifications.new-apps');
|
||||
$notifications = $this->getNotifications('new-apps');
|
||||
|
||||
return view('livewire.common.notifications.new-apps', compact('notifications'));
|
||||
}
|
||||
}
|
||||
|
@@ -46,12 +46,13 @@ class Reminder extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
$limit = 10;
|
||||
$limit = 5;
|
||||
|
||||
$type = config('type.' . $this->type . '.notification.class');
|
||||
|
||||
$documents = user()->notifications()->unread()
|
||||
->where('type', $type)
|
||||
->where('data', 'like', '%template_alias:{$this->type}_remind_admin%')
|
||||
->paginate($limit);
|
||||
|
||||
$items = [];
|
||||
|
@@ -20,7 +20,7 @@ class Header
|
||||
{
|
||||
$user = user();
|
||||
|
||||
$invoices = $bills = $exports = $imports = [];
|
||||
$new_apps = $invoices = $bills = $exports = $imports = [];
|
||||
$updates = $notifications = 0;
|
||||
$company = null;
|
||||
|
||||
@@ -51,11 +51,11 @@ class Header
|
||||
$notifications++;
|
||||
break;
|
||||
case 'App\Notifications\Common\ImportCompleted':
|
||||
$import_completed[$data['bill_id']] = $data['amount'];
|
||||
$imports['completed'][] = $data['translation'];
|
||||
$notifications++;
|
||||
break;
|
||||
case 'App\Notifications\Common\ImportFailed':
|
||||
$import_failed[$data['bill_id']] = $data['amount'];
|
||||
$imports['failed'][] = '';
|
||||
$notifications++;
|
||||
break;
|
||||
case 'App\Notifications\Purchase\Bill':
|
||||
@@ -68,6 +68,12 @@ class Header
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$new_apps = $this->getNotifications('new-apps');
|
||||
|
||||
foreach ($new_apps as $new_app) {
|
||||
$notifications++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->can('read-install-updates')) {
|
||||
@@ -80,6 +86,7 @@ class Header
|
||||
$view->with([
|
||||
'user' => $user,
|
||||
'notifications' => $notifications,
|
||||
'new_apps' => $new_apps,
|
||||
'exports' => $exports,
|
||||
'imports' => $imports,
|
||||
'bills' => $bills,
|
||||
|
@@ -11,11 +11,18 @@ class ImportCompleted extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $translation;
|
||||
|
||||
protected $total_rows;
|
||||
|
||||
/**
|
||||
* Create a notification instance.
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($translation, $total_rows)
|
||||
{
|
||||
$this->translation = $translation;
|
||||
$this->total_rows = $total_rows;
|
||||
|
||||
$this->onQueue('notifications');
|
||||
}
|
||||
|
||||
@@ -27,7 +34,7 @@ class ImportCompleted extends Notification implements ShouldQueue
|
||||
*/
|
||||
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'))
|
||||
->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ class ImportFailed extends Notification implements ShouldQueue
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
return ['mail', 'database'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,8 +50,8 @@ class ImportFailed extends Notification implements ShouldQueue
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$message = (new MailMessage)
|
||||
->subject(trans('notifications.import.failed.subject'))
|
||||
->line(trans('notifications.import.failed.description'));
|
||||
->subject(trans('notifications.import.failed.subject'))
|
||||
->line(trans('notifications.import.failed.description'));
|
||||
|
||||
foreach ($this->errors as $error) {
|
||||
$message->line($error);
|
||||
@@ -59,4 +59,17 @@ class ImportFailed extends Notification implements ShouldQueue
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'errors' => $this->errors,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -24,8 +24,15 @@ class Import
|
||||
$file = $request->file('import');
|
||||
|
||||
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([
|
||||
new NotifyUser(user(), new ImportCompleted),
|
||||
new NotifyUser(user(), new ImportCompleted($translation, $total_rows)),
|
||||
]);
|
||||
|
||||
$message = trans('messages.success.import_queued', ['type' => $translation]);
|
||||
|
Reference in New Issue
Block a user