Feste Profilfelder in Formularen, Geburtstage, anpassbare Startseite
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m21s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m8s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m43s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m1s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m21s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m8s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m43s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m1s
- Formulare: Felder fest aus dem Profil (nicht änderbar, Server setzt den Profilwert ein), Hinweis bei fehlender Profilangabe - Geburtstage (optionales Plugin, standardmäßig aus): Tag und Monat freiwillig im Profil, Kachel, Liste /geburtstage, Pagebuilder-Block, Glückwunsch am eigenen Geburtstag; Sichtbarkeit alle/Abteilung/Standort - Startseite: Kacheln je Bereich sortieren und ausblenden; eigene Kacheln (Bild mit Link, Text, Hinweis) mit Zeitraum und Zielgruppe - Kern: optionale mitgelieferte Plugins, Startseitenbereich „top“, Profilabschnitte für Plugins, Kachel-Bezeichnungen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
435960725d
commit
ee8dde93c0
262 changed files with 2385 additions and 692 deletions
|
|
@ -20,11 +20,11 @@ class CoreWidgets
|
|||
'location' => $user->location,
|
||||
'avatar_url' => $user->avatarUrl(256),
|
||||
],
|
||||
], mobileSort: 0);
|
||||
], label: 'Begrüßung mit Profil', mobileSort: 0);
|
||||
|
||||
$widgets->add('core.quick-links', 'core::QuickLinks', 'main', sort: 10, props: fn () => [
|
||||
'links' => app(QuickLinks::class)->all(),
|
||||
], mobileSort: 40);
|
||||
], label: 'Schnellzugriffe', mobileSort: 40);
|
||||
|
||||
$widgets->add('core.new-colleagues', 'core::NewColleagues', 'main', sort: 90, props: function (User $user) {
|
||||
$people = User::query()
|
||||
|
|
@ -36,12 +36,12 @@ class CoreWidgets
|
|||
->get();
|
||||
|
||||
return $people->isEmpty() ? null : ['people' => PersonResource::collection($people)->resolve()];
|
||||
}, mobileSort: 60);
|
||||
}, label: 'Neue Kolleginnen und Kollegen', mobileSort: 60);
|
||||
|
||||
$widgets->add('core.profile-incomplete', 'core::ProfileIncomplete', 'aside', sort: 50, props: fn (User $user) => $user->avatar_path && $user->job_title ? null : [], mobileSort: 70);
|
||||
$widgets->add('core.profile-incomplete', 'core::ProfileIncomplete', 'aside', sort: 50, props: fn (User $user) => $user->avatar_path && $user->job_title ? null : [], label: 'Hinweis „Profil vervollständigen“', mobileSort: 70);
|
||||
|
||||
$widgets->add('core.people-search', 'core::PeopleSearch', 'aside', sort: 60, props: fn () => [
|
||||
'count' => User::query()->active()->count(),
|
||||
], mobileSort: 80);
|
||||
], label: 'Personen finden', mobileSort: 80);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace App\Dashboard;
|
||||
|
||||
use App\Models\DashboardTile;
|
||||
use App\Models\User;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
|
|
@ -11,6 +14,7 @@ use Throwable;
|
|||
* Kacheln der Startseite als Registry.
|
||||
*
|
||||
* Bereiche (siehe resources/js/pages/Dashboard.vue):
|
||||
* top – volle Breite über allem (Hinweise, z. B. Geburtstagsgruß)
|
||||
* hero – groß links oben (z. B. Slider) feed – neben hero
|
||||
* main – volle Breite der linken Spalte aside – rechte Spalte
|
||||
*
|
||||
|
|
@ -19,25 +23,27 @@ use Throwable;
|
|||
*/
|
||||
class Widgets
|
||||
{
|
||||
public const AREAS = ['hero', 'feed', 'main', 'aside'];
|
||||
public const AREAS = ['top', 'hero', 'feed', 'main', 'aside'];
|
||||
|
||||
/** @var array<string, array{component: string, area: string, sort: int, mobileSort: int, props: callable}> */
|
||||
/** @var array<string, array{component: string, area: string, sort: int, mobileSort: int, props: callable, label: string}> */
|
||||
private array $widgets = [];
|
||||
|
||||
/**
|
||||
* @param string $component Vue-Komponente, z. B. „core::QuickLinks“ oder „news::Hero“
|
||||
* @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“
|
||||
*/
|
||||
public function add(string $key, string $component, string $area, int $sort, callable $props, ?int $mobileSort = null): void
|
||||
public function add(string $key, string $component, string $area, int $sort, callable $props, ?int $mobileSort = null, ?string $label = null): void
|
||||
{
|
||||
if (! in_array($area, self::AREAS, true)) {
|
||||
throw new \InvalidArgumentException("Unbekannter Bereich „{$area}“ für Kachel {$key}.");
|
||||
}
|
||||
|
||||
$mobileSort ??= ['hero' => 10, 'feed' => 20, 'aside' => 30, 'main' => 50][$area] + $sort;
|
||||
$mobileSort ??= ['top' => -100, 'hero' => 10, 'feed' => 20, 'aside' => 30, 'main' => 50][$area] + $sort;
|
||||
|
||||
$this->widgets[$key] = compact('component', 'area', 'sort', 'mobileSort', 'props');
|
||||
$label ??= $key;
|
||||
$this->widgets[$key] = compact('component', 'area', 'sort', 'mobileSort', 'props', 'label');
|
||||
}
|
||||
|
||||
public function remove(string $key): void
|
||||
|
|
@ -45,6 +51,71 @@ class Widgets
|
|||
unset($this->widgets[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}>
|
||||
*/
|
||||
public function forAdmin(string $area): array
|
||||
{
|
||||
$layout = $this->layout();
|
||||
|
||||
return $this->candidates()
|
||||
->filter(fn (array $w) => $w['area'] === $area)
|
||||
->map(fn (array $w, string $key) => [
|
||||
'key' => $key,
|
||||
'label' => $w['label'],
|
||||
'area' => $w['area'],
|
||||
'visible' => $layout[$key]['visible'] ?? true,
|
||||
'custom' => $w['custom'] ?? false,
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mitgelieferte Kacheln plus eigene Kacheln, sortiert nach gespeicherter Anordnung.
|
||||
*
|
||||
* @return Collection<string, array<string, mixed>>
|
||||
*/
|
||||
private function candidates(?User $user = null)
|
||||
{
|
||||
$widgets = collect($this->widgets);
|
||||
|
||||
try {
|
||||
$tiles = DashboardTile::query()->when($user, fn ($q) => $q->visibleTo($user))->get();
|
||||
} catch (Throwable) {
|
||||
$tiles = collect(); // Tabelle noch nicht angelegt (Aktualisierung läuft)
|
||||
}
|
||||
|
||||
foreach ($tiles as $tile) {
|
||||
$widgets[$tile->widgetKey()] = [
|
||||
'component' => 'core::CustomTile',
|
||||
'area' => array_key_exists($tile->area, DashboardTile::AREAS) ? $tile->area : 'aside',
|
||||
'sort' => 1000 + $tile->id,
|
||||
'mobileSort' => ['top' => -50, 'main' => 45, 'aside' => 32][$tile->area] ?? 32,
|
||||
'props' => fn () => $tile->toWidgetProps(),
|
||||
'label' => 'Eigene Kachel: '.$tile->name,
|
||||
'custom' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$layout = $this->layout();
|
||||
|
||||
return $widgets->sortBy(fn (array $w, string $key) => $layout[$key]['sort'] ?? $w['sort']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gespeicherte Anordnung: Schlüssel => [sort, visible].
|
||||
*
|
||||
* @return array<string, array{sort?: int, visible?: bool}>
|
||||
*/
|
||||
private function layout(): array
|
||||
{
|
||||
return (array) app(Settings::class)->get('dashboard.layout', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{key: string, component: string, area: string, mobileSort: int, props: array<string, mixed>}>
|
||||
*/
|
||||
|
|
@ -52,7 +123,13 @@ class Widgets
|
|||
{
|
||||
$result = [];
|
||||
|
||||
foreach (collect($this->widgets)->sortBy('sort') as $key => $widget) {
|
||||
$layout = $this->layout();
|
||||
|
||||
foreach ($this->candidates($user) as $key => $widget) {
|
||||
if (($layout[$key]['visible'] ?? true) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$props = ($widget['props'])($user, $request);
|
||||
} catch (Throwable $e) {
|
||||
|
|
|
|||
108
app/Filament/Pages/DashboardSettings.php
Normal file
108
app/Filament/Pages/DashboardSettings.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Filament\Resources\DashboardTiles\DashboardTileResource;
|
||||
use App\Support\Settings;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* 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|UnitEnum|null $navigationGroup = 'Portal';
|
||||
|
||||
protected static ?int $navigationSort = 10;
|
||||
|
||||
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(collect(self::AREAS)->mapWithKeys(fn ($info, $area) => [$area => $widgets->forAdmin($area)])->all());
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->statePath('data')->components(
|
||||
collect(self::AREAS)->map(fn ($info, $area) => Section::make($info[0])
|
||||
->description($info[1] ?: null)
|
||||
->visible(fn () => app(Widgets::class)->forAdmin($area) !== [])
|
||||
->schema([
|
||||
Repeater::make($area)
|
||||
->hiddenLabel()
|
||||
->reorderable()
|
||||
->reorderableWithDragAndDrop()
|
||||
->addable(false)
|
||||
->deletable(false)
|
||||
->itemLabel(fn (array $state) => $state['label'] ?? $state['key'])
|
||||
->schema([
|
||||
Hidden::make('key'),
|
||||
Hidden::make('label'),
|
||||
Toggle::make('visible')->label('Anzeigen'),
|
||||
]),
|
||||
]))->values()->all()
|
||||
);
|
||||
}
|
||||
|
||||
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)];
|
||||
}
|
||||
}
|
||||
|
||||
$settings->set('dashboard.layout', $layout);
|
||||
|
||||
Notification::make()->success()->title('Startseite gespeichert')->send();
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
104
app/Filament/Resources/DashboardTiles/DashboardTileResource.php
Normal file
104
app/Filament/Resources/DashboardTiles/DashboardTileResource.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DashboardTiles;
|
||||
|
||||
use App\Filament\Components\AudienceSection;
|
||||
use App\Filament\Resources\DashboardTiles\Pages\ManageDashboardTiles;
|
||||
use App\Models\DashboardTile;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Eigene Kacheln der Startseite. Reihenfolge und Ein-/Ausblenden unter „Startseite“.
|
||||
*/
|
||||
class DashboardTileResource extends Resource
|
||||
{
|
||||
protected static ?string $model = DashboardTile::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleGroup;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Portal';
|
||||
|
||||
protected static ?int $navigationSort = 11;
|
||||
|
||||
protected static ?string $modelLabel = 'Eigene Kachel';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Eigene Kacheln';
|
||||
|
||||
protected static ?string $slug = 'kacheln';
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('appearance.manage') ?? false;
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
$type = fn (string ...$types) => fn (Get $get) => in_array($get('type'), $types, true);
|
||||
|
||||
return $schema->columns(2)->components([
|
||||
TextInput::make('name')->label('Name (nur im Admin)')->required()->maxLength(100),
|
||||
Select::make('type')->label('Art')->options(DashboardTile::TYPES)->default('image')->required()->live()->native(false),
|
||||
Select::make('area')->label('Bereich')->options(DashboardTile::AREAS)->default('aside')->required()->native(false)
|
||||
->helperText('Die Reihenfolge innerhalb des Bereichs legen Sie unter „Startseite“ fest.'),
|
||||
TextInput::make('title')->label(fn (Get $get) => $get('type') === 'image' ? 'Bildunterschrift (optional)' : 'Überschrift')->maxLength(150),
|
||||
|
||||
FileUpload::make('image_path')->label('Bild')->image()->disk('uploads')->directory('dashboard')->visibility('public')
|
||||
->maxSize(8 * 1024)->required($type('image'))->visible($type('image'))->columnSpanFull()
|
||||
->helperText('Für die Seitenleiste z. B. 800 × 600 Pixel, für „ganz oben“ ein breites Banner (z. B. 2400 × 500).'),
|
||||
TextInput::make('alt')->label('Alternativtext')->maxLength(200)->visible($type('image'))->helperText('Beschreibt das Bild für Screenreader.'),
|
||||
|
||||
RichEditor::make('body')->label('Text')->toolbarButtons([['bold', 'italic', 'link'], ['bulletList', 'orderedList'], ['undo', 'redo']])
|
||||
->required($type('text', 'notice'))->visible($type('text', 'notice'))->columnSpanFull(),
|
||||
Select::make('variant')->label('Farbe')->options(DashboardTile::VARIANTS)->default('brand')->visible($type('notice'))->native(false),
|
||||
|
||||
TextInput::make('url')->label('Link')->placeholder('https://… oder /seiten/…')->maxLength(2000),
|
||||
Toggle::make('new_tab')->label('In neuem Tab öffnen')->inline(false),
|
||||
|
||||
Section::make('Anzeige')->columnSpanFull()->columns(3)->schema([
|
||||
Toggle::make('is_active')->label('Aktiv')->default(true)->inline(false),
|
||||
DateTimePicker::make('starts_at')->label('Ab')->native(false)->seconds(false)->displayFormat('d.m.Y H:i'),
|
||||
DateTimePicker::make('ends_at')->label('Bis')->native(false)->seconds(false)->displayFormat('d.m.Y H:i')->after('starts_at'),
|
||||
]),
|
||||
AudienceSection::make('dashboard_tile', 'Wer die Kachel sieht. Leer lassen = alle.')->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
ImageColumn::make('image_path')->label('')->disk('uploads')->width(64)->height(40),
|
||||
TextColumn::make('name')->label('Name')->weight('medium')->searchable(),
|
||||
TextColumn::make('type')->label('Art')->formatStateUsing(fn (string $state) => DashboardTile::TYPES[$state] ?? $state),
|
||||
TextColumn::make('area')->label('Bereich')->formatStateUsing(fn (string $state) => DashboardTile::AREAS[$state] ?? $state),
|
||||
IconColumn::make('is_active')->label('Aktiv')->boolean(),
|
||||
TextColumn::make('ends_at')->label('Bis')->dateTime('d.m.Y H:i')->placeholder('–'),
|
||||
])
|
||||
->recordActions([EditAction::make(), DeleteAction::make()])
|
||||
->emptyStateHeading('Noch keine eigenen Kacheln')
|
||||
->emptyStateDescription('Zum Beispiel ein verlinktes Bild in der Seitenleiste oder ein Hinweis ganz oben.');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return ['index' => ManageDashboardTiles::route('/')];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DashboardTiles\Pages;
|
||||
|
||||
use App\Filament\Pages\DashboardSettings;
|
||||
use App\Filament\Resources\DashboardTiles\DashboardTileResource;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
|
||||
class ManageDashboardTiles extends ManageRecords
|
||||
{
|
||||
protected static string $resource = DashboardTileResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('layout')->label('Anordnung der Startseite')->icon(Heroicon::OutlinedSquares2x2)->color('gray')
|
||||
->url(fn () => DashboardSettings::getUrl()),
|
||||
CreateAction::make()->label('Kachel anlegen'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Http\Requests\UpdateProfileRequest;
|
||||
use App\Models\User;
|
||||
use App\Profile\ProfileSections;
|
||||
use App\Support\Avatars;
|
||||
use App\Support\ProfileFields;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
|
@ -39,6 +40,7 @@ class ProfileController extends Controller
|
|||
// Felder, die Microsoft Entra ID pflegt – im Portal nur lesbar.
|
||||
'managed' => $managed,
|
||||
'customFields' => $profileFields->formFor($user, $managed),
|
||||
'sections' => app(ProfileSections::class)->resolve($user),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
94
app/Models/DashboardTile.php
Normal file
94
app/Models/DashboardTile.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Pagebuilder\Field;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Eigene Kachel auf der Startseite („Administration → Portal → Startseite“).
|
||||
*/
|
||||
#[Fillable(['name', 'type', 'area', 'title', 'image_path', 'url', 'new_tab', 'alt', 'body', 'variant', 'is_active', 'starts_at', 'ends_at'])]
|
||||
class DashboardTile extends Model
|
||||
{
|
||||
public const TYPES = [
|
||||
'image' => 'Bild mit Link',
|
||||
'text' => 'Text',
|
||||
'notice' => 'Hinweis',
|
||||
];
|
||||
|
||||
public const AREAS = [
|
||||
'aside' => 'Seitenleiste (rechts)',
|
||||
'main' => 'Hauptspalte (breit)',
|
||||
'top' => 'Ganz oben (volle Breite)',
|
||||
];
|
||||
|
||||
public const VARIANTS = [
|
||||
'brand' => 'Markenfarbe',
|
||||
'info' => 'Info (blau)',
|
||||
'success' => 'Erfolg (grün)',
|
||||
'warning' => 'Warnung (rot)',
|
||||
'neutral' => 'Neutral (grau)',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (DashboardTile $tile) {
|
||||
$tile->url = filled($tile->url) ? (Field::safeUrl($tile->url) ?: null) : null;
|
||||
|
||||
if ($tile->isDirty('body')) {
|
||||
$tile->body_html = app(RichText::class)->toSafeHtml($tile->body);
|
||||
}
|
||||
});
|
||||
|
||||
static::deleted(fn (DashboardTile $tile) => $tile->image_path && Storage::disk('uploads')->delete($tile->image_path));
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['new_tab' => 'boolean', 'is_active' => 'boolean', 'starts_at' => 'datetime', 'ends_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function widgetKey(): string
|
||||
{
|
||||
return 'tile.'.$this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktiv, im Zeitraum und für die Person sichtbar.
|
||||
*
|
||||
* @param Builder<DashboardTile> $query
|
||||
*/
|
||||
public function scopeVisibleTo(Builder $query, User $user): void
|
||||
{
|
||||
$query->where('is_active', true)
|
||||
->where(fn ($q) => $q->whereNull('starts_at')->orWhere('starts_at', '<=', now()))
|
||||
->where(fn ($q) => $q->whereNull('ends_at')->orWhere('ends_at', '>', now()));
|
||||
|
||||
Audiences::constrain($query, 'dashboard_tile', 'dashboard_tiles.id', $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toWidgetProps(): array
|
||||
{
|
||||
return [
|
||||
'tile' => [
|
||||
'type' => $this->type,
|
||||
'title' => $this->title,
|
||||
'image_url' => $this->image_path ? Storage::disk('uploads')->url($this->image_path) : null,
|
||||
'url' => $this->url,
|
||||
'new_tab' => $this->new_tab,
|
||||
'alt' => $this->alt ?: '',
|
||||
'html' => $this->body_html,
|
||||
'variant' => $this->variant ?: 'brand',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ final class PluginManifest
|
|||
public readonly bool $core,
|
||||
public readonly array $requires,
|
||||
public readonly ?string $updateUrl,
|
||||
public readonly bool $enabledByDefault = true,
|
||||
) {}
|
||||
|
||||
public static function fromDirectory(string $path, bool $core): self
|
||||
|
|
@ -90,6 +91,7 @@ final class PluginManifest
|
|||
core: $core,
|
||||
requires: is_array($data['requires'] ?? null) ? $data['requires'] : [],
|
||||
updateUrl: is_string($data['update_url'] ?? null) ? $data['update_url'] : null,
|
||||
enabledByDefault: (bool) ($data['enabled_by_default'] ?? true),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,17 @@ use App\Support\Update\AtomicFile;
|
|||
/**
|
||||
* Aktivierungszustand der Plugins in storage/app/plugins.json – als Datei, damit
|
||||
* das Laden der Plugins keine Datenbankabfrage kostet und auch ohne DB klappt.
|
||||
* Mitgelieferte Plugins sind aktiv, solange nichts anderes vermerkt ist.
|
||||
* Mitgelieferte Plugins sind aktiv, solange nichts anderes vermerkt ist – außer sie
|
||||
* sind als optional markiert („enabled_by_default“: false in plugin.json).
|
||||
*/
|
||||
class PluginState
|
||||
{
|
||||
/**
|
||||
* Test-Suite: optionale mitgelieferte Plugins ebenfalls laden, damit ihre
|
||||
* Tabellen und Tests dabei sind (gesetzt in tests/TestCase.php).
|
||||
*/
|
||||
public static bool $enableOptionalCorePlugins = false;
|
||||
|
||||
/** @var array<string, array<string, mixed>>|null */
|
||||
private ?array $data = null;
|
||||
|
||||
|
|
@ -20,7 +27,7 @@ class PluginState
|
|||
{
|
||||
$entry = $this->all()[$manifest->slug] ?? null;
|
||||
|
||||
return is_array($entry) ? (bool) ($entry['enabled'] ?? false) : $manifest->core;
|
||||
return is_array($entry) ? (bool) ($entry['enabled'] ?? false) : $manifest->core && ($manifest->enabledByDefault || self::$enableOptionalCorePlugins);
|
||||
}
|
||||
|
||||
public function setEnabled(string $slug, bool $enabled, ?string $reason = null): void
|
||||
|
|
|
|||
52
app/Profile/ProfileSections.php
Normal file
52
app/Profile/ProfileSections.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Profile;
|
||||
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Zusätzliche Abschnitte in „Profil bearbeiten“, beigesteuert von Plugins
|
||||
* (z. B. „Geburtstag“). Die Vue-Komponente liegt unter
|
||||
* plugins-core/<plugin>/resources/js/profile/<Name>.vue („<plugin>::Name“)
|
||||
* und speichert über eigene Routen des Plugins.
|
||||
*/
|
||||
class ProfileSections
|
||||
{
|
||||
/** @var array<string, array{component: string, sort: int, props: Closure}> */
|
||||
private array $sections = [];
|
||||
|
||||
/**
|
||||
* @param Closure(User): (array<string, mixed>|null) $props null = Abschnitt nicht zeigen
|
||||
*/
|
||||
public function add(string $key, string $component, int $sort, Closure $props): void
|
||||
{
|
||||
$this->sections[$key] = compact('component', 'sort', 'props');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{key: string, component: string, props: array<string, mixed>}>
|
||||
*/
|
||||
public function resolve(User $user): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach (collect($this->sections)->sortBy('sort') as $key => $section) {
|
||||
try {
|
||||
$props = ($section['props'])($user);
|
||||
} catch (Throwable $e) {
|
||||
Log::error("Profilabschnitt {$key} fehlgeschlagen: ".$e->getMessage());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($props !== null) {
|
||||
$result[] = ['key' => $key, 'component' => $section['component'], 'props' => $props];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace App\Providers\Filament;
|
|||
|
||||
use App\Filament\AvatarProviders\InitialsAvatarProvider;
|
||||
use App\Filament\Pages\Feedback;
|
||||
use App\Filament\Resources\DashboardTiles\DashboardTileResource;
|
||||
use App\Filament\Resources\IdentityProviders\IdentityProviderResource;
|
||||
use App\Filament\Resources\ProfileFields\ProfileFieldResource;
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
|
|
@ -65,6 +66,7 @@ class AdminPanelProvider extends PanelProvider
|
|||
UserResource::class,
|
||||
RoleResource::class,
|
||||
ProfileFieldResource::class,
|
||||
DashboardTileResource::class,
|
||||
IdentityProviderResource::class,
|
||||
])
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Dashboard\Widgets;
|
|||
use App\Plugins\Hooks;
|
||||
use App\Plugins\PluginManager;
|
||||
use App\Plugins\PluginState;
|
||||
use App\Profile\ProfileSections;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
|
@ -24,6 +25,7 @@ class PluginServiceProvider extends ServiceProvider
|
|||
$this->app->singleton(Navigation::class);
|
||||
$this->app->singleton(Widgets::class);
|
||||
$this->app->singleton(Abilities::class);
|
||||
$this->app->singleton(ProfileSections::class);
|
||||
|
||||
$this->app->make(PluginManager::class)->registerAll();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue