Skip to content

Commit

Permalink
Use database for notifications
Browse files Browse the repository at this point in the history
Adds a notification bell on top bar and  saves notification history. For use in the front end, ex. Server crashes.
  • Loading branch information
notAreYouScared committed Jul 7, 2024
1 parent 212c93c commit 99ca8fb
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 20 deletions.
3 changes: 2 additions & 1 deletion app/Exceptions/DisplayException.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function render(Request $request)
->title(static::class)
->body($this->getMessage())
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function exception($e, $stopPropagation): void
->color('danger')
->icon('tabler-database')
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

$stopPropagation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function exception($e, $stopPropagation): void
->color('danger')
->icon('tabler-database')
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

$stopPropagation();
}
Expand Down
9 changes: 6 additions & 3 deletions app/Filament/Resources/EggResource/Pages/EditEgg.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ protected function getHeaderActions(): array
->title('Import Failed')
->body($exception->getMessage())
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

report($exception);

Expand All @@ -287,7 +288,8 @@ protected function getHeaderActions(): array
->title('Import Failed')
->body($exception->getMessage())
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

report($exception);

Expand All @@ -299,7 +301,8 @@ protected function getHeaderActions(): array
Notification::make()
->title('Import Success')
->success()
->send();
->send()
->sendToDatabase(auth()->user());
}),

$this->getSaveFormAction()->formId('form'),
Expand Down
9 changes: 6 additions & 3 deletions app/Filament/Resources/EggResource/Pages/ListEggs.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ protected function getHeaderActions(): array
Notification::make()
->title('Import Failed')
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

report($exception);

Expand All @@ -126,7 +127,8 @@ protected function getHeaderActions(): array
Notification::make()
->title('Import Failed')
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

report($exception);

Expand All @@ -137,7 +139,8 @@ protected function getHeaderActions(): array
Notification::make()
->title('Import Success')
->success()
->send();
->send()
->sendToDatabase(auth()->user());
}),
];
}
Expand Down
6 changes: 5 additions & 1 deletion app/Filament/Resources/NodeResource/Pages/EditNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ public function form(Forms\Form $form): Forms\Form
->modalDescription('Resetting the daemon token will void any request coming from the old token. This token is used for all sensitive operations on the daemon including server creation and deletion. We suggest changing this token regularly for security.')
->action(function (NodeUpdateService $nodeUpdateService, Node $node) {
$nodeUpdateService->handle($node, [], true);
Notification::make()->success()->title('Daemon Key Reset')->send();
Notification::make()
->success()
->title('Daemon Key Reset')
->send()
->sendToDatabase(auth()->user());
$this->fillForm();
}),
]),
Expand Down
12 changes: 10 additions & 2 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,11 @@ public function form(Form $form): Form
->hidden(fn (Server $server) => $server->isSuspended())
->action(function (SuspensionService $suspensionService, Server $server) {
$suspensionService->toggle($server, 'suspend');
Notification::make()->success()->title('Server Suspended!')->send();
Notification::make()
->success()
->title('Server Suspended!')
->send()
->sendToDatabase(auth()->user());

$this->refreshFormData(['status', 'docker']);
}),
Expand All @@ -660,7 +664,11 @@ public function form(Form $form): Form
->hidden(fn (Server $server) => !$server->isSuspended())
->action(function (SuspensionService $suspensionService, Server $server) {
$suspensionService->toggle($server, 'unsuspend');
Notification::make()->success()->title('Server Unsuspended!')->send();
Notification::make()
->success()
->title('Server Unsuspended!')
->send()
->sendToDatabase(auth()->user());

$this->refreshFormData(['status', 'docker']);
}),
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/UserResource/Pages/EditProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ public function exception($e, $stopPropagation): void
->color('danger')
->icon('tabler-2fa')
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

$stopPropagation();
}
Expand Down
7 changes: 6 additions & 1 deletion app/Filament/Resources/UserResource/Pages/ListUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ protected function getHeaderActions(): array
->successRedirectUrl(route('filament.admin.resources.users.index'))
->action(function (array $data) {
resolve(UserCreationService::class)->handle($data);
Notification::make()->title('User Created!')->success()->send();
Notification::make()
->title('User Created!')
->body(fn ($data) => 'New User: '. $data['username'])
->success()
->send()
->sendToDatabase(auth()->user());

return redirect()->route('filament.admin.resources.users.index');
}),
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Admin/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function toggleInstall(Server $server)
->title('Success!')
->body(trans('admin/server.alerts.install_toggled'))
->success()
->send();
->send()
->sendToDatabase(auth()->user());

return null;
}
Expand All @@ -102,7 +103,7 @@ public function reinstallServer(Server $server)
->title('Success!')
->body(trans('admin/server.alerts.server_reinstalled'))
->success()
->send();
->send()->sendToDatabase(auth()->user());
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function panel(Panel $panel): Panel
->path('admin')
->topNavigation(config('panel.filament.top-navigation', true))
->login()
->databaseNotifications()
->homeUrl('/')
->favicon(config('app.favicon', '/pelican.ico'))
->brandName(config('app.name', 'Pelican'))
Expand Down
3 changes: 2 additions & 1 deletion app/Repositories/Daemon/DaemonServerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function getDetails(): array
->title('Cloudflare Issue')
->body('Your Node is not accessible by Cloudflare')
->danger()
->send();
->send()
->sendToDatabase(auth()->user());
}
} catch (Exception $exception) {
report($exception);
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Exceptions/FilamentExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public function handle(Exception $exception, callable $stopPropagation): void
->color($exception->color ?? 'danger')
->icon($exception->icon ?? 'tabler-x')
->danger()
->send();
->send()
->sendToDatabase(auth()->user());

if ($this->stopPropagation ?? true) {
$stopPropagation();
Expand Down
15 changes: 13 additions & 2 deletions app/Services/Servers/SuspensionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ public function toggle(Server $server, string $action = self::ACTION_SUSPEND)
// suspended in the database. Additionally, nothing needs to happen if the server
// is not suspended, and we try to un-suspend the instance.
if ($isSuspending === $server->isSuspended()) {
return Notification::make()->danger()->title('Failed!')->body('Server is already suspended!')->send();
return Notification::make()
->danger()
->title('Failed!')
->body('Server is already suspended!')
->send()
->sendToDatabase(auth()->user());
}

// Check if the server is currently being transferred.
if (!is_null($server->transfer)) {
Notification::make()->danger()->title('Failed!')->body('Server is currently being transferred.')->send();
Notification::make()
->danger()
->title('Failed!')
->body('Server is currently being transferred.')
->send()
->sendToDatabase(auth()->user());

throw new ConflictHttpException('Cannot toggle suspension status on a server that is currently being transferred.');
}

Expand Down

0 comments on commit 99ca8fb

Please sign in to comment.