fix dashes on the name and better error handling (#336)

This commit is contained in:
Saeed Vaziry
2024-11-02 22:44:02 +01:00
committed by GitHub
parent f743611b22
commit 6639fac9c0
16 changed files with 53 additions and 96 deletions

View File

@ -5,7 +5,6 @@
use App\Actions\CronJob\CreateCronJob;
use App\Models\CronJob;
use App\Web\Pages\Servers\Page;
use Exception;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
@ -70,18 +69,16 @@ protected function getHeaderActions(): array
->placeholder('0 * * * *'),
])
->action(function (array $data) {
try {
run_action($this, function () use ($data) {
app(CreateCronJob::class)->create($this->server, $data);
} catch (Exception $e) {
$this->dispatch('$refresh');
Notification::make()
->danger()
->title($e->getMessage())
->success()
->title('Cron Job created!')
->send();
throw $e;
}
$this->dispatch('$refresh');
});
}),
];
}

View File

@ -8,7 +8,6 @@
use App\Web\Contracts\HasSecondSubNav;
use App\Web\Pages\Servers\Page;
use App\Web\Pages\Settings\StorageProviders\Actions\Create;
use Exception;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
@ -73,7 +72,7 @@ protected function getHeaderActions(): array
])
->modalSubmitActionLabel('Create')
->action(function (array $data) {
try {
run_action($this, function () use ($data) {
app(CreateBackup::class)->create($this->server, $data);
$this->dispatch('$refresh');
@ -82,14 +81,7 @@ protected function getHeaderActions(): array
->success()
->title('Backup created!')
->send();
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
});
}),
];
}

View File

@ -7,7 +7,6 @@
use App\Models\DatabaseUser;
use App\Web\Contracts\HasSecondSubNav;
use App\Web\Pages\Servers\Page;
use Exception;
use Filament\Actions\Action;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\TextInput;
@ -52,7 +51,7 @@ protected function getHeaderActions(): array
])
->modalSubmitActionLabel('Create')
->action(function (array $data) {
try {
run_action($this, function () use ($data) {
app(CreateDatabaseUser::class)->create($this->server, $data);
$this->dispatch('$refresh');
@ -61,14 +60,7 @@ protected function getHeaderActions(): array
->success()
->title('Database user created!')
->send();
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
});
}),
];
}

View File

@ -6,8 +6,6 @@
use App\Models\Backup;
use App\Models\BackupFile;
use App\Models\Server;
use Exception;
use Filament\Notifications\Notification;
use Filament\Support\Enums\MaxWidth;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
@ -95,18 +93,10 @@ public function getTable(): Table
->authorize(fn (Backup $record) => auth()->user()->can('delete', $record))
->requiresConfirmation()
->action(function (Backup $record) {
try {
run_action($this, function () use ($record) {
$record->delete();
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
$this->dispatch('$refresh');
$this->dispatch('$refresh');
});
}),
]);
}

View File

@ -6,7 +6,6 @@
use App\Actions\Database\LinkUser;
use App\Models\DatabaseUser;
use App\Models\Server;
use Exception;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
@ -98,21 +97,14 @@ private function linkAction(): Action
->default(fn (DatabaseUser $record) => $record->databases),
])
->action(function (DatabaseUser $record, array $data) {
try {
run_action($this, function () use ($record, $data) {
app(LinkUser::class)->link($record, $data);
Notification::make()
->success()
->title('User linked to databases!')
->send();
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
});
});
}
@ -127,18 +119,10 @@ private function deleteAction(): Action
->authorize(fn ($record) => auth()->user()->can('delete', $record))
->requiresConfirmation()
->action(function (DatabaseUser $record) {
try {
run_action($this, function () use ($record) {
app(DeleteDatabaseUser::class)->delete($this->server, $record);
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
$this->dispatch('$refresh');
$this->dispatch('$refresh');
});
});
}
}

View File

@ -5,8 +5,6 @@
use App\Actions\Database\DeleteDatabase;
use App\Models\Database;
use App\Models\Server;
use Exception;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
@ -56,18 +54,10 @@ public function getTable(): Table
->authorize(fn ($record) => auth()->user()->can('delete', $record))
->requiresConfirmation()
->action(function (Database $record) {
try {
run_action($this, function () use ($record) {
app(DeleteDatabase::class)->delete($this->server, $record);
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
$this->dispatch('$refresh');
$this->dispatch('$refresh');
});
}),
]);
}

View File

@ -5,7 +5,6 @@
use App\Actions\FirewallRule\CreateRule;
use App\Models\FirewallRule;
use App\Web\Pages\Servers\Page;
use Exception;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
@ -69,18 +68,16 @@ protected function getHeaderActions(): array
->rules(CreateRule::rules()['mask']),
])
->action(function (array $data) {
try {
run_action($this, function () use ($data) {
app(CreateRule::class)->create($this->server, $data);
} catch (Exception $e) {
$this->dispatch('$refresh');
Notification::make()
->danger()
->title($e->getMessage())
->success()
->title('Firewall rule created!')
->send();
throw $e;
}
$this->dispatch('$refresh');
});
}),
];
}