69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\System;
|
|
|
|
use App\Models\SandboxRoute;
|
|
use App\Services\SandboxService;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Component;
|
|
|
|
class SandboxRoutes extends Component
|
|
{
|
|
public string $newType = 'domain';
|
|
public string $newTarget = '';
|
|
public ?string $syncMessage = null;
|
|
public bool $syncOk = false;
|
|
|
|
public function boot(SandboxService $sandboxService): void
|
|
{
|
|
$this->sandboxService = $sandboxService;
|
|
}
|
|
|
|
public function addRoute(): void
|
|
{
|
|
if ($this->newType !== 'global') {
|
|
$this->validate(['newTarget' => 'required|string|max:255']);
|
|
}
|
|
|
|
$target = $this->newType === 'global' ? null : trim($this->newTarget);
|
|
$this->sandboxService->enable($this->newType, $target);
|
|
$this->sandboxService->syncTransportFile();
|
|
$this->dispatch('sandbox-route-changed');
|
|
$this->newTarget = '';
|
|
}
|
|
|
|
public function removeRoute(int $id): void
|
|
{
|
|
$this->sandboxService->delete($id);
|
|
$this->sandboxService->syncTransportFile();
|
|
$this->dispatch('sandbox-route-changed');
|
|
}
|
|
|
|
public function toggleRoute(int $id): void
|
|
{
|
|
$route = SandboxRoute::findOrFail($id);
|
|
$route->is_active = !$route->is_active;
|
|
$route->save();
|
|
$this->sandboxService->syncTransportFile();
|
|
$this->dispatch('sandbox-route-changed');
|
|
}
|
|
|
|
public function syncPostfix(): void
|
|
{
|
|
$result = $this->sandboxService->syncTransportFile();
|
|
$this->syncOk = $result['ok'];
|
|
$this->syncMessage = $result['message'];
|
|
}
|
|
|
|
#[Computed]
|
|
public function routes()
|
|
{
|
|
return SandboxRoute::orderBy('type')->orderBy('target')->get();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.ui.system.sandbox-routes');
|
|
}
|
|
}
|