126 lines
4.2 KiB
PHP
126 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\Domain;
|
|
|
|
use App\Models\Domain;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
class DomainDnsList extends Component
|
|
{
|
|
/** System-Domain (is_system = true) */
|
|
public ?Domain $systemDomain = null;
|
|
|
|
/** Benutzer-Domains (is_system = false) */
|
|
public $userDomains = [];
|
|
public $tags = [];
|
|
|
|
#[On('domain-updated')]
|
|
#[On('domain-created')]
|
|
public function reloadDomains(): void
|
|
{
|
|
$this->loadDomains();
|
|
}
|
|
|
|
public function loadDomains(): void
|
|
{
|
|
$this->systemDomain = Domain::where('is_system', true)->first();
|
|
// $this->userDomains = Domain::where('is_system', false)->orderBy('domain')->get();
|
|
$domains = Domain::where('is_system', false)
|
|
->withCount([
|
|
'mailUsers as mailboxes_count', // -> mail_users
|
|
'mailAliases as aliases_count', // -> mail_aliases
|
|
])
|
|
->orderBy('domain')
|
|
->get();
|
|
|
|
|
|
$this->userDomains = $domains->map(function (Domain $d) {
|
|
$tags = $d->tag_objects ?? []; // aus Model-Accessor (vorher gebaut)
|
|
$d->setAttribute('visible_tags', array_slice($tags, 0, 2));
|
|
$d->setAttribute('extra_tags', max(count($tags) - 2, 0));
|
|
$d->setAttribute('domainActive', (bool)$d->is_active);
|
|
$d->setAttribute('effective_reason', $d->is_active ? 'Aktiv' : 'Inaktiv');
|
|
return $d;
|
|
});
|
|
|
|
}
|
|
|
|
public function openDnsModal(int $domainId): void
|
|
{
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-dns-modal', arguments: [
|
|
'domainId' => $domainId,
|
|
]);
|
|
}
|
|
|
|
public function openEditModal(int $id): void
|
|
{
|
|
$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 daher nicht geändert oder entfernt werden.', duration: 0,);
|
|
return;
|
|
}
|
|
|
|
// dein Modal
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-edit-modal', arguments: ['domainId' => $id]);
|
|
}
|
|
|
|
|
|
public function openLimitsModal(int $id): void
|
|
{
|
|
$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 daher nicht geändert oder entfernt werden.', duration: 0,);
|
|
return;
|
|
}
|
|
|
|
// dein Modal
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-limits-modal', arguments: ['domainId' => $id]);
|
|
}
|
|
|
|
public function openDeleteModal(int $id): void
|
|
{
|
|
$this->dispatch('openModal', component: 'ui.domain.modal.domain-delete-modal', arguments: [
|
|
'domainId' => $id,
|
|
]);
|
|
}
|
|
|
|
public function deleteDomain(int $id): void
|
|
{
|
|
$domain = Domain::findOrFail($id);
|
|
|
|
if ($domain->is_system || $id === $this->systemDomainId) {
|
|
$this->dispatch('toast', type:'forbidden', badge:'System-Domain', title: 'Domain', text: 'Diese Domain ist als System-Domain markiert und kann daher nicht geändert oder entfernt werden.', duration: 0,);
|
|
return;
|
|
}
|
|
|
|
$domain->loadCount(['mailUsers as mailboxes_count','mailAliases as aliases_count']);
|
|
if ($domain->mailboxes_count > 0 || $domain->aliases_count > 0) {
|
|
$this->dispatch('toast', type:'forbidden', badge:'Domain',
|
|
text:'Löschen blockiert: Es sind noch Postfächer/Aliasse vorhanden. Bitte zuerst entfernen.', duration:0);
|
|
return;
|
|
}
|
|
|
|
$domain->delete();
|
|
|
|
$this->reloadDomains();
|
|
$this->dispatch('toast',
|
|
type: 'done',
|
|
badge: 'Domain',
|
|
title: 'Domain gelöscht',
|
|
text: 'Die Domain <b>' . e($domain->domain) . '</b> wurde erfolgreich entfernt.',
|
|
duration: 6000
|
|
);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$this->loadDomains();
|
|
|
|
return view('livewire.ui.domain.domain-dns-list', [
|
|
'systemDomain' => $this->systemDomain,
|
|
'userDomains' => $this->userDomains,
|
|
]);
|
|
}
|
|
}
|