Loheide-eu-mitarbeiterplatt.../app/Filament/Pages/HubsSettings.php
Friederich Loheide 4d0a2984ec
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 9m9s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 9m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 10m30s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 11m5s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m15s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m54s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m57s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 11m44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m20s
Wissen, Service, Gremien-Baustein und Menü-Vorschlag (0.56.0)
Übersichtsseiten /wissen und /service (Hubs, im Admin pflegbar), Baustein
„Mitglieder mit Rolle“, Menü-Vorschlag für die Mitarbeiter-App.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 16:03:08 +00:00

129 lines
5.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Pages;
use App\Filament\Clusters\HomepageCluster;
use App\Models\Role;
use App\Models\User;
use App\Support\Hubs;
use App\Support\Icons;
use App\Support\Settings;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
/**
* Kacheln der Übersichtsseiten „Wissen“ (/wissen) und „Service“ (/service) pflegen.
*/
class HubsSettings extends Page
{
protected string $view = 'filament.pages.settings-form';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedLifebuoy;
protected static ?string $cluster = HomepageCluster::class;
protected static ?int $navigationSort = 4;
protected static ?string $navigationLabel = 'Wissen & Service';
protected static ?string $title = 'Wissen & Service';
protected static ?string $slug = 'wissen-service';
/** @var array<string, mixed>|null */
public ?array $data = [];
public static function canAccess(): bool
{
return auth()->user()?->can('appearance.manage') ?? false;
}
public function getSubheading(): ?string
{
return 'Kacheln der Seiten „Wissen“ (/wissen) und „Service“ (/service) – jeweils mit Ansprechperson. Im Menü als Link eintragen, z. B. mit „Menü → Vorschlag für die Mitarbeiter-App“.';
}
public function mount(Hubs $hubs): void
{
$this->form->fill(['wissen' => $hubs->entries('wissen'), 'service' => $hubs->entries('service')]);
}
public function form(Schema $schema): Schema
{
return $schema
->components([
Section::make('Wissen')->description('Bereiche zum Nachschlagen – unter der großen Suche.')
->schema([$this->repeater('wissen')]),
Section::make('Service')->description('Anlaufstellen neben dem IT-Service (der erscheint automatisch, wenn das Plugin aktiv ist).')
->schema([$this->repeater('service')]),
])
->statePath('data');
}
private function repeater(string $name): Repeater
{
return Repeater::make($name)
->hiddenLabel()
->columns(4)
->reorderable()
->collapsible()
->collapsed()
->itemLabel(fn (array $state) => $state['title'] ?? null)
->addActionLabel('Kachel hinzufügen')
->maxItems(24)
->schema([
TextInput::make('title')->label('Titel')->required()->maxLength(60),
TextInput::make('url')->label('Adresse')->placeholder('/downloads oder https://…')->required()->maxLength(500)
->regex('#^(https?://|/)#i')->validationMessages(['regex' => 'Bitte eine Adresse, die mit https://, http:// oder / beginnt.'])->columnSpan(2),
Select::make('icon')->label('Symbol')->options(Icons::options())->allowHtml()->searchable()
->getSearchResultsUsing(fn (string $search) => Icons::search($search))
->getOptionLabelUsing(fn (?string $value) => $value ? Icons::option($value) : null)
->default('link')->required(),
TextInput::make('text')->label('Beschreibung')->maxLength(160)->columnSpan(2),
TextInput::make('action')->label('Knopf (optional)')->placeholder('z. B. Antrag stellen')->maxLength(30),
Select::make('person')->label('Ansprechperson')->searchable()
->getSearchResultsUsing(fn (string $search) => User::query()->active()
->where(fn ($q) => $q->where('name', 'like', "%{$search}%")->orWhere('email', 'like', "%{$search}%"))
->orderBy('name')->limit(30)->pluck('name', 'id')->all())
->getOptionLabelUsing(fn ($value) => User::query()->find($value)?->name),
Select::make('roles')->label('Sichtbar für')->multiple()
->options(fn () => Role::query()->orderBy('name')->pluck('name', 'id')->all())
->placeholder('Alle')->columnSpan(2),
Hidden::make('plugin'),
]);
}
protected function getHeaderActions(): array
{
return [
Action::make('suggest')->label('Vorschlag laden')->icon(Heroicon::OutlinedSparkles)->color('gray')
->requiresConfirmation()
->modalDescription('Ersetzt die Kacheln im Formular durch einen Vorschlag aus den vorhandenen Bereichen. Gespeichert wird erst mit „Speichern“.')
->action(fn (Hubs $hubs) => $this->form->fill(['wissen' => $hubs->suggestion('wissen'), 'service' => $hubs->suggestion('service')])),
];
}
public function save(Settings $settings): void
{
$state = $this->form->getState();
foreach (Hubs::HUBS as $hub) {
$settings->set("hubs.{$hub}", array_values(array_map(fn (array $entry) => [
...$entry,
'person' => filled($entry['person'] ?? null) ? (int) $entry['person'] : null,
'roles' => array_values(array_map('intval', (array) ($entry['roles'] ?? []))),
], $state[$hub] ?? [])));
}
Notification::make()->success()->title('Wissen & Service gespeichert')->send();
}
}