63 lines
2.0 KiB
PHP
63 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use App\Models\Datacenter;
|
|
use App\Models\Host;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Url;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.admin')]
|
|
class Hosts extends Component
|
|
{
|
|
#[Url(as: 'q')]
|
|
public string $search = '';
|
|
|
|
#[Url]
|
|
public string $datacenter = '';
|
|
|
|
#[Url]
|
|
public string $status = '';
|
|
|
|
public function updated(): void
|
|
{
|
|
// no-op; keeps the query string in sync as filters change
|
|
}
|
|
|
|
public function clearFilters(): void
|
|
{
|
|
$this->reset('search', 'datacenter', 'status');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$hosts = Host::query()
|
|
->withCount('instances')
|
|
// The VPN column reads SyncVpnPeers' synced row, not a live hub
|
|
// call — the console container has no wg0 (see VpnPeer::vpnPeer()
|
|
// and SyncVpnPeers' docblock). One eager-loaded query for the
|
|
// whole page, not one per host.
|
|
->with('vpnPeer')
|
|
->when($this->search !== '', function ($q) {
|
|
$term = '%'.$this->search.'%';
|
|
$q->where(fn ($w) => $w->where('name', 'like', $term)->orWhere('public_ip', 'like', $term));
|
|
})
|
|
->when($this->datacenter !== '', fn ($q) => $q->where('datacenter', $this->datacenter))
|
|
->when($this->status !== '', fn ($q) => $q->where('status', $this->status))
|
|
->orderBy('datacenter')->orderBy('name')
|
|
->get();
|
|
|
|
return view('livewire.admin.hosts', [
|
|
'hosts' => $hosts,
|
|
'datacenters' => Datacenter::query()->orderBy('name')->get(),
|
|
'statuses' => ['pending', 'onboarding', 'active', 'error', 'disabled'],
|
|
'total' => Host::query()->count(),
|
|
// Für die aufklappbare Anleitung: dieselbe Adresse, die später in
|
|
// der Befehlszeile steht, damit hier nichts anderes behauptet wird
|
|
// als dort getan wird.
|
|
'archiveUrl' => \App\Support\HostTakeoverCommand::archiveUrl(),
|
|
]);
|
|
}
|
|
}
|