Skip to content

Commit

Permalink
Notifications are cool
Browse files Browse the repository at this point in the history
  • Loading branch information
notAreYouScared committed Aug 14, 2024
1 parent e0ee02b commit 42b8a22
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions app/Filament/App/Pages/Startup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\App\Pages;

use App\Facades\Activity;
use App\Models\Permission;
use App\Models\Server;
use App\Models\ServerVariable;
Expand All @@ -15,7 +16,9 @@
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Set;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Validator;
use Filament\Notifications\Actions\Action as NotificationAction;

class Startup extends SimplePage
{
Expand Down Expand Up @@ -93,7 +96,7 @@ public function form(Form $form): Form

$text = TextInput::make($serverVariable->variable->name)
->hidden(fn (Component $component) => $this->shouldHideComponent($serverVariable, $component))
->readOnly(fn () => !$serverVariable->variable->user_editable)
->disabled(fn () => !$serverVariable->variable->user_editable)
->required(fn () => in_array('required', explode('|', $serverVariable->variable->rules)))
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) use ($serverVariable) {
Expand Down Expand Up @@ -193,24 +196,44 @@ public function update($state, string $var): null
$variable = $server->variables()->where('env_variable', $var)->first();
$original = $variable->server_value;

//$this->validate($state, $variable->rules); //TODO: Setup Rule Validation

ServerVariable::query()->updateOrCreate([
'server_id' => $server->id,
'variable_id' => $variable->id,
], [
'variable_value' => $state ?? '',
]);

if ($variable->env_variable !== $var) {
Activity::event('server:startup.edit')
->subject($variable)
->property([
'variable' => $variable->env_variable,
'old' => $original,
'new' => $state,
try {
//TODO: RULE CHECK

ServerVariable::query()->updateOrCreate([
'server_id' => $server->id,
'variable_id' => $variable->id,
], [
'variable_value' => $state ?? '',
]);

if ($variable->env_variable !== $var) {
Activity::event('server:startup.edit')
->subject($variable)
->property([
'variable' => $variable->env_variable,
'old' => $original,
'new' => $state,
])
->log();
}
Notification::make()
->success()
->duration(5000) // 5 seconds
->actions([
NotificationAction::make('undo')
->label('Undo')
->color('warning')
->action(''), //TODO Allow user to click revert and change the value back?
])
->log();
->title('Updated: ' . $variable->name)
->body(fn () => $original . ' -> ' . $state)
->send();
} catch (\Exception $e) {
Notification::make()
->danger()
->title('Failed: ' . $variable->name)
->body($e->getMessage())
->send();
}

return null;
Expand Down

0 comments on commit 42b8a22

Please sign in to comment.