Refactor Livewire Server Advanced and Form components

This commit is contained in:
Andras Bacsai
2024-10-17 15:50:43 +02:00
parent aca198e0bb
commit 6545d04c46
2 changed files with 21 additions and 48 deletions

View File

@@ -2,12 +2,14 @@
namespace App\Livewire\Server; namespace App\Livewire\Server;
use App\Jobs\DockerCleanupJob;
use App\Models\Server; use App\Models\Server;
use Livewire\Component; use Livewire\Component;
class Advanced extends Component class Advanced extends Component
{ {
public Server $server; public Server $server;
protected $rules = [ protected $rules = [
'server.settings.concurrent_builds' => 'required|integer|min:1', 'server.settings.concurrent_builds' => 'required|integer|min:1',
'server.settings.dynamic_timeout' => 'required|integer|min:1', 'server.settings.dynamic_timeout' => 'required|integer|min:1',
@@ -28,6 +30,7 @@ class Advanced extends Component
'server.settings.delete_unused_volumes' => 'Delete Unused Volumes', 'server.settings.delete_unused_volumes' => 'Delete Unused Volumes',
'server.settings.delete_unused_networks' => 'Delete Unused Networks', 'server.settings.delete_unused_networks' => 'Delete Unused Networks',
]; ];
public function instantSave() public function instantSave()
{ {
try { try {
@@ -37,9 +40,21 @@ class Advanced extends Component
$this->dispatch('refreshServerShow'); $this->dispatch('refreshServerShow');
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->server->settings->refresh(); $this->server->settings->refresh();
return handleError($e, $this); return handleError($e, $this);
} }
} }
public function manualCleanup()
{
try {
DockerCleanupJob::dispatch($this->server, true);
$this->dispatch('success', 'Manual cleanup job started. Depending on the amount of data, this might take a while.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function submit() public function submit()
{ {
try { try {
@@ -54,6 +69,7 @@ class Advanced extends Component
return handleError($e, $this); return handleError($e, $this);
} }
} }
public function render() public function render()
{ {
return view('livewire.server.advanced'); return view('livewire.server.advanced');

View File

@@ -4,8 +4,6 @@ namespace App\Livewire\Server;
use App\Actions\Server\StartSentinel; use App\Actions\Server\StartSentinel;
use App\Actions\Server\StopSentinel; use App\Actions\Server\StopSentinel;
use App\Jobs\DockerCleanupJob;
use App\Jobs\PullSentinelImageJob;
use App\Models\Server; use App\Models\Server;
use Livewire\Component; use Livewire\Component;
@@ -172,30 +170,7 @@ class Form extends Component
$this->server->save(); $this->server->save();
$this->dispatch('success', 'Server updated.'); $this->dispatch('success', 'Server updated.');
$this->dispatch('refreshServerShow'); $this->dispatch('refreshServerShow');
// if ($this->server->isSentinelEnabled()) {
// StartSentinel::run($this->server);
// } else {
// StopSentinel::run($this->server);
// $this->server->settings->is_metrics_enabled = false;
// $this->server->settings->save();
// $this->server->sentinelHeartbeat(isReset: true);
// }
// if ($this->server->isSentinelEnabled()) {
// PullSentinelImageJob::dispatchSync($this->server);
// ray('Sentinel is enabled');
// if ($this->server->settings->isDirty('is_metrics_enabled')) {
// $this->dispatch('reloadWindow');
// }
// if ($this->server->settings->isDirty('is_sentinel_enabled') && $this->server->settings->is_sentinel_enabled === true) {
// ray('Starting sentinel');
// }
// } else {
// ray('Sentinel is not enabled');
// StopSentinel::dispatch($this->server);
// }
$this->server->settings->save(); $this->server->settings->save();
// $this->checkPortForServerApi();
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->server->settings->refresh(); $this->server->settings->refresh();
@@ -272,11 +247,11 @@ class Form extends Component
} }
refresh_server_connection($this->server->privateKey); refresh_server_connection($this->server->privateKey);
$this->server->settings->wildcard_domain = $this->wildcard_domain; $this->server->settings->wildcard_domain = $this->wildcard_domain;
if ($this->server->settings->force_docker_cleanup) { // if ($this->server->settings->force_docker_cleanup) {
$this->server->settings->docker_cleanup_frequency = $this->server->settings->docker_cleanup_frequency; // $this->server->settings->docker_cleanup_frequency = $this->server->settings->docker_cleanup_frequency;
} else { // } else {
$this->server->settings->docker_cleanup_threshold = $this->server->settings->docker_cleanup_threshold; // $this->server->settings->docker_cleanup_threshold = $this->server->settings->docker_cleanup_threshold;
} // }
$currentTimezone = $this->server->settings->getOriginal('server_timezone'); $currentTimezone = $this->server->settings->getOriginal('server_timezone');
$newTimezone = $this->server->settings->server_timezone; $newTimezone = $this->server->settings->server_timezone;
if ($currentTimezone !== $newTimezone || $currentTimezone === '') { if ($currentTimezone !== $newTimezone || $currentTimezone === '') {
@@ -290,22 +265,4 @@ class Form extends Component
return handleError($e, $this); return handleError($e, $this);
} }
} }
public function manualCleanup()
{
try {
DockerCleanupJob::dispatch($this->server, true);
$this->dispatch('success', 'Manual cleanup job started. Depending on the amount of data, this might take a while.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function manualCloudflareConfig()
{
$this->server->settings->is_cloudflare_tunnel = true;
$this->server->settings->save();
$this->server->refresh();
$this->dispatch('success', 'Cloudflare Tunnels enabled.');
}
} }