Loheide-eu-mitarbeiterplatt.../app/Filament/Pages/DashboardSettings.php
Friederich Loheide 38f47f98e2
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 14m38s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 14m13s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 11m56s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 11m44s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 56m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1h2m6s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m30s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m13s
Oberfläche Mitarbeiter-App umschaltbar (0.52.0)
Einstellung interface (classic|app) im Erscheinungsbild; data-ui am Wurzelelement,
warme Tokens, Karten mit Schatten, Menüpunkte als Pillen; Startseite dreispaltig.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 19:17:23 +00:00

186 lines
8.2 KiB
PHP
Raw 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\Dashboard\Homepage;
use App\Dashboard\Widgets;
use App\Filament\Clusters\HomepageCluster;
use App\Filament\Resources\DashboardTiles\DashboardTileResource;
use App\Support\Branding;
use App\Support\ContactCards;
use App\Support\Settings;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Repeater\TableColumn;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
/**
* Anordnung der Startseite: Kacheln je Bereich sortieren und ausblenden –
* mitgelieferte wie eigene.
*/
class DashboardSettings extends Page
{
protected string $view = 'filament.pages.settings-form';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedHome;
protected static ?string $cluster = HomepageCluster::class;
protected static ?int $navigationSort = 1;
protected static ?string $navigationLabel = 'Startseite';
protected static ?string $title = 'Startseite';
protected static ?string $slug = 'startseite';
private const AREAS = [
'top' => ['Ganz oben (volle Breite)', 'Hinweise und Banner über allem.'],
'hero' => ['Groß links oben', 'Nur die erste sichtbare Kachel wird gezeigt.'],
'feed' => ['Neben dem großen Bereich', ''],
'main' => ['Hauptspalte', ''],
'aside' => ['Seitenleiste (rechts)', ''],
];
/** @var array<string, mixed>|null */
public ?array $data = [];
public static function canAccess(): bool
{
return auth()->user()?->can('appearance.manage') ?? false;
}
public function mount(Widgets $widgets): void
{
$this->form->fill([
'mode' => app(Homepage::class)->mode(),
...collect(self::AREAS)->mapWithKeys(fn ($info, $area) => [$area => $widgets->forAdmin($area)])->all(),
'people_fields' => (array) app(Settings::class)->get(ContactCards::PEOPLE_SEARCH_FIELDS, ContactCards::DEFAULT_PEOPLE_SEARCH_FIELDS),
]);
}
/**
* Erlaubte Bereiche einer Kachel (mehr als einer = verschiebbar).
*
* @return list<string>
*/
private static function areasOf(?string $key): array
{
foreach (array_keys(self::AREAS) as $area) {
foreach (app(Widgets::class)->forAdmin($area) as $widget) {
if ($widget['key'] === $key) {
return $widget['areas'];
}
}
}
return [];
}
public function form(Schema $schema): Schema
{
return $schema->statePath('data')->components([
Section::make('Art der Startseite')
->schema([
Radio::make('mode')
->hiddenLabel()
->live()
->options([
'widgets' => 'Kacheln – feste Bereiche, Anordnung unten festlegen',
'builder' => 'Frei gestaltet – mit dem Baukasten („Startseite gestalten“)',
])
->helperText(fn () => (app(Branding::class)->interface() === 'app'
? 'Hinweis: In der Oberfläche „Mitarbeiter-App“ hat die Startseite einen festen Aufbau aus Kacheln (links Begrüßung, Anwendungen und Gruppen, in der Mitte Neuigkeiten, rechts der Tag). Die frei gestaltete Startseite gilt nur für „Klassisch“. '
: '').(app(Homepage::class)->published() === null
? 'Die freie Gestaltung ist noch nicht veröffentlicht – bis dahin bleiben die Kacheln sichtbar. Beim ersten Öffnen übernimmt der Baukasten die heutige Anordnung.'
: 'Alle Kacheln stehen im Baukasten als Block „Kachel“ zur Verfügung.')),
]),
...collect(self::AREAS)->map(fn ($info, $area) => Section::make($info[0])
->description($info[1] ?: null)
->visible(fn (Get $get) => ($get('mode') !== 'builder' || app(Branding::class)->interface() === 'app') && app(Widgets::class)->forAdmin($area) !== [])
->schema([
Repeater::make($area)
->hiddenLabel()
->reorderable()
->reorderableWithDragAndDrop()
->addable(false)
->deletable(false)
// Kompakt als Tabelle: eine Zeile je Kachel
->table([
TableColumn::make('Kachel'),
TableColumn::make('Anzeigen')->width('7rem'),
TableColumn::make('Platzierung')->width('16rem'),
])
->schema([
Hidden::make('key'),
TextInput::make('label')->hiddenLabel()->readOnly()->dehydrated(false)->extraInputAttributes(['tabindex' => '-1'])->extraFieldWrapperAttributes(['class' => 'ih-plain']),
Toggle::make('visible')->hiddenLabel(),
Select::make('area')
->hiddenLabel()
->options(fn (Get $get) => collect(self::areasOf($get('key')))->mapWithKeys(fn ($a) => [$a => self::AREAS[$a][0]])->all())
->selectablePlaceholder(false)
->visible(fn (Get $get) => count(self::areasOf($get('key'))) > 1),
]),
]))->values()->all(),
Section::make('Kachel „Kolleg:innen finden“')
->description('Welche Angaben auf den Kontaktkarten der Live-Suche erscheinen – in dieser Reihenfolge. Name, Foto, Funktion und Abteilung stehen immer oben.')
->schema([
Select::make('people_fields')
->hiddenLabel()
->multiple()
->options(fn () => app(ContactCards::class)->options()),
]),
]);
}
public function save(Settings $settings): void
{
$layout = [];
foreach (array_keys(self::AREAS) as $area) {
foreach (array_values($this->data[$area] ?? []) as $index => $item) {
$layout[$item['key']] = ['sort' => $index * 10, 'visible' => (bool) ($item['visible'] ?? true)];
if (in_array($item['area'] ?? null, self::areasOf($item['key']), true)) {
$layout[$item['key']]['area'] = $item['area'];
}
}
}
// Bei „Frei gestaltet“ sind die Kachel-Bereiche ausgeblendet – ihre Anordnung bleibt dann unverändert
if (($this->data['mode'] ?? 'widgets') !== 'builder' || app(Branding::class)->interface() === 'app') {
$settings->set('dashboard.layout', $layout);
}
app(Homepage::class)->setMode((string) ($this->data['mode'] ?? 'widgets'));
$settings->set(ContactCards::PEOPLE_SEARCH_FIELDS, array_values(array_intersect((array) ($this->data['people_fields'] ?? []), array_keys(app(ContactCards::class)->options()))));
// Verschobene Kacheln im Formular in ihren neuen Bereich umsortieren
$this->mount(app(Widgets::class));
Notification::make()->success()->title('Startseite gespeichert')->send();
}
protected function getHeaderActions(): array
{
return [
Action::make('design')->label('Startseite gestalten')->icon(Heroicon::OutlinedPaintBrush)
->url('/startseite/gestalten'),
Action::make('tiles')->label('Eigene Kacheln')->icon(Heroicon::OutlinedRectangleGroup)->color('gray')
->url(fn () => DashboardTileResource::getUrl()),
Action::make('preview')->label('Startseite ansehen')->icon(Heroicon::OutlinedEye)->color('gray')
->url('/')->openUrlInNewTab(),
];
}
}