diff --git a/CHANGELOG.md b/CHANGELOG.md index 42a8e92e..65072955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,35 @@ Neueste Version oben. Jeder Abschnitt beginnt mit `## MAJOR.MINOR.PATCH` und enthält kurze Stichpunkte für Anwenderinnen und Anwender – keine Commit-Texte. Der Self-Updater zeigt diese Abschnitte bei neuen Versionen an. +## 0.7.0 + +- Erscheinungsbild vollständig anpassbar: Portalname, Logos für helle und dunkle Flächen, Signet für Smartphones, App-Symbol für Favicon und Homescreen +- Markenfarbe wird exakt übernommen, optional eine zweite Akzentfarbe; Kopfleiste hell, in der Markenfarbe oder dunkel +- Kontrastprüfung nach WCAG AA: zu helle Markenfarben bekommen automatisch gut lesbare Linkfarben +- Schriften zur Auswahl oder als eigene Datei, auch getrennt für Überschriften – immer vom eigenen Server, nie von Google +- Ecken, Abstände und Dunkelmodus (frei wählbar, immer hell oder immer dunkel) einstellbar +- Anmeldeseite mit Hintergrundbild, eigenem Begrüßungstext und zwei Aufteilungen +- Fußzeile mit Links (z. B. Impressum, Datenschutz); E-Mails im gleichen Design mit eigener Fußzeile +- Entwurf, Live-Vorschau (Startseite, Anmeldung, Beispielseite – hell und dunkel) und Veröffentlichen; Export, Import und Zurücksetzen +- Eigenes CSS für Fortgeschrittene +- Der Admin-Bereich übernimmt Logo, Farbe und Favicon; „Inhaus“ erscheint nirgends mehr zwingend +- Hochgeladene SVG-Logos werden von Skripten bereinigt + +## 0.6.0 + +- Formulare: Anträge, Anmeldungen, Umfragen und Meldungen im visuellen Baukasten zusammenstellen – so, wie das Formular später aussieht: Bezeichnungen und Auswahlmöglichkeiten direkt bearbeiten, Felder per Ziehen und Ablegen anordnen, Vorschau mit Bedingungen +- Felder lassen sich abhängig von anderen Antworten ein- und ausblenden und aus dem Profil vorbelegen +- Einsendungen landen im Backend und per E-Mail bei festen Empfängern; auf Wunsch eine Kopie an die ausfüllende Person +- Zugriff auf die Ergebnisse je Formular und Rolle – ansehen und exportieren (CSV für Excel) bzw. löschen getrennt vergebbar +- Anonyme Formulare, „nur einmal ausfüllen“, Einsendeschluss, Sichtbarkeit und automatische Löschfrist +- Formularfelder lassen sich fest mit Profilangaben füllen (z. B. Vorname, Personalnummer, Abteilung) – nicht änderbar, beim Absenden gilt immer der Profilwert +- Formulare lassen sich mit dem Pagebuilder in Seiten und unter Neuigkeiten-Beiträgen einbinden +- Ergebnisse als CSV herunterladen – alle oder nur ausgewählte Einsendungen +- WordPress-Import: Beiträge mit Kategorien, Autorinnen und Autoren, Beitragsbildern und Bildern im Text übernehmen, auf Wunsch auch Seiten – wiederholbar, ohne Doppelungen +- E-Mail-Versand im Admin einrichten (SMTP), mit Test-Mail +- Startseite anpassen: Kacheln je Bereich sortieren und ausblenden, eigene Kacheln anlegen – Bild mit Link, Text oder Hinweis, mit Zeitraum und Zielgruppe +- Geburtstage (optional, unter „Plugins“ zu aktivieren): Mitarbeitende tragen freiwillig Tag und Monat im Profil ein; Kachel und Liste der anstehenden Geburtstage, Glückwunsch auf der Startseite am eigenen Geburtstag + ## 0.5.0 - Seiten: eigener Seitenbaum für Bereiche, Abteilungen und Gremien – mit Seitennavigation, Brotkrumen und optional in der Hauptnavigation diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2efe91d9..20a5ccb6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,3 +66,10 @@ und danach `bin/build` ausführen, damit `vendor/` nachzieht. `text-muted-foreground` …), nie fest verdrahtet – sonst greift das Branding nicht - N+1-Abfragen vermeiden: `Model::preventLazyLoading()` ist außerhalb der Produktion aktiv + +## Schriften + +Die mitgelieferten Schriften kommen aus `@fontsource`-Paketen, eingebunden nur +mit den Zeichensätzen Latein und Latein-Erweitert. Nach dem Hinzufügen einer +Schrift `python3 scripts/generate-fonts-css.py` ausführen und die Schrift in +`App\Support\Theme\Fonts` eintragen. diff --git a/app/Dashboard/CoreWidgets.php b/app/Dashboard/CoreWidgets.php index 22f36128..ab49798b 100644 --- a/app/Dashboard/CoreWidgets.php +++ b/app/Dashboard/CoreWidgets.php @@ -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); } } diff --git a/app/Dashboard/Widgets.php b/app/Dashboard/Widgets.php index 17c437a5..1e3069dc 100644 --- a/app/Dashboard/Widgets.php +++ b/app/Dashboard/Widgets.php @@ -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 */ + /** @var array */ private array $widgets = []; /** * @param string $component Vue-Komponente, z. B. „core::QuickLinks“ oder „news::Hero“ * @param callable(User, Request): (array|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 + */ + 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> + */ + 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 + */ + private function layout(): array + { + return (array) app(Settings::class)->get('dashboard.layout', []); + } + /** * @return list}> */ @@ -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) { diff --git a/app/Filament/Pages/Appearance.php b/app/Filament/Pages/Appearance.php index 84a69e0a..2a33af5c 100644 --- a/app/Filament/Pages/Appearance.php +++ b/app/Filament/Pages/Appearance.php @@ -2,27 +2,46 @@ namespace App\Filament\Pages; +use App\Support\Audit; use App\Support\Branding; -use App\Support\Settings; +use App\Support\Theme\Contrast; +use App\Support\Theme\Fonts; +use App\Support\Theme\Icons; +use App\Support\Theme\Theme; +use App\Support\Theme\ThemeCompiler; +use App\Support\Theme\ThemeTransfer; use BackedEnum; +use Filament\Actions\Action; +use Filament\Actions\ActionGroup; use Filament\Forms\Components\ColorPicker; use Filament\Forms\Components\FileUpload; +use Filament\Forms\Components\Radio; +use Filament\Forms\Components\Repeater; +use Filament\Forms\Components\Select; +use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Notifications\Notification; use Filament\Pages\Page; use Filament\Schemas\Components\Section; +use Filament\Schemas\Components\Tabs; +use Filament\Schemas\Components\Tabs\Tab; +use Filament\Schemas\Components\Text; +use Filament\Schemas\Components\Utilities\Get; use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\HtmlString; +use Symfony\Component\HttpFoundation\StreamedResponse; +use Throwable; use UnitEnum; /** - * Basis-Branding (Phase 0). Die vollständige Seite „Erscheinungsbild“ mit - * Logo-Varianten, Schriften, Vorschau usw. folgt in Phase 5. + * „Erscheinungsbild“ (docs/PLAN.md, Abschnitt 12): Entwurf bearbeiten, in der + * Vorschau ansehen, dann für alle veröffentlichen. */ class Appearance extends Page { - protected string $view = 'filament.pages.settings-form'; + protected string $view = 'filament.pages.appearance'; protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPaintBrush; @@ -32,75 +51,194 @@ class Appearance extends Page protected static ?string $title = 'Erscheinungsbild'; - public static function canAccess(): bool - { - return auth()->user()?->can('appearance.manage') ?? false; - } - protected static ?string $slug = 'erscheinungsbild'; /** @var array|null */ public ?array $data = []; - public function mount(Branding $branding): void + public static function canAccess(): bool { - $this->form->fill([ - 'portal_name' => $branding->portalName(), - 'primary_color' => $branding->primaryColor(), - 'logo_path' => $branding->logoPath(), - ]); + return auth()->user()?->can('appearance.manage') ?? false; + } + + public function mount(Theme $theme): void + { + $this->form->fill($theme->working()); + } + + public function hasDraft(): bool + { + return app(Theme::class)->hasDraft(); } public function form(Schema $schema): Schema { - return $schema - ->components([ - Section::make('Portal') - ->description('Name und Logo erscheinen im Kopfbereich, auf der Anmeldeseite und im Browser-Tab.') - ->schema([ - TextInput::make('portal_name') - ->label('Name des Portals') - ->placeholder(Branding::DEFAULT_NAME) - ->maxLength(60), - FileUpload::make('logo_path') - ->label('Logo') - ->helperText('SVG, PNG oder WebP, am besten mit transparentem Hintergrund.') - ->disk('uploads') - ->directory('branding') - ->visibility('public') - ->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']) - ->maxSize(2048), + $image = fn (string $name, string $label, string $help) => FileUpload::make($name)->label($label)->helperText($help) + ->disk('uploads')->directory('theme')->visibility('public')->maxSize(4096); + + return $schema->statePath('data')->components([ + Tabs::make()->persistTabInQueryString()->tabs([ + Tab::make('Identität')->icon(Heroicon::OutlinedIdentification)->columns(2)->schema([ + TextInput::make('portal_name')->label('Name des Portals')->required()->maxLength(60) + ->helperText('Erscheint im Kopfbereich, im Browser-Tab, in E-Mails und auf dem Homescreen.')->columnSpanFull(), + $image('logo_light', 'Logo für helle Flächen', 'SVG, PNG oder WebP mit transparentem Hintergrund.') + ->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']), + $image('logo_dark', 'Logo für dunkle Flächen', 'Für den Dunkelmodus und farbige Kopfleisten, z. B. in Weiß. Leer = wie hell.') + ->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']), + $image('logo_mark', 'Signet (quadratisch)', 'Kurzform für Smartphones, z. B. nur das Bildzeichen.') + ->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']), + $image('app_icon', 'App-Symbol', 'Quadratisch, mindestens 512 × 512 Pixel (PNG oder JPG). Daraus entstehen Favicon und Homescreen-Symbole.') + ->image()->acceptedFileTypes(['image/png', 'image/jpeg', 'image/webp']), + ]), + + Tab::make('Farben')->icon(Heroicon::OutlinedSwatch)->columns(2)->schema([ + ColorPicker::make('primary_color')->label('Markenfarbe')->required()->regex('/^#[0-9a-fA-F]{6}$/')->live(onBlur: true) + ->helperText('Wird exakt übernommen: Schaltflächen, aktive Navigation, Begrüßungskarte. Die Abstufungen werden berechnet.'), + ColorPicker::make('secondary_color')->label('Zweite Akzentfarbe (optional)')->regex('/^#[0-9a-fA-F]{6}$/')->live(onBlur: true) + ->helperText('Für Kategorien und Datumsangaben. Leer = Markenfarbe.'), + Radio::make('header_style')->label('Kopfleiste')->options(Theme::HEADER_STYLES)->inline()->required()->columnSpanFull(), + Section::make('Kontrastprüfung (WCAG AA)')->columnSpanFull()->compact()->schema([ + Text::make(fn (Get $get) => $this->contrastReport((string) $get('primary_color'), $get('secondary_color'))), ]), - Section::make('Farben') - ->description('Aus der Primärfarbe wird die komplette Farbpalette für den hellen und den dunklen Modus berechnet.') - ->schema([ - ColorPicker::make('primary_color') - ->label('Primärfarbe') - ->regex('/^#[0-9a-fA-F]{6}$/') - ->required(), - ]), - ]) - ->statePath('data'); + ]), + + Tab::make('Schrift & Form')->icon(Heroicon::OutlinedLanguage)->columns(2)->schema([ + Select::make('font_body')->label('Schrift')->options(fn (Get $get) => Fonts::options((bool) $get('custom_font')))->required()->native(false), + Select::make('font_heading')->label('Schrift für Überschriften')->options(fn (Get $get) => ['same' => 'Wie die Schrift'] + Fonts::options((bool) $get('custom_font')))->required()->native(false), + FileUpload::make('custom_font')->label('Eigene Schrift (WOFF2)') + ->helperText('Z. B. die Hausschrift aus dem Corporate Design. Wird lokal ausgeliefert – keine Verbindung zu Google oder anderen Diensten. Bitte die Lizenz für die Nutzung im Web beachten.') + ->disk('uploads')->directory('theme/fonts')->visibility('public')->maxSize(2048) + ->acceptedFileTypes(['font/woff2', 'application/font-woff2', 'application/octet-stream']) + ->rule('extensions:woff2')->live()->columnSpanFull(), + Radio::make('radius')->label('Ecken')->options(collect(Theme::RADII)->map(fn ($r) => $r[0])->all())->inline()->required(), + Radio::make('density')->label('Abstände')->options(collect(Theme::DENSITIES)->map(fn ($d) => $d[0])->all())->inline()->required(), + Radio::make('dark_mode')->label('Dunkelmodus')->options(Theme::DARK_MODES)->required()->columnSpanFull(), + ]), + + Tab::make('Anmeldeseite')->icon(Heroicon::OutlinedArrowRightOnRectangle)->columns(2)->schema([ + Radio::make('login_layout')->label('Aufteilung')->options(Theme::LOGIN_LAYOUTS)->required()->columnSpanFull(), + TextInput::make('login_title')->label('Begrüßung')->maxLength(200)->columnSpanFull(), + Textarea::make('login_text')->label('Text darunter')->rows(2)->maxLength(500)->columnSpanFull(), + $image('login_image', 'Hintergrundbild', 'Querformat, mindestens 1600 Pixel breit. Leer = Fläche in der Markenfarbe.') + ->image()->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])->maxSize(8192)->columnSpanFull(), + ]), + + Tab::make('Fußzeile & E-Mails')->icon(Heroicon::OutlinedEnvelope)->schema([ + TextInput::make('footer_text')->label('Text in der Fußzeile')->placeholder('© 2027 Musterstift gGmbH')->maxLength(200), + Repeater::make('footer_links')->label('Links in der Fußzeile')->columns(2)->defaultItems(0)->reorderable() + ->addActionLabel('Link hinzufügen')->maxItems(8) + ->schema([ + TextInput::make('label')->label('Bezeichnung')->required()->maxLength(60)->placeholder('Impressum'), + TextInput::make('url')->label('Adresse')->required()->maxLength(500)->placeholder('https://… oder /seiten/impressum'), + ]), + Textarea::make('email_footer')->label('Fußzeile in E-Mails')->rows(3)->maxLength(500) + ->helperText('Z. B. Anschrift und Hinweis. Logo und Markenfarbe übernehmen die E-Mails automatisch.'), + ]), + + Tab::make('Erweitert')->icon(Heroicon::OutlinedCodeBracket)->schema([ + Textarea::make('custom_css')->label('Eigenes CSS')->rows(12)->maxLength(50000) + ->extraInputAttributes(['class' => 'font-mono text-xs', 'spellcheck' => 'false']) + ->helperText('Für Fortgeschrittene. Wird nach dem Portal-CSS geladen und bei Aktualisierungen unverändert übernommen. Klassennamen können sich mit neuen Versionen ändern – bitte nach jedem Update prüfen. Verfügbare Variablen: --brand, --brand-50 … --brand-950, --radius, --font-body, --font-heading.'), + ]), + ]), + ]); } - public function save(Settings $settings, Branding $branding): void + private function contrastReport(string $primary, ?string $secondary): HtmlString { - $data = $this->form->getState(); - $previousLogo = $branding->logoPath(); - - $settings->setMany([ - 'branding.portal_name' => filled($data['portal_name']) ? trim($data['portal_name']) : null, - 'branding.primary_color' => strtoupper($data['primary_color']), - 'branding.logo_path' => $data['logo_path'] ?: null, - ]); - - if ($previousLogo && $previousLogo !== $data['logo_path']) { - Storage::disk('uploads')->delete($previousLogo); + if (! preg_match('/^#[0-9a-fA-F]{6}$/', $primary)) { + return new HtmlString(''); } - Notification::make() - ->success() - ->title('Erscheinungsbild gespeichert') - ->send(); + $colors = ['ok' => '#15803d', 'info' => '#0369a1', 'warning' => '#b45309']; + $icons = ['ok' => '✓', 'info' => 'i', 'warning' => '!']; + + return new HtmlString(collect(Contrast::report(strtoupper($primary), $secondary && preg_match('/^#[0-9a-fA-F]{6}$/', $secondary) ? strtoupper($secondary) : null)) + ->map(fn ($note) => '

'.$icons[$note['level']].''.e($note['text']).'

') + ->implode('')); + } + + /** + * Entwurf speichern und die Vorschau aktualisieren. + */ + public function save(Theme $theme, Branding $branding): void + { + $theme->saveDraft($this->form->getState()); + session()->put(Branding::PREVIEW_SESSION_KEY, true); + $branding->refresh(); + + $this->dispatch('theme-preview-reload'); + Notification::make()->success()->title('Entwurf gespeichert')->body('Die Vorschau zeigt jetzt den Entwurf. Für alle sichtbar wird er erst mit „Veröffentlichen“.')->send(); + } + + protected function getHeaderActions(): array + { + return [ + Action::make('publish')->label('Veröffentlichen')->icon(Heroicon::OutlinedRocketLaunch) + ->requiresConfirmation() + ->modalHeading('Erscheinungsbild veröffentlichen?') + ->modalDescription('Der gespeicherte Entwurf wird für alle sichtbar. Ungespeicherte Änderungen im Formular werden vorher als Entwurf gespeichert.') + ->action(function (Theme $theme, ThemeCompiler $compiler, Icons $icons, Branding $branding) { + $theme->saveDraft($this->form->getState()); + $theme->publish($compiler, $icons); + session()->forget(Branding::PREVIEW_SESSION_KEY); + $branding->refresh(); + Audit::log('appearance.published'); + + $this->form->fill($theme->working()); + $this->dispatch('theme-preview-reload'); + Notification::make()->success()->title('Erscheinungsbild veröffentlicht')->send(); + }), + Action::make('discard')->label('Entwurf verwerfen')->icon(Heroicon::OutlinedArrowUturnLeft)->color('gray') + ->visible(fn () => $this->hasDraft()) + ->requiresConfirmation() + ->action(function (Theme $theme, Branding $branding) { + $theme->discardDraft(); + session()->forget(Branding::PREVIEW_SESSION_KEY); + $branding->refresh(); + $this->form->fill($theme->working()); + $this->dispatch('theme-preview-reload'); + }), + ActionGroup::make([ + Action::make('export')->label('Exportieren')->icon(Heroicon::OutlinedArrowDownTray) + ->action(fn (ThemeTransfer $transfer): StreamedResponse => response()->streamDownload( + fn () => print (json_encode($transfer->export(app(Theme::class)->working()), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)), + 'erscheinungsbild-'.now()->format('Y-m-d').'.json', + ['Content-Type' => 'application/json'], + )), + Action::make('import')->label('Importieren')->icon(Heroicon::OutlinedArrowUpTray) + ->modalDescription('Erscheinungsbild aus einer exportierten Datei übernehmen – als Entwurf, damit Sie es erst ansehen können.') + ->schema([ + FileUpload::make('file')->label('Datei (.json)')->disk('local')->directory('theme-import') + ->acceptedFileTypes(['application/json', 'text/plain'])->maxSize(20 * 1024)->required(), + ]) + ->action(function (array $data, ThemeTransfer $transfer, Theme $theme) { + try { + $values = $transfer->import((string) Storage::disk('local')->get($data['file'])); + } catch (Throwable $e) { + Notification::make()->danger()->title('Import nicht möglich')->body($e->getMessage())->send(); + + return; + } finally { + Storage::disk('local')->delete($data['file']); + } + + $theme->saveDraft($values); + session()->put(Branding::PREVIEW_SESSION_KEY, true); + $this->form->fill($theme->working()); + $this->dispatch('theme-preview-reload'); + Notification::make()->success()->title('Als Entwurf importiert')->send(); + }), + Action::make('reset')->label('Auf Standard zurücksetzen')->icon(Heroicon::OutlinedArrowPath)->color('danger') + ->requiresConfirmation() + ->modalDescription('Setzt Farben, Schriften, Logos und Texte auf die Standardwerte zurück – als Entwurf. Der Portalname bleibt.') + ->action(function (Theme $theme) { + $theme->resetToDefaults(); + session()->put(Branding::PREVIEW_SESSION_KEY, true); + $this->form->fill($theme->working()); + $this->dispatch('theme-preview-reload'); + }), + ])->label('Mehr')->icon(Heroicon::OutlinedEllipsisVertical)->button()->color('gray'), + ]; } } diff --git a/app/Filament/Pages/DashboardSettings.php b/app/Filament/Pages/DashboardSettings.php new file mode 100644 index 00000000..9213394f --- /dev/null +++ b/app/Filament/Pages/DashboardSettings.php @@ -0,0 +1,108 @@ + ['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|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(), + ]; + } +} diff --git a/app/Filament/Pages/MailSettingsPage.php b/app/Filament/Pages/MailSettingsPage.php new file mode 100644 index 00000000..05d6316a --- /dev/null +++ b/app/Filament/Pages/MailSettingsPage.php @@ -0,0 +1,109 @@ +|null */ + public ?array $data = []; + + public static function canAccess(): bool + { + return auth()->user()?->can('mail.manage') ?? false; + } + + public function mount(MailSettings $mail): void + { + $this->form->fill([...$mail->values(), 'password' => null]); + } + + public function form(Schema $schema): Schema + { + $smtp = fn (Get $get) => $get('mailer') === 'smtp'; + + return $schema + ->components([ + Section::make('Versand') + ->description('Die Zugangsdaten erhalten Sie von Ihrem Hoster oder Ihrer IT (z. B. Microsoft 365: smtp.office365.com, Port 587, TLS).') + ->columns(2) + ->schema([ + Select::make('mailer')->label('Versandart')->options(MailSettings::MAILERS)->required()->live()->native(false)->columnSpanFull(), + TextInput::make('host')->label('SMTP-Server')->required($smtp)->visible($smtp)->maxLength(255), + TextInput::make('port')->label('Port')->numeric()->required($smtp)->visible($smtp)->minValue(1)->maxValue(65535), + Select::make('encryption')->label('Verschlüsselung')->visible($smtp)->native(false) + ->options(['tls' => 'STARTTLS (meist Port 587)', 'ssl' => 'SSL/TLS (meist Port 465)', 'none' => 'Keine']), + TextInput::make('username')->label('Benutzername')->visible($smtp)->maxLength(255)->autocomplete('off'), + TextInput::make('password')->label('Passwort')->password()->revealable()->visible($smtp)->maxLength(255) + ->helperText('Leer lassen, um das gespeicherte Passwort zu behalten.')->autocomplete('new-password'), + ]), + Section::make('Absender') + ->columns(2) + ->schema([ + TextInput::make('from_address')->label('Absenderadresse')->email()->required()->maxLength(255)->placeholder('intranet@firma.de'), + TextInput::make('from_name')->label('Absendername')->maxLength(100)->placeholder('Name des Portals'), + ]), + ]) + ->statePath('data'); + } + + public function save(MailSettings $mail): void + { + $mail->save($this->form->getState()); + Audit::log('mail.settings_updated'); + + Notification::make()->success()->title('E-Mail-Versand gespeichert')->send(); + } + + protected function getHeaderActions(): array + { + return [ + Action::make('test') + ->label('Test-Mail senden') + ->icon(Heroicon::OutlinedPaperAirplane) + ->color('gray') + ->action(function () { + $to = auth()->user()->email; + + try { + Mail::raw('Diese Test-Mail bestätigt, dass der E-Mail-Versand des Portals funktioniert.', fn ($m) => $m->to($to)->subject('Test-Mail aus dem Portal')); + Notification::make()->success()->title('Test-Mail an '.$to.' gesendet')->send(); + } catch (Throwable $e) { + Notification::make()->danger()->title('Versand fehlgeschlagen')->body($e->getMessage())->persistent()->send(); + } + }), + ]; + } +} diff --git a/app/Filament/Resources/DashboardTiles/DashboardTileResource.php b/app/Filament/Resources/DashboardTiles/DashboardTileResource.php new file mode 100644 index 00000000..91ce484f --- /dev/null +++ b/app/Filament/Resources/DashboardTiles/DashboardTileResource.php @@ -0,0 +1,104 @@ +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('/')]; + } +} diff --git a/app/Filament/Resources/DashboardTiles/Pages/ManageDashboardTiles.php b/app/Filament/Resources/DashboardTiles/Pages/ManageDashboardTiles.php new file mode 100644 index 00000000..11df25ef --- /dev/null +++ b/app/Filament/Resources/DashboardTiles/Pages/ManageDashboardTiles.php @@ -0,0 +1,24 @@ +label('Anordnung der Startseite')->icon(Heroicon::OutlinedSquares2x2)->color('gray') + ->url(fn () => DashboardSettings::getUrl()), + CreateAction::make()->label('Kachel anlegen'), + ]; + } +} diff --git a/app/Http/Controllers/AppearanceController.php b/app/Http/Controllers/AppearanceController.php new file mode 100644 index 00000000..f7ceef73 --- /dev/null +++ b/app/Http/Controllers/AppearanceController.php @@ -0,0 +1,86 @@ +get('icons') ?? []) + ->reject(fn ($path, $size) => (int) $size < 192) + ->map(fn ($path, $size) => ['src' => $branding->url($path), 'sizes' => "{$size}x{$size}", 'type' => 'image/png', 'purpose' => 'any']) + ->values(); + + if ($icons->isEmpty()) { + $icons = collect([['src' => $branding->faviconUrl(), 'sizes' => 'any', 'type' => 'image/svg+xml']]); + } + + return response()->json([ + 'name' => $branding->portalName(), + 'short_name' => mb_substr($branding->portalName(), 0, 12), + 'start_url' => '/', + 'scope' => '/', + 'display' => 'standalone', + 'lang' => 'de', + 'theme_color' => $branding->primaryColor(), + 'background_color' => '#F4F5F7', + 'icons' => $icons->all(), + ], 200, ['Content-Type' => 'application/manifest+json', 'Cache-Control' => 'public, max-age=3600']); + } + + /** + * Anmeldeseite im aktuellen Entwurf – für die Vorschau (Formular ohne Funktion). + */ + public function loginPreview(Request $request): Response + { + return Inertia::render('Auth/Login', [ + 'canResetPassword' => true, + 'providers' => IdentityProvider::query()->where('enabled', true)->get() + ->map(fn (IdentityProvider $p) => ['slug' => $p->slug, 'type' => $p->type, 'label' => $p->buttonLabel()])->values(), + 'preview' => true, + ]); + } + + /** + * Beispielseite mit Boxen, Tabs, Akkordeon, Tabelle und Schaltflächen. + */ + public function sample(Request $request, Content $content): Response + { + $text = fn (string $html) => ['type' => 'text', 'data' => ['html' => $html]]; + $box = fn (string $variant, string $title, string $html) => ['type' => 'box', 'data' => ['variant' => $variant, 'title' => $title, 'show_icon' => true], 'items' => [['blocks' => [$text($html)]]]]; + + $blocks = [ + ['type' => 'heading', 'data' => ['text' => 'Überschrift der Seite', 'level' => '2']], + $text('

Fließtext mit einem Link in der Akzentfarbe, Hervorhebungen und einer Liste:

  • erster Punkt
  • zweiter Punkt
'), + ['type' => 'columns', 'data' => ['layout' => '1-1'], 'items' => [ + ['blocks' => [$box('info', 'Info', '

Sprechstunde dienstags 14–16 Uhr.

'), $box('warning', 'Warnung', '

Bitte bis Freitag einreichen.

')]], + ['blocks' => [$box('success', 'Erfolg', '

Das neue Verfahren gilt ab sofort.

'), $box('highlight', 'Hervorgehoben', '

In der Markenfarbe.

')]], + ]], + ['type' => 'tabs', 'items' => [ + ['title' => 'Erster Tab', 'blocks' => [$text('

Inhalt des ersten Tabs.

')]], + ['title' => 'Zweiter Tab', 'blocks' => [$text('

Inhalt des zweiten Tabs.

')]], + ]], + ['type' => 'accordion', 'data' => ['first_open' => true], 'items' => [ + ['title' => 'Häufige Frage', 'blocks' => [$text('

Die Antwort steht hier.

')]], + ['title' => 'Noch eine Frage', 'blocks' => [$text('

Noch eine Antwort.

')]], + ]], + ['type' => 'table', 'data' => ['header' => true, 'rows' => [['Bereich', 'Ansprechpartner', 'Durchwahl'], ['Personal', 'A. Beispiel', '123'], ['IT', 'B. Muster', '456']]]], + ['type' => 'buttons', 'data' => ['buttons' => [['label' => 'Primäre Schaltfläche', 'url' => '#', 'variant' => 'primary'], ['label' => 'Umrandet', 'url' => '#', 'variant' => 'outline']]]], + ]; + + return Inertia::render('Appearance/Sample', [ + 'content' => $content->render($content->sanitize(['blocks' => $blocks]), $request->user()), + ]); + } +} diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 6b33fa91..50036fe4 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -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), ]); } diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index 11e570e7..7cb20982 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -42,6 +42,7 @@ class HandleInertiaRequests extends Middleware 'notifications' => fn () => $user ? ['unread' => $user->unreadNotifications()->count()] : null, 'flash' => [ 'status' => fn () => $request->session()->get('status'), + 'form_submitted' => fn () => $request->session()->get('form_submitted'), ], ]; } diff --git a/app/Http/Middleware/ThemePreview.php b/app/Http/Middleware/ThemePreview.php new file mode 100644 index 00000000..d9a81cd2 --- /dev/null +++ b/app/Http/Middleware/ThemePreview.php @@ -0,0 +1,32 @@ +query('vorschau'); + + if ($value !== null && $request->hasSession()) { + if ($value === 'entwurf' && $request->user()?->can('appearance.manage')) { + $request->session()->put(Branding::PREVIEW_SESSION_KEY, true); + } elseif ($value === 'aus') { + $request->session()->forget(Branding::PREVIEW_SESSION_KEY); + } + } + + app(Branding::class)->refresh(); + + return $next($request); + } +} diff --git a/app/Models/DashboardTile.php b/app/Models/DashboardTile.php new file mode 100644 index 00000000..6eb59f6d --- /dev/null +++ b/app/Models/DashboardTile.php @@ -0,0 +1,94 @@ + '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 $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 + */ + 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', + ], + ]; + } +} diff --git a/app/Plugins/PluginManifest.php b/app/Plugins/PluginManifest.php index dafe2cc6..51291a3d 100644 --- a/app/Plugins/PluginManifest.php +++ b/app/Plugins/PluginManifest.php @@ -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), ); } diff --git a/app/Plugins/PluginState.php b/app/Plugins/PluginState.php index cf6e98f9..29c7a948 100644 --- a/app/Plugins/PluginState.php +++ b/app/Plugins/PluginState.php @@ -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>|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 diff --git a/app/Profile/ProfileSections.php b/app/Profile/ProfileSections.php new file mode 100644 index 00000000..967427ac --- /dev/null +++ b/app/Profile/ProfileSections.php @@ -0,0 +1,52 @@ +/resources/js/profile/.vue („::Name“) + * und speichert über eigene Routen des Plugins. + */ +class ProfileSections +{ + /** @var array */ + private array $sections = []; + + /** + * @param Closure(User): (array|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}> + */ + 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; + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 254192fc..5f10d37a 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,12 +13,15 @@ use App\Support\BackgroundTasks; use App\Support\Branding; use App\Support\Installation; use App\Support\License\LicenseStore; +use App\Support\MailSettings; use App\Support\Navigation; use App\Support\Permissions\PermissionResource; use App\Support\Permissions\Permissions; use App\Support\ProfileFields; use App\Support\QuickLinks; use App\Support\Settings; +use App\Support\Theme\Theme; +use App\Support\Theme\ThemeCompiler; use App\Support\Update\InstalledVersion; use App\Support\Update\MaintenanceFlag; use App\Support\Update\UpdateProgress; @@ -42,7 +45,10 @@ class AppServiceProvider extends ServiceProvider } $this->app->singleton(Settings::class); + $this->app->singleton(MailSettings::class); $this->app->singleton(Branding::class); + $this->app->singleton(Theme::class); + $this->app->singleton(ThemeCompiler::class); $this->app->singleton(Avatars::class); $this->app->singleton(QuickLinks::class); $this->app->singleton(LicenseStore::class); @@ -60,7 +66,7 @@ class AppServiceProvider extends ServiceProvider { CoreWidgets::register($this->app->make(Widgets::class)); - $this->app->make(Navigation::class)->add('editorial', 'Redaktion', '/redaktion', active: ['editorial', 'pages.editor', 'news.editor.*'], sort: 85, + $this->app->make(Navigation::class)->add('editorial', 'Redaktion', '/redaktion', active: ['editorial', 'pages.editor', 'news.editor.*', 'forms.builder'], sort: 85, visible: fn (User $user) => $this->app->make(Editorial::class)->visibleFor($user)); // N+1-Abfragen in Entwicklung und Tests sofort sichtbar machen (docs/PLAN.md, Performance). @@ -84,5 +90,16 @@ class AppServiceProvider extends ServiceProvider }); Password::defaults(fn () => Password::min(10)->letters()->numbers()); + + if (Installation::isInstalled()) { + $this->app->make(MailSettings::class)->apply(); + + // Whitelabel: Laravel nutzt app.name z. B. in Benachrichtigungs-Mails („Viele Grüße …“). + try { + config(['app.name' => $this->app->make(Branding::class)->portalName()]); + } catch (\Throwable) { + // Datenbank noch nicht bereit + } + } } } diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index f412bac7..31b35592 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -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; @@ -41,6 +42,9 @@ class AdminPanelProvider extends PanelProvider ->defaultAvatarProvider(InitialsAvatarProvider::class) ->brandName(fn () => app(Branding::class)->portalName()) ->brandLogo(fn () => app(Branding::class)->logoUrl()) + ->darkModeBrandLogo(fn () => app(Branding::class)->logoDarkUrl()) + ->brandLogoHeight('2rem') + ->favicon(fn () => app(Branding::class)->faviconUrl()) ->colors(fn () => [ 'primary' => app(Branding::class)->palette(), ]) @@ -65,6 +69,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') diff --git a/app/Providers/PluginServiceProvider.php b/app/Providers/PluginServiceProvider.php index ad145ae1..9d57c021 100644 --- a/app/Providers/PluginServiceProvider.php +++ b/app/Providers/PluginServiceProvider.php @@ -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(); } diff --git a/app/Support/Abilities.php b/app/Support/Abilities.php index d6685b32..665cd40d 100644 --- a/app/Support/Abilities.php +++ b/app/Support/Abilities.php @@ -25,6 +25,7 @@ class Abilities $this->define('plugins.manage', 'Plugins verwalten und installieren', 'System'); $this->define('appearance.manage', 'Erscheinungsbild und Schnellzugriffe', 'System'); $this->define('updates.manage', 'Aktualisierungen, Lizenz und Systemzustand', 'System'); + $this->define('mail.manage', 'E-Mail-Versand einrichten', 'System'); $this->define('feedback.send', 'Rückmeldungen an den Hersteller senden', 'System'); } diff --git a/app/Support/Branding.php b/app/Support/Branding.php index 58419cd9..a5511f66 100644 --- a/app/Support/Branding.php +++ b/app/Support/Branding.php @@ -2,11 +2,15 @@ namespace App\Support; +use App\Support\Theme\Icons; +use App\Support\Theme\Theme; +use App\Support\Theme\ThemeCompiler; use Illuminate\Support\Facades\Storage; +use Throwable; /** - * Basis-Branding der Installation (Phase 0): Portalname, Logo, Primärfarbe. - * Das vollständige Erscheinungsbild folgt in Phase 5 (docs/PLAN.md, Abschnitt 12). + * Das aktive Erscheinungsbild (docs/PLAN.md, Abschnitt 12): der veröffentlichte + * Stand – oder der Entwurf, wenn eine berechtigte Person gerade die Vorschau nutzt. */ class Branding { @@ -14,31 +18,84 @@ class Branding public const DEFAULT_PRIMARY_COLOR = '#0F4C5C'; - public function __construct(private readonly Settings $settings) {} + public const PREVIEW_SESSION_KEY = 'theme_preview'; + + /** @var array|null */ + private ?array $active = null; + + private ?bool $previewing = null; + + public function __construct( + private readonly Settings $settings, + private readonly Theme $theme, + private readonly ThemeCompiler $compiler, + ) {} + + /** + * @return array + */ + public function active(): array + { + return $this->active ??= $this->isPreviewing() ? ($this->theme->draft() ?? $this->theme->published()) : $this->theme->published(); + } + + public function isPreviewing(): bool + { + if ($this->previewing !== null) { + return $this->previewing; + } + + try { + $request = request(); + + return $this->previewing = $request->hasSession() + && $request->session()->get(self::PREVIEW_SESSION_KEY) === true + && (bool) $request->user()?->can('appearance.manage') + && $this->theme->hasDraft(); + } catch (Throwable) { + return $this->previewing = false; + } + } + + /** Nach dem Speichern eines Entwurfs oder Veröffentlichen neu lesen. */ + public function refresh(): void + { + $this->active = null; + $this->previewing = null; + } + + public function get(string $key): mixed + { + return $this->active()[$key] ?? null; + } public function portalName(): string { - return $this->settings->get('branding.portal_name') ?: self::DEFAULT_NAME; + return $this->get('portal_name') ?: self::DEFAULT_NAME; } public function primaryColor(): string { - $color = $this->settings->get('branding.primary_color'); - - return is_string($color) && preg_match('/^#[0-9a-fA-F]{6}$/', $color) - ? strtoupper($color) - : self::DEFAULT_PRIMARY_COLOR; + return $this->get('primary_color') ?: self::DEFAULT_PRIMARY_COLOR; } public function logoPath(): ?string { - return $this->settings->get('branding.logo_path') ?: null; + return $this->get('logo_light'); } public function logoUrl(): ?string { - $path = $this->logoPath(); + return $this->url($this->get('logo_light')); + } + public function logoDarkUrl(): ?string + { + return $this->url($this->get('logo_dark')) ?? $this->logoUrl(); + } + + public function url(?string $path): ?string + { return $path ? Storage::disk('uploads')->url($path) : null; } @@ -51,33 +108,80 @@ class Branding } /** - * CSS-Variablen für das Portal. Werden serverseitig in die Seite geschrieben – - * ohne Build und ohne Farbberechnung im Browser. + * Stylesheet des veröffentlichten Stands; null = inline ausgeben (Vorschau, noch nie veröffentlicht). */ - public function cssVariables(): string + public function stylesheetUrl(): ?string { - $color = $this->primaryColor(); - $variables = [ - '--brand' => $color, - '--brand-foreground' => ColorPalette::foregroundFor($color), - ]; + $path = $this->isPreviewing() ? null : $this->get('stylesheet'); - foreach ($this->palette() as $shade => $hex) { - $variables["--brand-{$shade}"] = $hex; - } + return $path && Storage::disk('uploads')->exists($path) ? $this->url($path) : null; + } - return collect($variables)->map(fn (string $value, string $name) => "{$name}:{$value}")->implode(';'); + public function inlineCss(): string + { + return $this->compiler->css($this->active()); } /** - * @return array{portal_name: string, primary_color: string, logo_url: string|null} + * @deprecated Nur noch für Übergänge – das Theme liefert alle Variablen. + */ + public function cssVariables(): string + { + return '--brand:'.$this->primaryColor(); + } + + public function faviconUrl(): string + { + $icons = $this->get('icons') ?? []; + + return isset($icons[32]) ? $this->url($icons[32]) : Icons::monogram($this->portalName(), $this->primaryColor(), ColorPalette::foregroundFor($this->primaryColor())); + } + + public function appleTouchIconUrl(): ?string + { + return isset(($this->get('icons') ?? [])[180]) ? $this->url($this->get('icons')[180]) : null; + } + + /** + * Welche Darstellung gilt für eine Person? null = selbst gewählt/Systemeinstellung. + */ + public function forcedColorMode(): ?string + { + return match ($this->get('dark_mode')) { + 'light' => 'light', + 'dark' => 'dark', + default => null, + }; + } + + /** + * Für das Portal (Inertia). + * + * @return array */ public function toArray(): array { + $theme = $this->active(); + return [ 'portal_name' => $this->portalName(), 'primary_color' => $this->primaryColor(), 'logo_url' => $this->logoUrl(), + 'logo_dark_url' => $this->logoDarkUrl(), + 'logo_mark_url' => $this->url($theme['logo_mark']), + 'header_style' => $theme['header_style'], + 'color_mode' => $this->forcedColorMode(), + 'login' => [ + 'layout' => $theme['login_layout'], + 'title' => $theme['login_title'], + 'text' => $theme['login_text'], + 'image_url' => $this->url($theme['login_image']), + ], + 'footer' => [ + 'text' => $theme['footer_text'], + 'links' => $theme['footer_links'], + ], + 'preview' => $this->isPreviewing(), ]; } } diff --git a/app/Support/MailSettings.php b/app/Support/MailSettings.php new file mode 100644 index 00000000..9bc6d03d --- /dev/null +++ b/app/Support/MailSettings.php @@ -0,0 +1,100 @@ + 'SMTP-Server', + 'sendmail' => 'Sendmail des Servers', + 'log' => 'Nicht senden (nur ins Protokoll schreiben)', + ]; + + public function __construct(private readonly Settings $settings) {} + + public function configured(): bool + { + return $this->settings->get('mail.mailer') !== null; + } + + /** + * @return array + */ + public function values(): array + { + return [ + 'mailer' => $this->settings->get('mail.mailer', 'log'), + 'host' => $this->settings->get('mail.host'), + 'port' => $this->settings->get('mail.port', 587), + 'encryption' => $this->settings->get('mail.encryption', 'tls'), + 'username' => $this->settings->get('mail.username'), + 'from_address' => $this->settings->get('mail.from_address'), + 'from_name' => $this->settings->get('mail.from_name'), + ]; + } + + /** + * @param array $values + */ + public function save(array $values): void + { + $data = [ + 'mail.mailer' => $values['mailer'], + 'mail.host' => $values['host'] ?? null, + 'mail.port' => isset($values['port']) ? (int) $values['port'] : null, + 'mail.encryption' => $values['encryption'] ?? 'tls', + 'mail.username' => $values['username'] ?? null, + 'mail.from_address' => $values['from_address'] ?? null, + 'mail.from_name' => $values['from_name'] ?? null, + ]; + + // Leeres Passwortfeld = gespeichertes behalten. + if (filled($values['password'] ?? null)) { + $data['mail.password'] = Crypt::encryptString($values['password']); + } + + $this->settings->setMany($data); + $this->apply(); + } + + public function apply(): void + { + if (! $this->configured()) { + return; + } + + $values = $this->values(); + + try { + $password = $this->settings->get('mail.password') ? Crypt::decryptString($this->settings->get('mail.password')) : null; + } catch (Throwable) { + $password = null; // APP_KEY geändert – Passwort muss neu eingegeben werden + } + + config([ + 'mail.default' => $values['mailer'], + 'mail.mailers.smtp.host' => $values['host'], + 'mail.mailers.smtp.port' => (int) $values['port'], + 'mail.mailers.smtp.scheme' => $values['encryption'] === 'ssl' ? 'smtps' : 'smtp', + 'mail.mailers.smtp.username' => $values['username'], + 'mail.mailers.smtp.password' => $password, + 'mail.mailers.smtp.timeout' => 15, + 'mail.from.address' => $values['from_address'] ?: config('mail.from.address'), + 'mail.from.name' => $values['from_name'] ?: app(Branding::class)->portalName(), + ]); + + // Bereits erzeugte Mailer mit alter Konfiguration verwerfen. + app()->forgetInstance('mail.manager'); + app()->forgetInstance('mailer'); + Mail::clearResolvedInstance('mail.manager'); + } +} diff --git a/app/Support/Theme/Contrast.php b/app/Support/Theme/Contrast.php new file mode 100644 index 00000000..894b5106 --- /dev/null +++ b/app/Support/Theme/Contrast.php @@ -0,0 +1,91 @@ += self::AA) { + return $shade; + } + } + + return 950; + } + + /** + * Farbe für Links und Akzenttext auf dunklem Grund. + */ + public static function textShadeOnDark(string $hex): int + { + $palette = ColorPalette::fromHex($hex); + + foreach ([300, 200, 100, 50] as $shade) { + if (ColorPalette::contrast($palette[$shade], self::DARK_BACKGROUND) >= self::AA) { + return $shade; + } + } + + return 50; + } + + /** + * Hinweise für die Seite „Erscheinungsbild“. + * + * @return list + */ + public static function report(string $primary, ?string $secondary = null): array + { + $notes = []; + $foreground = ColorPalette::foregroundFor($primary); + $onButton = ColorPalette::contrast($primary, $foreground); + $onWhite = ColorPalette::contrast($primary, self::LIGHT_BACKGROUND); + $palette = ColorPalette::fromHex($primary); + + $notes[] = $onButton >= self::AA + ? ['level' => 'ok', 'text' => sprintf('Schrift auf Schaltflächen (%s): Kontrast %s:1 – gut lesbar.', $foreground === '#FFFFFF' ? 'weiß' : 'schwarz', self::format($onButton))] + : ['level' => 'warning', 'text' => sprintf('Schrift auf Schaltflächen erreicht nur %s:1 (empfohlen mindestens 4,5:1). Eine etwas dunklere oder hellere Markenfarbe wäre besser lesbar, z. B. %s.', self::format($onButton), $palette[700])]; + + if ($onWhite >= self::AA) { + $notes[] = ['level' => 'ok', 'text' => sprintf('Links auf hellem Grund: Kontrast %s:1 – die Markenfarbe wird unverändert verwendet.', self::format($onWhite))]; + } else { + $shade = self::textShadeOnLight($primary); + $notes[] = ['level' => 'info', 'text' => sprintf('Die Markenfarbe ist auf Weiß als Textfarbe zu hell (%s:1). Für Links und Akzenttexte wird automatisch die dunklere Abstufung %s verwendet. Schaltflächen und Flächen behalten die Markenfarbe.', self::format($onWhite), $palette[$shade])]; + } + + if ($secondary !== null) { + $onWhite2 = ColorPalette::contrast($secondary, self::LIGHT_BACKGROUND); + + if ($onWhite2 < 3) { + $notes[] = ['level' => 'info', 'text' => sprintf('Die zweite Akzentfarbe ist auf Weiß sehr hell (%s:1). Für Beschriftungen wird automatisch eine dunklere Abstufung verwendet.', self::format($onWhite2))]; + } + } + + return $notes; + } + + private static function format(float $ratio): string + { + return number_format($ratio, 1, ',', ''); + } +} diff --git a/app/Support/Theme/Fonts.php b/app/Support/Theme/Fonts.php new file mode 100644 index 00000000..16c6bc5e --- /dev/null +++ b/app/Support/Theme/Fonts.php @@ -0,0 +1,55 @@ + [Bezeichnung, CSS-Familie, serif?] */ + public const FONTS = [ + 'inter' => ['Inter', 'Inter Variable', false], + 'source-sans-3' => ['Source Sans 3', 'Source Sans 3 Variable', false], + 'open-sans' => ['Open Sans', 'Open Sans Variable', false], + 'nunito-sans' => ['Nunito Sans', 'Nunito Sans Variable', false], + 'roboto' => ['Roboto', 'Roboto Variable', false], + 'ibm-plex-sans' => ['IBM Plex Sans', 'IBM Plex Sans Variable', false], + 'figtree' => ['Figtree', 'Figtree Variable', false], + 'atkinson' => ['Atkinson Hyperlegible (besonders gut lesbar)', 'Atkinson Hyperlegible', false], + 'source-serif-4' => ['Source Serif 4 (Serifen)', 'Source Serif 4 Variable', true], + 'merriweather' => ['Merriweather (Serifen)', 'Merriweather Variable', true], + 'lora' => ['Lora (Serifen)', 'Lora Variable', true], + 'system' => ['Systemschrift des Geräts', null, false], + ]; + + /** Familienname einer hochgeladenen Schrift. */ + public const CUSTOM_FAMILY = 'Portal Eigene Schrift'; + + /** + * @return array + */ + public static function options(bool $withCustom = false): array + { + $options = array_map(fn (array $font) => $font[0], self::FONTS); + + return $withCustom ? $options + ['custom' => 'Eigene Schrift (hochgeladen)'] : $options; + } + + public static function stack(string $key): string + { + if ($key === 'custom') { + return '"'.self::CUSTOM_FAMILY.'", '.self::FALLBACK_SANS; + } + + [, $family, $serif] = self::FONTS[$key] ?? self::FONTS['inter']; + $fallback = $serif ? self::FALLBACK_SERIF : self::FALLBACK_SANS; + + return $family ? '"'.$family.'", '.$fallback : $fallback; + } +} diff --git a/app/Support/Theme/Icons.php b/app/Support/Theme/Icons.php new file mode 100644 index 00000000..2d5c8f06 --- /dev/null +++ b/app/Support/Theme/Icons.php @@ -0,0 +1,66 @@ + $theme + * @return array Größe => Pfad im Speicher „uploads“ + */ + public function generate(array $theme): array + { + $source = $theme['app_icon'] ?? null; + $disk = Storage::disk('uploads'); + + if (! $source || ! $disk->exists($source)) { + return []; + } + + try { + Images::raiseMemoryLimitFor($disk->path($source)); + $manager = ImageManager::usingDriver(Driver::class); + $hash = substr(sha1((string) $disk->get($source)), 0, 10); + $result = []; + + foreach (self::SIZES as $size) { + $image = $manager->decodePath($disk->path($source)); + $image->cover($size, $size); + $path = "theme/icons/icon-{$hash}-{$size}.png"; + $disk->put($path, $image->encode(new PngEncoder)->toString()); + $result[$size] = $path; + } + + return $result; + } catch (Throwable $e) { + report($e); + + return []; + } + } + + /** + * Monogramm als SVG-Favicon (Daten-URL), wenn kein Symbol hochgeladen ist. + */ + public static function monogram(string $name, string $color, string $foreground): string + { + $letter = htmlspecialchars(mb_strtoupper(mb_substr(trim($name), 0, 1)) ?: 'P', ENT_XML1); + $svg = '' + .''.$letter.''; + + return 'data:image/svg+xml;base64,'.base64_encode($svg); + } +} diff --git a/app/Support/Theme/SvgSanitizer.php b/app/Support/Theme/SvgSanitizer.php new file mode 100644 index 00000000..f7e01546 --- /dev/null +++ b/app/Support/Theme/SvgSanitizer.php @@ -0,0 +1,62 @@ +exists($path)) { + return; + } + + $clean = self::sanitize((string) $disk->get($path)); + $clean === null ? $disk->delete($path) : $disk->put($path, $clean); + } + + public static function sanitize(string $svg): ?string + { + $dom = new DOMDocument; + + // Keine externen Entitäten, kein Netzwerkzugriff. + if (str_contains($svg, 'loadXML($svg, LIBXML_NONET) || $dom->documentElement?->localName !== 'svg') { + return null; + } + + $xpath = new DOMXPath($dom); + + foreach (iterator_to_array($xpath->query('//*[local-name()="script" or local-name()="foreignObject" or local-name()="iframe" or local-name()="object" or local-name()="embed"]')) as $node) { + $node->parentNode->removeChild($node); + } + + foreach (iterator_to_array($xpath->query('//*')) as $element) { + /** @var DOMElement $element */ + foreach (iterator_to_array($element->attributes) as $attribute) { + $name = strtolower($attribute->nodeName); + $value = strtolower(preg_replace('/\s+/', '', $attribute->nodeValue)); + + if (str_starts_with($name, 'on') || (in_array($name, ['href', 'xlink:href', 'src'], true) && ! str_starts_with($value, '#') && ! str_starts_with($value, 'data:image/'))) { + $element->removeAttributeNode($attribute); + } + } + } + + return $dom->saveXML($dom->documentElement); + } +} diff --git a/app/Support/Theme/Theme.php b/app/Support/Theme/Theme.php new file mode 100644 index 00000000..34d45f46 --- /dev/null +++ b/app/Support/Theme/Theme.php @@ -0,0 +1,191 @@ + 'Inhaus', + 'logo_light' => null, + 'logo_dark' => null, + 'logo_mark' => null, + 'app_icon' => null, + 'icons' => [], + 'primary_color' => '#0F4C5C', + 'secondary_color' => null, + 'header_style' => 'light', + 'font_body' => 'inter', + 'font_heading' => 'same', + 'custom_font' => null, + 'radius' => 'medium', + 'density' => 'normal', + 'dark_mode' => 'user', + 'login_layout' => 'split', + 'login_title' => 'Alles Wichtige für Ihren Arbeitsalltag – an einem Ort.', + 'login_text' => null, + 'login_image' => null, + 'footer_text' => null, + 'footer_links' => [], + 'email_footer' => null, + 'custom_css' => null, + 'stylesheet' => null, + ]; + + public const HEADER_STYLES = ['light' => 'Hell', 'brand' => 'In der Markenfarbe', 'dark' => 'Dunkel']; + + public const RADII = ['none' => ['Eckig', '0rem'], 'small' => ['Leicht gerundet', '0.25rem'], 'medium' => ['Gerundet', '0.5rem'], 'large' => ['Stark gerundet', '0.75rem'], 'round' => ['Rund', '1rem']]; + + public const DENSITIES = ['compact' => ['Kompakt', '0.225rem'], 'normal' => ['Normal', '0.25rem'], 'comfortable' => ['Luftig', '0.275rem']]; + + public const DARK_MODES = [ + 'user' => 'Jede Person wählt selbst (Standard: wie im System)', + 'light' => 'Immer hell', + 'dark' => 'Immer dunkel', + ]; + + public const LOGIN_LAYOUTS = ['split' => 'Geteilt: Bild bzw. Markenfarbe links, Anmeldung rechts', 'centered' => 'Zentriert: Anmeldung vor dem Hintergrundbild']; + + private const PUBLISHED = 'theme.published'; + + private const DRAFT = 'theme.draft'; + + public function __construct(private readonly Settings $settings) {} + + /** + * @return array + */ + public function published(): array + { + $stored = $this->settings->get(self::PUBLISHED); + + return self::normalize(is_array($stored) ? $stored : $this->legacy()); + } + + /** + * @return array|null + */ + public function draft(): ?array + { + $stored = $this->settings->get(self::DRAFT); + + return is_array($stored) ? self::normalize($stored) : null; + } + + public function hasDraft(): bool + { + return $this->draft() !== null; + } + + /** + * Entwurf, sonst der veröffentlichte Stand – Ausgangspunkt für das Formular. + * + * @return array + */ + public function working(): array + { + return $this->draft() ?? $this->published(); + } + + /** + * @param array $values + */ + public function saveDraft(array $values): void + { + $theme = self::normalize([...$this->working(), ...$values]); + + foreach (['logo_light', 'logo_dark', 'logo_mark'] as $logo) { + SvgSanitizer::sanitizeFile($theme[$logo]); + } + + $this->settings->set(self::DRAFT, $theme); + } + + public function discardDraft(): void + { + $this->settings->set(self::DRAFT, null); + } + + /** + * Entwurf veröffentlichen: statische CSS-Datei erzeugen, Symbole berechnen. + */ + public function publish(ThemeCompiler $compiler, Icons $icons): void + { + $theme = $this->working(); + $theme['icons'] = $icons->generate($theme); + $theme['stylesheet'] = $compiler->write($theme); + + $this->settings->setMany([self::PUBLISHED => $theme, self::DRAFT => null]); + } + + /** + * Auf die Standardwerte zurücksetzen – als Entwurf, damit man es erst ansehen kann. + */ + public function resetToDefaults(): void + { + $this->settings->set(self::DRAFT, self::normalize([...self::DEFAULTS, 'portal_name' => $this->published()['portal_name']])); + } + + /** + * Nur bekannte Schlüssel, gültige Werte. + * + * @param array $theme + * @return array + */ + public static function normalize(array $theme): array + { + $theme = [...self::DEFAULTS, ...Arr::only($theme, array_keys(self::DEFAULTS))]; + $hex = fn ($value) => is_string($value) && preg_match('/^#[0-9a-fA-F]{6}$/', $value) ? strtoupper($value) : null; + + $theme['portal_name'] = mb_substr(trim((string) $theme['portal_name']), 0, 60) ?: self::DEFAULTS['portal_name']; + $theme['primary_color'] = $hex($theme['primary_color']) ?? self::DEFAULTS['primary_color']; + $theme['secondary_color'] = $hex($theme['secondary_color']); + $theme['header_style'] = array_key_exists($theme['header_style'], self::HEADER_STYLES) ? $theme['header_style'] : 'light'; + $theme['font_body'] = array_key_exists($theme['font_body'], Fonts::FONTS) || ($theme['font_body'] === 'custom' && $theme['custom_font']) ? $theme['font_body'] : 'inter'; + $theme['font_heading'] = $theme['font_heading'] === 'same' || array_key_exists($theme['font_heading'], Fonts::FONTS) || ($theme['font_heading'] === 'custom' && $theme['custom_font']) ? $theme['font_heading'] : 'same'; + $theme['radius'] = array_key_exists($theme['radius'], self::RADII) ? $theme['radius'] : 'medium'; + $theme['density'] = array_key_exists($theme['density'], self::DENSITIES) ? $theme['density'] : 'normal'; + $theme['dark_mode'] = array_key_exists($theme['dark_mode'], self::DARK_MODES) ? $theme['dark_mode'] : 'user'; + $theme['login_layout'] = array_key_exists($theme['login_layout'], self::LOGIN_LAYOUTS) ? $theme['login_layout'] : 'split'; + $theme['footer_links'] = array_values(array_filter(array_map( + fn ($link) => is_array($link) && filled($link['label'] ?? null) && filled($link['url'] ?? null) + ? ['label' => mb_substr(trim($link['label']), 0, 60), 'url' => mb_substr(trim($link['url']), 0, 500)] + : null, + (array) $theme['footer_links'], + ))); + $theme['icons'] = is_array($theme['icons']) ? $theme['icons'] : []; + + foreach (['login_title', 'login_text', 'footer_text', 'email_footer'] as $text) { + $theme[$text] = filled($theme[$text]) ? mb_substr(trim((string) $theme[$text]), 0, 500) : null; + } + + foreach (['logo_light', 'logo_dark', 'logo_mark', 'app_icon', 'login_image', 'custom_font'] as $file) { + $theme[$file] = is_string($theme[$file]) && preg_match('#^(theme|branding)/[A-Za-z0-9/_.-]+$#', $theme[$file]) && ! str_contains($theme[$file], '..') ? $theme[$file] : null; + } + + $theme['custom_css'] = filled($theme['custom_css']) ? mb_substr((string) $theme['custom_css'], 0, 50000) : null; + + return $theme; + } + + /** + * Einstellungen aus Phase 0 (Portalname, Logo, Markenfarbe) übernehmen. + * + * @return array + */ + private function legacy(): array + { + return array_filter([ + 'portal_name' => $this->settings->get('branding.portal_name'), + 'primary_color' => $this->settings->get('branding.primary_color'), + 'logo_light' => $this->settings->get('branding.logo_path'), + ]); + } +} diff --git a/app/Support/Theme/ThemeCompiler.php b/app/Support/Theme/ThemeCompiler.php new file mode 100644 index 00000000..875662b9 --- /dev/null +++ b/app/Support/Theme/ThemeCompiler.php @@ -0,0 +1,98 @@ + $theme + */ + public function css(array $theme): string + { + $primary = $theme['primary_color']; + $palette = ColorPalette::fromHex($primary); + $secondary = $theme['secondary_color'] ?? $primary; + $palette2 = ColorPalette::fromHex($secondary); + + $light = [ + '--brand' => $primary, + '--brand-foreground' => ColorPalette::foregroundFor($primary), + '--brand-text' => $palette[Contrast::textShadeOnLight($primary)], + '--accent2' => $secondary, + '--accent2-foreground' => ColorPalette::foregroundFor($secondary), + '--accent2-text' => $palette2[Contrast::textShadeOnLight($secondary)], + '--radius' => Theme::RADII[$theme['radius']][1], + '--spacing' => Theme::DENSITIES[$theme['density']][1], + '--font-body' => Fonts::stack($theme['font_body']), + '--font-heading' => Fonts::stack($theme['font_heading'] === 'same' ? $theme['font_body'] : $theme['font_heading']), + ]; + + foreach ($palette as $shade => $hex) { + $light["--brand-{$shade}"] = $hex; + } + + foreach ($palette2 as $shade => $hex) { + $light["--accent2-{$shade}"] = $hex; + } + + $dark = [ + '--brand-text' => $palette[Contrast::textShadeOnDark($primary)], + '--accent2-text' => $palette2[Contrast::textShadeOnDark($secondary)], + ]; + + $css = ':root{'.$this->declarations($light).'}'."\n" + .'.dark{'.$this->declarations($dark).'}'."\n"; + + if ($theme['custom_font']) { + $url = Storage::disk('uploads')->url($theme['custom_font']); + $css .= '@font-face{font-family:"'.Fonts::CUSTOM_FAMILY.'";src:url("'.$url.'") format("woff2");font-weight:100 900;font-display:swap}'."\n"; + } + + if ($theme['custom_css']) { + // Eigenes CSS steht in einer eigenen CSS-Datei; ein schließendes ist dort bedeutungslos, + // wird aber für die Vorschau (inline) trotzdem entschärft. + $css .= "/* Eigenes CSS */\n".str_ireplace(' $theme + */ + public function write(array $theme): string + { + $css = $this->css($theme); + $path = 'theme/theme-'.substr(sha1($css), 0, 12).'.css'; + $disk = Storage::disk('uploads'); + + if (! $disk->exists($path)) { + $disk->put($path, $css); + } + + // Ältere Fassungen aufräumen (die aktuelle und die vorherige bleiben für offene Seiten). + $old = collect($disk->files('theme'))->filter(fn ($f) => preg_match('#^theme/theme-[0-9a-f]{12}\.css$#', $f) && $f !== $path) + ->sortByDesc(fn ($f) => $disk->lastModified($f))->slice(1); + $disk->delete($old->all()); + + return $path; + } + + /** + * @param array $values + */ + private function declarations(array $values): string + { + return collect($values)->map(fn ($value, $name) => $name.':'.$value)->implode(';'); + } +} diff --git a/app/Support/Theme/ThemeTransfer.php b/app/Support/Theme/ThemeTransfer.php new file mode 100644 index 00000000..78581928 --- /dev/null +++ b/app/Support/Theme/ThemeTransfer.php @@ -0,0 +1,92 @@ + 'svg', 'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/webp' => 'webp', 'font/woff2' => 'woff2', + ]; + + /** + * @param array $theme + * @return array + */ + public function export(array $theme): array + { + $disk = Storage::disk('uploads'); + $files = []; + + foreach (self::FILES as $key) { + if ($theme[$key] && $disk->exists($theme[$key])) { + $mime = $key === 'custom_font' ? 'font/woff2' : ($disk->mimeType($theme[$key]) ?: 'application/octet-stream'); + $files[$key] = 'data:'.$mime.';base64,'.base64_encode((string) $disk->get($theme[$key])); + } + } + + return [ + 'format' => self::FORMAT, + 'version' => 1, + 'exported_at' => now()->toIso8601String(), + 'theme' => collect($theme)->except([...self::FILES, 'icons', 'stylesheet'])->all(), + 'files' => $files, + ]; + } + + /** + * @return array Werte für den Entwurf + */ + public function import(string $json): array + { + $data = json_decode($json, true); + + if (! is_array($data) || ($data['format'] ?? null) !== self::FORMAT || ! is_array($data['theme'] ?? null)) { + throw new RuntimeException('Die Datei ist kein exportiertes Erscheinungsbild.'); + } + + $values = collect($data['theme'])->except([...self::FILES, 'icons', 'stylesheet'])->all(); + + foreach (self::FILES as $key) { + $values[$key] = null; + $uri = $data['files'][$key] ?? null; + + if (! is_string($uri) || ! preg_match('#^data:([a-z0-9.+/-]+);base64,(.+)$#i', $uri, $m)) { + continue; + } + + $extension = self::MIME[strtolower($m[1])] ?? null; + $binary = base64_decode($m[2], true); + + if (! $extension || $binary === false || strlen($binary) > 8 * 1024 * 1024) { + continue; + } + + // Inhalt prüfen: Bilder müssen sich lesen lassen, SVG wird von allem Ausführbaren befreit. + if ($extension === 'svg' && ($binary = SvgSanitizer::sanitize($binary)) === null) { + continue; + } + + if (in_array($extension, ['png', 'jpg', 'webp'], true) && @getimagesizefromstring($binary) === false) { + continue; + } + + $path = ($key === 'custom_font' ? 'theme/fonts/' : 'theme/').'import-'.Str::random(20).'.'.$extension; + Storage::disk('uploads')->put($path, $binary); + $values[$key] = $path; + } + + return Theme::normalize([...Theme::DEFAULTS, ...$values]); + } +} diff --git a/app/Version.php b/app/Version.php index c7787881..355c9695 100644 --- a/app/Version.php +++ b/app/Version.php @@ -9,5 +9,5 @@ namespace App; */ final class Version { - public const VERSION = '0.5.0'; + public const VERSION = '0.7.0'; } diff --git a/bootstrap/app.php b/bootstrap/app.php index 0c5f90d0..68a5f95d 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -5,6 +5,7 @@ use App\Http\Middleware\HandleInertiaRequests; use App\Http\Middleware\RedirectToInstaller; use App\Http\Middleware\RunPendingMigrations; use App\Http\Middleware\RunPseudoCron; +use App\Http\Middleware\ThemePreview; use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; @@ -22,6 +23,7 @@ return Application::configure(basePath: dirname(__DIR__)) RedirectToInstaller::class, ], append: [ RunPendingMigrations::class, + ThemePreview::class, HandleInertiaRequests::class, RunPseudoCron::class, ]); diff --git a/database/migrations/2026_09_28_000005_create_dashboard_tiles_table.php b/database/migrations/2026_09_28_000005_create_dashboard_tiles_table.php new file mode 100644 index 00000000..89d673e6 --- /dev/null +++ b/database/migrations/2026_09_28_000005_create_dashboard_tiles_table.php @@ -0,0 +1,38 @@ +id(); + $table->string('name'); + $table->string('type', 20); + $table->string('area', 20)->default('aside'); + $table->string('title')->nullable(); + $table->string('image_path')->nullable(); + $table->string('url', 2000)->nullable(); + $table->boolean('new_tab')->default(false); + $table->string('alt')->nullable(); + $table->longText('body')->nullable(); + $table->longText('body_html')->nullable(); + $table->string('variant', 20)->nullable(); + $table->boolean('is_active')->default(true); + $table->timestamp('starts_at')->nullable(); + $table->timestamp('ends_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('dashboard_tiles'); + } +}; diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index f3921bab..cfecf48b 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -81,6 +81,44 @@ Die Anmeldung mit Passwort bleibt für Notfälle erhalten (z. B. wenn Entra ID nicht erreichbar ist). Den geheimen Clientschlüssel vor Ablauf erneuern – er ist bei Microsoft befristet. +## Erscheinungsbild + +Unter **Administration → Portal → Erscheinungsbild** lassen sich Name, Logos, +Farben, Schriften, Anmeldeseite, Fußzeile und E-Mails anpassen. Änderungen +werden zuerst als **Entwurf** gespeichert und sind nur in der Vorschau +sichtbar; für alle gelten sie erst nach **Veröffentlichen**. Über „Mehr“ lässt +sich das Erscheinungsbild als Datei exportieren und auf einem anderen System +(z. B. vom Test- auf das Produktivsystem) importieren. + +Schriften werden immer vom eigenen Server ausgeliefert. Eine eigene Schrift +(WOFF2) darf nur hochgeladen werden, wenn ihre Lizenz die Nutzung im Web erlaubt. + +## E-Mail-Versand + +Unter **Administration → E-Mail-Versand** den SMTP-Zugang eintragen (vom +Hoster oder der IT, z. B. Microsoft 365: `smtp.office365.com`, Port 587, +STARTTLS) und mit **Test-Mail senden** prüfen. Das Passwort wird verschlüsselt +gespeichert. Gebraucht wird der Versand für „Passwort vergessen“ und +Formular-Benachrichtigungen. Mails werden über die Hintergrundaufgaben +verschickt – ohne Cron oder Web-Cron also mit etwas Verzögerung. + +## Umstieg von WordPress + +1. In WordPress unter **Werkzeuge → Daten exportieren** „Alle Inhalte“ wählen + und die XML-Datei herunterladen. +2. Im Portal unter **Administration → Inhalte → WordPress-Import** hochladen + und **Datei prüfen**. +3. Kategorien zuordnen (neu anlegen, vorhandene nutzen oder weglassen), + Autorinnen und Autoren prüfen (Zuordnung über die E-Mail-Adresse) und + entscheiden, ob Entwürfe und WordPress-Seiten mitkommen. +4. **Import starten** – die Seite geöffnet lassen, der Import läuft in Portionen. + +Bilder werden von der alten Website geladen, sie muss dafür noch erreichbar +sein. Ein erneuter Import legt nichts doppelt an; auf Wunsch aktualisiert er +bereits übernommene Einträge. Kommentare, Schlagwörter und Inhalte anderer +WordPress-Plugins werden nicht übernommen. Nach dem Umstieg kann das Plugin +„WordPress-Import“ deaktiviert werden. + ## Hintergrundaufgaben Rückmeldungen, geplante Inhalte und Aufräumarbeiten laufen im Hintergrund. Die diff --git a/docs/PLAN.md b/docs/PLAN.md index 819ac9ea..e814dcb0 100644 --- a/docs/PLAN.md +++ b/docs/PLAN.md @@ -452,8 +452,8 @@ Entwickler, ohne Build, direkt im Admin unter „Erscheinungsbild“. ## 13. Mitgelieferte Plugins -**Start:** Dashboard, News/Feed mit Kategorien, CMS-Seiten, Verzeichnis & -Organigramm, Dokumente, App-Launcher. +**Start:** Dashboard, News/Feed mit Kategorien, CMS-Seiten, Formulare, +WordPress-Import, Verzeichnis & Organigramm, Dokumente, App-Launcher. **Später:** Events, Umfragen, Geburtstage/Jubiläen, Onboarding, Raumbuchung, Kantinenplan, Ideenbox, Urlaubsanträge. @@ -482,7 +482,8 @@ Kantinenplan, Ideenbox, Urlaubsanträge. | **2 – Plugin-System & Rechte** ✅ | Plugin-Loader, Hooks/Filter, Registries, Recovery-Modus, Import-Map-Frontend; Rollen, Grants, Zielgruppen, Rechte-Cache, Rechte-Prüfer | | **3 – Entra ID** ✅ | OIDC-Login, JIT, Gruppen-/App-Rollen-Mapping (additiv), Graph-Profil- & Foto-Sync mit frei zuordenbaren Attributen (inkl. Erweiterungsattributen) und eigenen Profilfeldern, Delta-Sync | | **4 – CMS** ✅ | Seitenbaum, Pagebuilder (Layout-, Inhalts-, Medien- und dynamische Blöcke, Sichtbarkeit je Block), Entwürfe, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigaben; News-Freigabe-Workflow und Redaktion im Portal; Benachrichtigungen. Offen: Vorlagen und wiederverwendbare Blöcke | -| **5 – Branding & Theming** | Vollständige Seite „Erscheinungsbild“: Logo-Varianten, Farben inkl. Farbtreue & Kontrastprüfung, Schriften, Form, Login-Seite, E-Mails, Live-Vorschau, Entwurf/Veröffentlichen, Export/Import | +| **4b – Formulare & Umstieg** ✅ | Formular-Plugin (visueller Baukasten im Portal, Bedingungen, Uploads, anonyme Formulare, Mail + Backend, Ergebnis-Rechte je Formular und Rolle, CSV, Löschfristen; eingebunden per Pagebuilder-Block und unter Beiträgen, kein eigener Menüpunkt); WordPress-Import (Beiträge, Kategorien, Bilder, Seiten); E-Mail-Versand im Admin; anpassbare Startseite mit eigenen Kacheln; Geburtstage (optionales Plugin) | +| **5 – Branding & Theming** ✅ | Vollständige Seite „Erscheinungsbild“: Logo-Varianten, Farben inkl. Farbtreue & Kontrastprüfung, Schriften, Form, Login-Seite, E-Mails, Live-Vorschau, Entwurf/Veröffentlichen, Export/Import | | **6 – Weitere Plugins & IdPs** | Verzeichnis/Organigramm, Dokumente, Events …; OIDC generisch, LDAP, SAML; Lasttests 5.000 User | | **7 – Plugin-SDK öffentlich** | Doku, Generator, Beispiel-Plugins (kein Plugin-Verzeichnis) | | **8 – Mobil** | REST-API (Sanctum), Web-Push, native App | diff --git a/docs/PLUGINS.md b/docs/PLUGINS.md index f9bab006..05ce6368 100644 --- a/docs/PLUGINS.md +++ b/docs/PLUGINS.md @@ -116,6 +116,14 @@ $this->app->make(Blocks::class)->add(BlockType::make('mein-plugin.liste', 'Meine - Die Vue-Komponente erhält `block` (`data`, `items`, `props`) – Kinder werden mit `inject('pagebuilder:list')` gerendert. `inject('pagebuilder:editing')` ist im Editor wahr. +## Startseite und Profil + +- Kacheln: `app(App\Dashboard\Widgets::class)->add($key, 'mein-plugin::Kachel', 'aside', sort: 20, props: fn (User $user) => [...], label: 'Name im Admin')`. + Bereiche: `top`, `hero`, `feed`, `main`, `aside`. Admins sortieren und blenden Kacheln unter „Startseite“ aus. +- Abschnitt in „Profil bearbeiten“: `app(App\Profile\ProfileSections::class)->add($key, 'mein-plugin::Abschnitt', $sort, fn (User $user) => [...])` + (Komponente unter `resources/js/profile/`, speichert über eigene Routen). +- Optionale mitgelieferte Plugins: `"enabled_by_default": false` in `plugin.json`. + ## Redaktion, Navigation und Benachrichtigungen - Arbeitslisten im Bereich „Redaktion“: `app(App\Editorial\Editorial::class)->add($key, $label, 'mein-plugin::Liste', $sort, $sichtbar, $props)`. diff --git a/package-lock.json b/package-lock.json index 450b85e3..0cef1324 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,17 @@ "packages": { "": { "devDependencies": { + "@fontsource-variable/figtree": "^5.3.0", + "@fontsource-variable/ibm-plex-sans": "^5.3.0", "@fontsource-variable/inter": "^5.3.0", + "@fontsource-variable/lora": "^5.3.0", + "@fontsource-variable/merriweather": "^5.3.0", + "@fontsource-variable/nunito-sans": "^5.3.0", + "@fontsource-variable/open-sans": "^5.3.0", + "@fontsource-variable/roboto": "^5.3.0", + "@fontsource-variable/source-sans-3": "^5.3.0", + "@fontsource-variable/source-serif-4": "^5.3.0", + "@fontsource/atkinson-hyperlegible": "^5.3.0", "@inertiajs/vue3": "^3.7.1", "@lucide/vue": "^1.48.0", "@tailwindcss/typography": "^0.5.20", @@ -148,6 +158,26 @@ } } }, + "node_modules/@fontsource-variable/figtree": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/figtree/-/figtree-5.3.0.tgz", + "integrity": "sha512-VRVodD7OiG7apQwE8/2fMjaqpY/a0qRJqL5HtYj8CKIVps+9amaFcdfKmDIf7iqYQx6iPLlArVXAfKeIZmVcNQ==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/ibm-plex-sans": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/ibm-plex-sans/-/ibm-plex-sans-5.3.0.tgz", + "integrity": "sha512-agG8tXFEo0hD9+J7npa4vbbWult52eMLVaQ6WQRlhs/iCAojrMAoejru85W9HTVXHfyUj96KM7gp/KGAS87XaQ==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, "node_modules/@fontsource-variable/inter": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/@fontsource-variable/inter/-/inter-5.3.0.tgz", @@ -158,6 +188,86 @@ "url": "https://github.com/sponsors/ayuhito" } }, + "node_modules/@fontsource-variable/lora": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/lora/-/lora-5.3.0.tgz", + "integrity": "sha512-2ph8KiZ8Bn141hWuC3ErtpJ+Ui8p2MJQn8TJNRSRmLmnCIOCtHfiBM9R7WLRPeUG/q6hXyHOxWQ8DvRSX+ixvQ==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/merriweather": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/merriweather/-/merriweather-5.3.0.tgz", + "integrity": "sha512-wK7S4NtPXWUWll/sZCdub93pqSCnFkpKFbnoOE8fh+9Ut6JFjgkc9UlBxHJ0RVMkDpoWwGwMwYYTMvd3G9aAXA==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/nunito-sans": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/nunito-sans/-/nunito-sans-5.3.0.tgz", + "integrity": "sha512-Vk1PSfckNDwgw2yGcsvJP3o/0zEW8Rp6KzbD8Ql/6iRHQshnhhAjt+cSIfAUyp5vQuSlleGHFW2LfYaaex0diw==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/open-sans": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/open-sans/-/open-sans-5.3.0.tgz", + "integrity": "sha512-VOfhZfLIOBVa6K/dTEu7scqQXYdGa4jBX8quFpQ0S6574B+W2EOBJf9PkqyVtMEI7WWIWNEbpvPc3vY1mN2mmQ==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/roboto": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/roboto/-/roboto-5.3.0.tgz", + "integrity": "sha512-BoaaZiQf8fgtxv07KXkTwx1bKz/EoqIlTXq2OOKKXINxp6qXWdnlChqV+hSaDANS49yyUASFl3OVBMMDTCIHFA==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/source-sans-3": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/source-sans-3/-/source-sans-3-5.3.0.tgz", + "integrity": "sha512-dpi0GZk7EQe2tYpg6Q0Fx0OmUgnuGu+0rHPgtXqtKhglYmJuP7jZ12Mu1uN+NfRaJRY1Emn8AQJEWzmoZ4wa9g==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/source-serif-4": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/source-serif-4/-/source-serif-4-5.3.0.tgz", + "integrity": "sha512-9vch9WqxjaaA+1o9Ur8pOgIGbCYLjRReOUel23A6lOpD1syptgjtkORevvNmldJ5kGXQL29onQUqI5Ltz0s3bQ==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource/atkinson-hyperlegible": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource/atkinson-hyperlegible/-/atkinson-hyperlegible-5.3.0.tgz", + "integrity": "sha512-Sp8Ve8+rQmENY2Lv02VH7sLpntzTTvnncnJMTbRE7DX6TLxGraN4ykZfzaUWIoCFmaomwkvNiqmlPkrKBuDoSA==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, "node_modules/@inertiajs/core": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/@inertiajs/core/-/core-3.7.1.tgz", diff --git a/package.json b/package.json index e4a1ba24..ba02e2d2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,17 @@ "dev": "vite" }, "devDependencies": { + "@fontsource-variable/figtree": "^5.3.0", + "@fontsource-variable/ibm-plex-sans": "^5.3.0", "@fontsource-variable/inter": "^5.3.0", + "@fontsource-variable/lora": "^5.3.0", + "@fontsource-variable/merriweather": "^5.3.0", + "@fontsource-variable/nunito-sans": "^5.3.0", + "@fontsource-variable/open-sans": "^5.3.0", + "@fontsource-variable/roboto": "^5.3.0", + "@fontsource-variable/source-sans-3": "^5.3.0", + "@fontsource-variable/source-serif-4": "^5.3.0", + "@fontsource/atkinson-hyperlegible": "^5.3.0", "@inertiajs/vue3": "^3.7.1", "@lucide/vue": "^1.48.0", "@tailwindcss/typography": "^0.5.20", diff --git a/plugins-core/birthdays/database/migrations/2026_09_28_000004_create_birthdays_table.php b/plugins-core/birthdays/database/migrations/2026_09_28_000004_create_birthdays_table.php new file mode 100644 index 00000000..2c23dbee --- /dev/null +++ b/plugins-core/birthdays/database/migrations/2026_09_28_000004_create_birthdays_table.php @@ -0,0 +1,29 @@ +id(); + $table->foreignId('user_id')->unique()->constrained('users')->cascadeOnDelete(); + $table->unsignedTinyInteger('month'); + $table->unsignedTinyInteger('day'); + $table->timestamps(); + + $table->index(['month', 'day']); + }); + } + + public function down(): void + { + Schema::dropIfExists('birthdays'); + } +}; diff --git a/plugins-core/birthdays/plugin.json b/plugins-core/birthdays/plugin.json new file mode 100644 index 00000000..acca40b7 --- /dev/null +++ b/plugins-core/birthdays/plugin.json @@ -0,0 +1,14 @@ +{ + "slug": "birthdays", + "name": "Geburtstage", + "version": "1.0.0", + "description": "Geburtstagsliste zum Mitmachen: Wer möchte, trägt Tag und Monat im Profil ein. Mit Kachel auf der Startseite und Glückwunsch am eigenen Geburtstag.", + "author": "Inhaus", + "namespace": "Inhaus\\Plugins\\Birthdays\\", + "class": "Inhaus\\Plugins\\Birthdays\\BirthdaysPlugin", + "enabled_by_default": false, + "requires": { + "core": ">=0.6.0", + "php": ">=8.3" + } +} diff --git a/plugins-core/birthdays/resources/js/blocks/BirthdaysBlock.vue b/plugins-core/birthdays/resources/js/blocks/BirthdaysBlock.vue new file mode 100644 index 00000000..75c21b30 --- /dev/null +++ b/plugins-core/birthdays/resources/js/blocks/BirthdaysBlock.vue @@ -0,0 +1,15 @@ + + + diff --git a/plugins-core/birthdays/resources/js/components/BirthdayItem.vue b/plugins-core/birthdays/resources/js/components/BirthdayItem.vue new file mode 100644 index 00000000..8b233a29 --- /dev/null +++ b/plugins-core/birthdays/resources/js/components/BirthdayItem.vue @@ -0,0 +1,28 @@ + + + diff --git a/plugins-core/birthdays/resources/js/pages/Index.vue b/plugins-core/birthdays/resources/js/pages/Index.vue new file mode 100644 index 00000000..925c9ef8 --- /dev/null +++ b/plugins-core/birthdays/resources/js/pages/Index.vue @@ -0,0 +1,52 @@ + + + diff --git a/plugins-core/birthdays/resources/js/profile/ProfileBirthday.vue b/plugins-core/birthdays/resources/js/profile/ProfileBirthday.vue new file mode 100644 index 00000000..ddfdfb66 --- /dev/null +++ b/plugins-core/birthdays/resources/js/profile/ProfileBirthday.vue @@ -0,0 +1,69 @@ + + + diff --git a/plugins-core/birthdays/resources/js/widgets/Greeting.vue b/plugins-core/birthdays/resources/js/widgets/Greeting.vue new file mode 100644 index 00000000..412b0eb4 --- /dev/null +++ b/plugins-core/birthdays/resources/js/widgets/Greeting.vue @@ -0,0 +1,55 @@ + + + diff --git a/plugins-core/birthdays/resources/js/widgets/Upcoming.vue b/plugins-core/birthdays/resources/js/widgets/Upcoming.vue new file mode 100644 index 00000000..b48f8b56 --- /dev/null +++ b/plugins-core/birthdays/resources/js/widgets/Upcoming.vue @@ -0,0 +1,17 @@ + + + diff --git a/plugins-core/birthdays/routes/web.php b/plugins-core/birthdays/routes/web.php new file mode 100644 index 00000000..bc970cba --- /dev/null +++ b/plugins-core/birthdays/routes/web.php @@ -0,0 +1,10 @@ +group(function () { + Route::get('/geburtstage', [BirthdayController::class, 'index'])->name('birthdays.index'); + Route::put('/profil/geburtstag', [BirthdayController::class, 'update'])->name('birthdays.update'); + Route::delete('/profil/geburtstag', [BirthdayController::class, 'destroy'])->name('birthdays.destroy'); +}); diff --git a/plugins-core/birthdays/src/BirthdayList.php b/plugins-core/birthdays/src/BirthdayList.php new file mode 100644 index 00000000..dbf0547c --- /dev/null +++ b/plugins-core/birthdays/src/BirthdayList.php @@ -0,0 +1,95 @@ + 'Alle Mitarbeitenden', + 'department' => 'Nur die eigene Abteilung', + 'location' => 'Nur der eigene Standort', + ]; + + public function __construct(private readonly Settings $settings) {} + + public function scope(): string + { + return array_key_exists($s = (string) $this->settings->get('birthdays.scope', 'all'), self::SCOPES) ? $s : 'all'; + } + + public function daysAhead(): int + { + return max(0, min(60, (int) $this->settings->get('birthdays.days', 7))); + } + + public function greetingEnabled(): bool + { + return (bool) $this->settings->get('birthdays.greeting', true); + } + + /** + * @return list}> + */ + public function upcoming(User $viewer, ?int $days = null, ?string $scope = null, int $limit = 200): array + { + $days ??= $this->daysAhead(); + $scope ??= $this->scope(); + $today = Carbon::today(); + $end = $today->copy()->addDays($days); + + // Nur die betroffenen Monate laden (höchstens drei), dann genau filtern. + $months = collect(range(0, (int) $today->copy()->startOfMonth()->diffInMonths($end->copy()->startOfMonth()))) + ->map(fn ($i) => $today->copy()->startOfMonth()->addMonths($i)->month)->unique()->values()->all(); + + $birthdays = Birthday::query() + ->whereIn('month', $months) + ->whereHas('user', function ($q) use ($viewer, $scope) { + $q->where('is_active', true); + + if ($scope === 'department') { + $viewer->department ? $q->where('department', $viewer->department) : $q->whereKey($viewer->id); + } elseif ($scope === 'location') { + $viewer->location ? $q->where('location', $viewer->location) : $q->whereKey($viewer->id); + } + }) + ->with('user') + ->get(); + + return $birthdays + ->map(fn (Birthday $b) => ['birthday' => $b, 'date' => $b->nextOccurrence($today)]) + ->filter(fn ($row) => $row['date']->lte($end)) + ->sortBy(fn ($row) => $row['date']->format('Ymd').mb_strtolower($row['birthday']->user->last_name.' '.$row['birthday']->user->first_name)) + ->take($limit) + ->map(fn ($row) => [ + 'date' => $row['date']->toDateString(), + 'today' => $row['date']->isSameDay($today), + 'person' => (new PersonResource($row['birthday']->user))->resolve(), + ]) + ->values() + ->all(); + } + + public function isBirthdayToday(User $user): bool + { + return (bool) Birthday::query()->where('user_id', $user->id)->first()?->isOn(Carbon::today()); + } + + /** + * @return Collection + */ + public static function months(): Collection + { + return collect(range(1, 12))->mapWithKeys(fn ($m) => [$m => Carbon::create(2000, $m, 1)->locale('de')->translatedFormat('F')]); + } +} diff --git a/plugins-core/birthdays/src/BirthdaysPlugin.php b/plugins-core/birthdays/src/BirthdaysPlugin.php new file mode 100644 index 00000000..7659a79d --- /dev/null +++ b/plugins-core/birthdays/src/BirthdaysPlugin.php @@ -0,0 +1,60 @@ +app->singleton(BirthdayList::class); + + $this->app->make(ProfileSections::class)->add('birthday', 'birthdays::ProfileBirthday', 10, function (User $user) { + $birthday = Birthday::query()->where('user_id', $user->id)->first(); + + return [ + 'birthday' => $birthday ? ['day' => $birthday->day, 'month' => $birthday->month] : null, + 'months' => BirthdayList::months()->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(), + 'scope' => app(BirthdayList::class)->scope(), + ]; + }); + + $widgets = $this->app->make(Widgets::class); + + // Glückwunsch oben auf der Startseite – nur am eigenen Geburtstag. + $widgets->add('birthdays.greeting', 'birthdays::Greeting', 'top', sort: 0, props: function (User $user) { + $list = app(BirthdayList::class); + + return $list->greetingEnabled() && $list->isBirthdayToday($user) ? ['name' => $user->first_name ?: $user->name] : null; + }, label: 'Geburtstagsgruß (am eigenen Geburtstag)', mobileSort: -100); + + $widgets->add('birthdays.upcoming', 'birthdays::Upcoming', 'aside', sort: 30, props: function (User $user) { + $list = app(BirthdayList::class); + $upcoming = $list->upcoming($user, limit: 8); + + return $upcoming === [] ? null : ['birthdays' => $upcoming, 'days' => $list->daysAhead()]; + }, label: 'Geburtstage', mobileSort: 35); + + $this->app->make(Blocks::class)->add(BlockType::make('birthdays.list', 'Geburtstage', 'cake', 'dynamic', 'birthdays::BirthdaysBlock') + ->description('Anstehende Geburtstage – z. B. auf der Seite einer Abteilung.') + ->fields([ + Field::text('title', 'Überschrift', 150, 'Geburtstage'), + Field::select('scope', 'Wessen Geburtstage', ['' => 'Wie in den Einstellungen'] + BirthdayList::SCOPES, ''), + Field::number('days', 'Tage im Voraus', 0, 60, 14), + ]) + ->resolveUsing(fn (array $data, ?User $user) => $user ? [ + 'birthdays' => app(BirthdayList::class)->upcoming($user, $data['days'], $data['scope'] ?: null, 30), + ] : null)); + } +} diff --git a/plugins-core/birthdays/src/Filament/Pages/BirthdaySettings.php b/plugins-core/birthdays/src/Filament/Pages/BirthdaySettings.php new file mode 100644 index 00000000..0913c457 --- /dev/null +++ b/plugins-core/birthdays/src/Filament/Pages/BirthdaySettings.php @@ -0,0 +1,69 @@ +|null */ + public ?array $data = []; + + public static function canAccess(): bool + { + return auth()->user()?->can('appearance.manage') ?? false; + } + + public function mount(BirthdayList $list): void + { + $this->form->fill(['scope' => $list->scope(), 'days' => $list->daysAhead(), 'greeting' => $list->greetingEnabled()]); + } + + public function form(Schema $schema): Schema + { + return $schema->statePath('data')->components([ + Section::make('Geburtstagsliste') + ->description(fn () => 'Mitarbeitende tragen sich freiwillig im Profil ein (nur Tag und Monat). Derzeit eingetragen: '.Birthday::query()->count().'.') + ->columns(2) + ->schema([ + Select::make('scope')->label('Wer sieht wessen Geburtstag')->options(BirthdayList::SCOPES)->required()->native(false), + TextInput::make('days')->label('Tage im Voraus auf der Startseite')->numeric()->minValue(0)->maxValue(60)->required(), + Toggle::make('greeting')->label('Am eigenen Geburtstag auf der Startseite gratulieren')->columnSpanFull(), + ]), + ]); + } + + public function save(Settings $settings): void + { + $state = $this->form->getState(); + $settings->setMany(['birthdays.scope' => $state['scope'], 'birthdays.days' => (int) $state['days'], 'birthdays.greeting' => (bool) $state['greeting']]); + + Notification::make()->success()->title('Gespeichert')->send(); + } +} diff --git a/plugins-core/birthdays/src/Http/Controllers/BirthdayController.php b/plugins-core/birthdays/src/Http/Controllers/BirthdayController.php new file mode 100644 index 00000000..956304a0 --- /dev/null +++ b/plugins-core/birthdays/src/Http/Controllers/BirthdayController.php @@ -0,0 +1,48 @@ + $list->upcoming($request->user(), 30), + 'scope' => BirthdayList::SCOPES[$list->scope()], + 'registered' => Birthday::query()->where('user_id', $request->user()->id)->exists(), + ]); + } + + public function update(Request $request): RedirectResponse + { + $data = $request->validate([ + 'day' => ['required', 'integer', 'between:1,31'], + 'month' => ['required', 'integer', 'between:1,12'], + ], [], ['day' => 'Tag', 'month' => 'Monat']); + + // Gültiger Tag im Monat (29. Februar erlaubt). + if (! checkdate($data['month'], $data['day'], 2000)) { + throw ValidationException::withMessages(['day' => 'Diesen Tag gibt es im gewählten Monat nicht.']); + } + + Birthday::query()->updateOrCreate(['user_id' => $request->user()->id], $data); + + return back()->with('status', 'birthday-saved'); + } + + public function destroy(Request $request): RedirectResponse + { + Birthday::query()->where('user_id', $request->user()->id)->delete(); + + return back()->with('status', 'birthday-removed'); + } +} diff --git a/plugins-core/birthdays/src/Models/Birthday.php b/plugins-core/birthdays/src/Models/Birthday.php new file mode 100644 index 00000000..237f39cc --- /dev/null +++ b/plugins-core/birthdays/src/Models/Birthday.php @@ -0,0 +1,46 @@ + + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + + /** + * Nächster Geburtstag ab $from (heute eingeschlossen). Der 29. Februar + * wird in Nicht-Schaltjahren am 28. Februar gefeiert. + */ + public function nextOccurrence(Carbon $from): Carbon + { + $date = self::inYear($from->year, $this->month, $this->day); + + return $date->lt($from->copy()->startOfDay()) ? self::inYear($from->year + 1, $this->month, $this->day) : $date; + } + + public function isOn(Carbon $date): bool + { + return self::inYear($date->year, $this->month, $this->day)->isSameDay($date); + } + + private static function inYear(int $year, int $month, int $day): Carbon + { + if ($month === 2 && $day === 29 && ! Carbon::create($year)->isLeapYear()) { + $day = 28; + } + + return Carbon::create($year, $month, $day)->startOfDay(); + } +} diff --git a/plugins-core/events/resources/js/components/EventDateBlock.vue b/plugins-core/events/resources/js/components/EventDateBlock.vue index 75cf3336..1bfdb474 100644 --- a/plugins-core/events/resources/js/components/EventDateBlock.vue +++ b/plugins-core/events/resources/js/components/EventDateBlock.vue @@ -12,6 +12,6 @@ const block = computed(() => dateBlock(props.date)); diff --git a/plugins-core/events/src/EventsPlugin.php b/plugins-core/events/src/EventsPlugin.php index 87dd9343..99093a8a 100644 --- a/plugins-core/events/src/EventsPlugin.php +++ b/plugins-core/events/src/EventsPlugin.php @@ -25,7 +25,7 @@ class EventsPlugin extends Plugin $this->app->make(Widgets::class)->add('events.upcoming', 'events::Upcoming', 'aside', sort: 20, props: fn (User $user) => [ 'events' => EventResource::collection(Event::query()->upcoming()->visibleTo($user)->limit(4)->get())->resolve(), - ], mobileSort: 30); + ], label: 'Termine', mobileSort: 30); $this->app->make(Blocks::class)->add(BlockType::make('events.upcoming', 'Termine', 'calendar-days', 'dynamic', 'events::UpcomingEvents') ->description('Die nächsten Termine.') diff --git a/plugins-core/forms/database/migrations/2026_09_28_000002_create_forms_tables.php b/plugins-core/forms/database/migrations/2026_09_28_000002_create_forms_tables.php new file mode 100644 index 00000000..7ae396dc --- /dev/null +++ b/plugins-core/forms/database/migrations/2026_09_28_000002_create_forms_tables.php @@ -0,0 +1,57 @@ +id(); + $table->string('title'); + $table->string('slug', 120)->unique(); + $table->text('description')->nullable(); + $table->json('fields'); + $table->json('settings')->nullable(); + $table->boolean('is_open')->default(true); + $table->timestamp('closes_at')->nullable(); + $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete(); + $table->timestamps(); + }); + + Schema::create('form_submissions', function (Blueprint $table) { + $table->id(); + $table->foreignId('form_id')->constrained('forms')->cascadeOnDelete(); + // Bei anonymen Formularen leer; „nur einmal ausfüllen“ prüft dann user_hash. + $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete(); + $table->string('user_hash', 64)->nullable(); + $table->json('data'); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + + $table->index(['form_id', 'created_at']); + $table->index(['form_id', 'user_hash']); + $table->index(['form_id', 'user_id']); + }); + + Schema::create('form_files', function (Blueprint $table) { + $table->id(); + $table->foreignId('submission_id')->constrained('form_submissions')->cascadeOnDelete(); + $table->string('field', 80); + $table->string('name'); + $table->string('path'); + $table->string('mime', 150)->nullable(); + $table->unsignedBigInteger('size')->default(0); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('form_files'); + Schema::dropIfExists('form_submissions'); + Schema::dropIfExists('forms'); + } +}; diff --git a/plugins-core/forms/plugin.json b/plugins-core/forms/plugin.json new file mode 100644 index 00000000..0d1c1f80 --- /dev/null +++ b/plugins-core/forms/plugin.json @@ -0,0 +1,13 @@ +{ + "slug": "forms", + "name": "Formulare", + "version": "1.0.0", + "description": "Formulare zusammenstellen – Anträge, Anmeldungen, Umfragen, Meldungen. Ergebnisse per E-Mail und im Backend, Zugriff je Formular und Rolle.", + "author": "Inhaus", + "namespace": "Inhaus\\Plugins\\Forms\\", + "class": "Inhaus\\Plugins\\Forms\\FormsPlugin", + "requires": { + "core": ">=0.6.0", + "php": ">=8.3" + } +} diff --git a/plugins-core/forms/resources/js/blocks/FormBlock.vue b/plugins-core/forms/resources/js/blocks/FormBlock.vue new file mode 100644 index 00000000..4436a8ec --- /dev/null +++ b/plugins-core/forms/resources/js/blocks/FormBlock.vue @@ -0,0 +1,21 @@ + + + diff --git a/plugins-core/forms/resources/js/components/FormRenderer.vue b/plugins-core/forms/resources/js/components/FormRenderer.vue new file mode 100644 index 00000000..d78b10e0 --- /dev/null +++ b/plugins-core/forms/resources/js/components/FormRenderer.vue @@ -0,0 +1,218 @@ + + +