91 lines
3.0 KiB
PHP
91 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\Nx\Domain;
|
|
|
|
use App\Models\Domain;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Attributes\Url;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.dvx')]
|
|
#[Title('Domains · Mailwolt')]
|
|
class DomainList extends Component
|
|
{
|
|
#[Url(as: 'q', keep: true)]
|
|
public string $search = '';
|
|
|
|
#[On('domain-updated')]
|
|
#[On('domain-created')]
|
|
#[On('domain:delete')]
|
|
public function refresh(): void {}
|
|
|
|
public function openCreate(): void
|
|
{
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-create-modal');
|
|
}
|
|
|
|
public function openEdit(int $id): void
|
|
{
|
|
if ($this->isSystem($id)) return;
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-edit-modal', arguments: ['domainId' => $id]);
|
|
}
|
|
|
|
public function openLimits(int $id): void
|
|
{
|
|
if ($this->isSystem($id)) return;
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-limits-modal', arguments: ['domainId' => $id]);
|
|
}
|
|
|
|
public function openDns(int $id): void
|
|
{
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-dns-modal', arguments: ['domainId' => $id]);
|
|
}
|
|
|
|
public function openDelete(int $id): void
|
|
{
|
|
if ($this->isSystem($id)) return;
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-delete-modal', arguments: ['domainId' => $id]);
|
|
}
|
|
|
|
private function isSystem(int $id): bool
|
|
{
|
|
$domain = Domain::findOrFail($id);
|
|
if ($domain->is_system) {
|
|
$this->dispatch('toast', type: 'forbidden', badge: 'System-Domain',
|
|
title: 'Domain', text: 'Diese Domain ist als System-Domain markiert und kann nicht bearbeitet werden.', duration: 0);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$query = Domain::where('is_system', false)
|
|
->where('is_server', false)
|
|
->withCount(['mailUsers as mailboxes_count', 'mailAliases as aliases_count'])
|
|
->with(['dkimKeys' => fn($q) => $q->where('is_active', true)->latest()])
|
|
->orderBy('domain');
|
|
|
|
if ($this->search !== '') {
|
|
$query->where('domain', 'like', '%' . $this->search . '%');
|
|
}
|
|
|
|
$domains = $query->get()->map(function (Domain $d) {
|
|
$tags = is_array($d->tags) ? $d->tags : [];
|
|
$d->setAttribute('visible_tags', array_slice($tags, 0, 2));
|
|
$d->setAttribute('extra_tags', max(count($tags) - 2, 0));
|
|
return $d;
|
|
});
|
|
|
|
$systemDomain = Domain::where('is_system', true)
|
|
->withCount(['mailUsers as mailboxes_count', 'mailAliases as aliases_count'])
|
|
->with(['dkimKeys' => fn($q) => $q->where('is_active', true)->latest()])
|
|
->first();
|
|
$total = Domain::where('is_system', false)->where('is_server', false)->count();
|
|
|
|
return view('livewire.ui.nx.domain.domain-list', compact('domains', 'systemDomain', 'total'));
|
|
}
|
|
}
|