Startseite: acht Bereichs-Beiträge, Schnellzugriffe wahlweise in der Seitenleiste
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m7s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m13s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m27s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m12s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m41s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 17:44:32 +00:00
parent 4332b02efb
commit 3a5796aaf8
101 changed files with 519 additions and 405 deletions

View file

@ -24,7 +24,7 @@ class CoreWidgets
$widgets->add('core.quick-links', 'core::QuickLinks', 'main', sort: 10, props: fn () => [
'links' => app(QuickLinks::class)->all(),
], label: 'Schnellzugriffe', mobileSort: 40);
], label: 'Schnellzugriffe', mobileSort: 40, areas: ['main', 'aside']);
$widgets->add('core.new-colleagues', 'core::NewColleagues', 'main', sort: 90, props: function (User $user) {
$people = User::query()

View file

@ -18,6 +18,9 @@ use Throwable;
* hero – groß links oben (z. B. Slider) feed – neben hero
* main – volle Breite der linken Spalte aside – rechte Spalte
*
* Kacheln mit mehreren erlaubten Bereichen ($areas) kann die Administration
* unter „Portal → Startseite“ zwischen diesen Bereichen verschieben.
*
* Die Props-Funktion liefert die Daten der Kachel oder null, wenn sie für
* diese Person nichts anzuzeigen hat.
*/
@ -25,7 +28,7 @@ class Widgets
{
public const AREAS = ['top', 'hero', 'feed', 'main', 'aside'];
/** @var array<string, array{component: string, area: string, sort: int, mobileSort: int, props: callable, label: string}> */
/** @var array<string, array{component: string, area: string, areas: list<string>, sort: int, mobileSort: int, props: callable, label: string}> */
private array $widgets = [];
/**
@ -33,17 +36,22 @@ class Widgets
* @param callable(User, Request): (array<string, mixed>|null) $props
* @param int|null $mobileSort Reihenfolge in der einspaltigen Mobilansicht (Standard: nach Bereich)
* @param string|null $label Name im Admin unter „Startseite“
* @param list<string> $areas Bereiche, in die die Administration die Kachel verschieben darf
*/
public function add(string $key, string $component, string $area, int $sort, callable $props, ?int $mobileSort = null, ?string $label = null): void
public function add(string $key, string $component, string $area, int $sort, callable $props, ?int $mobileSort = null, ?string $label = null, array $areas = []): void
{
if (! in_array($area, self::AREAS, true)) {
throw new \InvalidArgumentException("Unbekannter Bereich „{$area}“ für Kachel {$key}.");
$areas = array_values(array_unique([$area, ...$areas]));
foreach ($areas as $candidate) {
if (! in_array($candidate, self::AREAS, true)) {
throw new \InvalidArgumentException("Unbekannter Bereich „{$candidate}“ für Kachel {$key}.");
}
}
$mobileSort ??= ['top' => -100, 'hero' => 10, 'feed' => 20, 'aside' => 30, 'main' => 50][$area] + $sort;
$label ??= $key;
$this->widgets[$key] = compact('component', 'area', 'sort', 'mobileSort', 'props', 'label');
$this->widgets[$key] = compact('component', 'area', 'areas', 'sort', 'mobileSort', 'props', 'label');
}
public function remove(string $key): void
@ -55,7 +63,7 @@ class Widgets
* Alle Kacheln eines Bereichs für den Admin: mitgelieferte und eigene,
* in gespeicherter Reihenfolge, mit Sichtbarkeit.
*
* @return list<array{key: string, label: string, area: string, visible: bool, custom: bool}>
* @return list<array{key: string, label: string, area: string, areas: list<string>, visible: bool, custom: bool}>
*/
public function forAdmin(string $area): array
{
@ -67,6 +75,7 @@ class Widgets
'key' => $key,
'label' => $w['label'],
'area' => $w['area'],
'areas' => $w['areas'],
'visible' => $layout[$key]['visible'] ?? true,
'custom' => $w['custom'] ?? false,
])
@ -96,6 +105,7 @@ class Widgets
'sort' => 1000 + $tile->id,
'mobileSort' => ['top' => -50, 'main' => 45, 'aside' => 32][$tile->area] ?? 32,
'props' => fn () => $tile->toWidgetProps(),
'areas' => [],
'label' => 'Eigene Kachel: '.$tile->name,
'custom' => true,
];
@ -103,13 +113,24 @@ class Widgets
$layout = $this->layout();
// Von der Administration verschobene Kacheln (nur in erlaubte Bereiche)
$widgets = $widgets->map(function (array $w, string $key) use ($layout) {
$moved = $layout[$key]['area'] ?? null;
if ($moved && in_array($moved, $w['areas'] ?? [], true)) {
$w['area'] = $moved;
}
return $w;
});
return $widgets->sortBy(fn (array $w, string $key) => $layout[$key]['sort'] ?? $w['sort']);
}
/**
* Gespeicherte Anordnung: Schlüssel => [sort, visible].
* Gespeicherte Anordnung: Schlüssel => [sort, visible, area].
*
* @return array<string, array{sort?: int, visible?: bool}>
* @return array<string, array{sort?: int, visible?: bool, area?: string}>
*/
private function layout(): array
{

View file

@ -9,10 +9,12 @@ 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\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;
use UnitEnum;
@ -58,6 +60,24 @@ class DashboardSettings extends Page
$this->form->fill(collect(self::AREAS)->mapWithKeys(fn ($info, $area) => [$area => $widgets->forAdmin($area)])->all());
}
/**
* 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(
@ -72,10 +92,17 @@ class DashboardSettings extends Page
->addable(false)
->deletable(false)
->itemLabel(fn (array $state) => $state['label'] ?? $state['key'])
->columns(2)
->schema([
Hidden::make('key'),
Hidden::make('label'),
Toggle::make('visible')->label('Anzeigen'),
Toggle::make('visible')->label('Anzeigen')->inline(false),
Select::make('area')
->label('Platzierung')
->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)
->helperText('Wird nach dem Speichern in den gewählten Bereich verschoben.'),
]),
]))->values()->all()
);
@ -88,11 +115,18 @@ class DashboardSettings extends Page
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'];
}
}
}
$settings->set('dashboard.layout', $layout);
// Verschobene Kacheln im Formular in ihren neuen Bereich umsortieren
$this->mount(app(Widgets::class));
Notification::make()->success()->title('Startseite gespeichert')->send();
}

View file

@ -9,5 +9,5 @@ namespace App;
*/
final class Version
{
public const VERSION = '0.12.0';
public const VERSION = '0.12.1';
}