Symbole im automatischen Menü (0.40.0) #62

Merged
friloo merged 1 commit from feature/menue-symbole into main 2026-09-27 18:02:27 +00:00
21 changed files with 102 additions and 29 deletions

View file

@ -4,6 +4,12 @@ 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.40.0
- Automatisches Menü: Jeder Hauptpunkt hat jetzt ein passendes Symbol (Startseite, Neuigkeiten, Termine, Gruppen, Nachrichten …); Seiten in der Hauptnavigation ein Seiten-Symbol. Untermenüpunkte bleiben ohne
- Menü-Editor: Beim Umstieg vom automatischen Menü werden die Symbole übernommen; wer einen Bereich wählt, bekommt dessen Symbol vorgeschlagen
- Für Plugins: `Navigation::add(…, icon: 'lucide-name')`; ohne Angabe gilt ein Standard bzw. ein neutrales Symbol
## 0.39.1
- Plugin-SDK: Sind mehrere Plugins mit eigener Oberfläche aktiv, konnte das CSS eines Plugins die Handy-/Desktop-Umschaltung (z. B. `ih:lg:hidden`) eines anderen überschreiben. Regeln mit Variante werden beim Bauen jetzt verstärkt – Plugins bitte mit der neuen `inhaus-sdk/vite.js` neu bauen

View file

@ -19,6 +19,7 @@ use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Illuminate\Support\HtmlString;
@ -105,6 +106,8 @@ class MenuSettings extends Page
Select::make('type')->label('Art')->options($types)->default('module')->required()->live()->native(false)->selectablePlaceholder(false),
Select::make('module')->label('Bereich')->required()->native(false)
->options(fn (Get $get) => $navigation->modules() + (filled($get('module')) && ! isset($navigation->modules()[$get('module')]) ? [$get('module') => $get('module').' (Plugin deaktiviert)'] : []))
// Symbol des Bereichs vorschlagen, solange noch keines gewählt ist
->live()->afterStateUpdated(fn (?string $state, Get $get, Set $set) => $state && blank($get('icon')) ? $set('icon', $navigation->iconFor($state)) : null)
->visible(fn (Get $get) => $get('type') === 'module'),
Select::make('target')->label(fn (Get $get) => $navigation->sourceTypes()[$get('type')] ?? 'Ziel')
->options(fn (Get $get) => $navigation->sourceOptions((string) $get('type')))
@ -185,9 +188,9 @@ class MenuSettings extends Page
foreach ($navigation->automatic(request(), auth()->user()) as $item) {
if (isset($modules[$item['key']])) {
$items[] = ['id' => (string) Str::uuid(), 'type' => 'module', 'module' => $item['key'], 'label' => null, 'roles' => [], 'children' => []];
$items[] = ['id' => (string) Str::uuid(), 'type' => 'module', 'module' => $item['key'], 'label' => null, 'icon' => $item['icon'], 'roles' => [], 'children' => []];
} elseif (preg_match('/^page-(\d+)$/', $item['key'], $m) && array_key_exists('page', $navigation->sourceTypes())) {
$items[] = ['id' => (string) Str::uuid(), 'type' => 'page', 'target' => $m[1], 'subpages' => true, 'label' => null, 'roles' => [], 'children' => []];
$items[] = ['id' => (string) Str::uuid(), 'type' => 'page', 'target' => $m[1], 'subpages' => true, 'label' => null, 'icon' => $item['icon'], 'roles' => [], 'children' => []];
}
}

View file

@ -112,7 +112,7 @@ class AppServiceProvider extends ServiceProvider
? $this->app->make(Widgets::class)->resolveOne($data['widget'], $user, request())
: null));
$this->app->make(Navigation::class)->add('editorial', 'Redaktion', '/redaktion', active: ['editorial', 'pages.editor', 'news.editor.*', 'forms.builder', 'media.*'], sort: 85,
$this->app->make(Navigation::class)->add('editorial', 'Redaktion', '/redaktion', active: ['editorial', 'pages.editor', 'news.editor.*', 'forms.builder', 'media.*'], sort: 85, icon: 'pen-line',
visible: fn (User $user) => $this->app->make(Editorial::class)->visibleFor($user));
$this->registerMedia();

View file

@ -11,7 +11,7 @@ use Illuminate\Http\Request;
/**
* Hauptnavigation des Portals als Registry: Kern und Plugins tragen Einträge ein.
*
* app(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: 'news.*', sort: 20);
* app(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: 'news.*', sort: 20, icon: 'newspaper');
*
* Dynamische Einträge (z. B. Seiten aus dem Seitenbaum) liefert ein Provider:
*
@ -25,7 +25,7 @@ use Illuminate\Http\Request;
*/
class Navigation
{
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null, visible: Closure|null}> */
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null, visible: Closure|null, icon: string|null}> */
private array $items = [];
/** @var array<string, Closure> */
@ -33,6 +33,30 @@ class Navigation
public const MENU_SETTING = 'navigation.menu';
/** Symbole im automatischen Menü, wenn ein Bereich keines mitgibt (auch separat installierte Plugins) */
public const DEFAULT_ICONS = [
'home' => 'house',
'people' => 'contact',
'editorial' => 'pen-line',
'news' => 'newspaper',
'events' => 'calendar-days',
'downloads' => 'folder-down',
'qm' => 'shield-check',
'gemeinsam' => 'handshake',
'speiseplan' => 'utensils',
'it-service' => 'headset',
'glossar' => 'book-a',
'stellen' => 'briefcase',
'umfragen' => 'vote',
'ideen' => 'lightbulb',
'forms' => 'clipboard-list',
'chat' => 'message-circle',
'gruppen' => 'users-round',
'kleinanzeigen' => 'shopping-bag',
];
public const FALLBACK_ICON = 'layout-grid';
/** @var array<string, array{label: string, options: Closure, resolve: Closure}> */
private array $sources = [];
@ -41,17 +65,31 @@ class Navigation
public function __construct()
{
$this->add('home', 'Startseite', '/', active: 'dashboard', sort: 0);
$this->add('people', 'Personen', '/personen', active: 'people.*', sort: 90);
$this->add('home', 'Startseite', '/', active: 'dashboard', sort: 0, icon: 'house');
$this->add('people', 'Personen', '/personen', active: 'people.*', sort: 90, icon: 'contact');
}
/**
* @param string|list<string> $active Routennamen (mit *), bei denen der Eintrag aktiv ist
* @param (Closure(User): bool)|null $visible zusätzliche Bedingung je Person
*/
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null, ?Closure $visible = null): void
/**
* @param string|null $icon Lucide-Symbol im automatischen Menü (z. B. „calendar-days“)
*/
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null, ?Closure $visible = null, ?string $icon = null): void
{
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability, 'visible' => $visible];
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability, 'visible' => $visible, 'icon' => $icon];
}
/**
* Symbol eines Bereichs: angegeben, sonst ein passender Standard (auch für Plugins, die
* noch kein Symbol mitgeben), sonst ein neutrales.
*/
public function iconFor(string $key): string
{
$icon = $this->items[$key]['icon'] ?? self::DEFAULT_ICONS[$key] ?? null;
return Icons::has($icon) ? $icon : self::FALLBACK_ICON;
}
public function remove(string $key): void
@ -139,6 +177,7 @@ class Navigation
'href' => $item['href'],
'active' => $item['active'] !== [] && $request->routeIs(...$item['active']),
'sort' => $item['sort'],
'icon' => $this->iconFor($key),
]);
foreach ($this->providers as $key => $provider) {
@ -150,7 +189,8 @@ class Navigation
}
return $items->sortBy('sort')
->map(fn (array $item) => ['key' => $item['key'], 'label' => $item['label'], 'href' => $item['href'], 'active' => (bool) $item['active'], 'icon' => null, 'new_tab' => false, 'children' => []])
// Jeder Hauptpunkt mit Symbol – Seiten aus der Hauptnavigation mit Seiten-Symbol
->map(fn (array $item) => ['key' => $item['key'], 'label' => $item['label'], 'href' => $item['href'], 'active' => (bool) $item['active'], 'icon' => Icons::has($item['icon'] ?? null) ? $item['icon'] : 'file-text', 'new_tab' => false, 'children' => []])
->values()
->all();
}

View file

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

View file

@ -56,7 +56,7 @@ class Plugin extends BasePlugin
public function register(): void
{
// Menüpunkt im Portal
$this->app->make(Navigation::class)->add('mein-plugin', 'Mein Bereich', '/mein-bereich', active: 'mein-plugin.*', sort: 40);
$this->app->make(Navigation::class)->add('mein-plugin', 'Mein Bereich', '/mein-bereich', active: 'mein-plugin.*', sort: 40, icon: 'sparkles');
// Rechte, die im Rollen-Formular erscheinen
$this->app->make(Abilities::class)->define('mein-plugin.manage', 'Mein Bereich verwalten', 'Mein Plugin');
@ -133,6 +133,7 @@ $this->app->make(Blocks::class)->add(BlockType::make('mein-plugin.liste', 'Meine
`app(Navigation::class)->source('typ', 'Bezeichnung', fn () => [id => 'Name'], fn (string $id, array $item, Request $request, ?User $user) => ['label' => …, 'href' => …, 'active' => …, 'children' => [...]] ?: null)`.
- Symbole: `App\Support\Icons` (alle Lucide-Symbole lokal; kuratierte Auswahl in `resources/icons/icons.json`, nach Änderungen `npm run icons`), im Portal `<AppIcon name="…" />` aus `@/components/AppIcon.vue`.
- Seitenköpfe im Portal: `@/components/PageHeader.vue` (Titel, Beschreibung, Pfad, Slot „actions“).
- Menü-Symbol: `add(…, icon: 'calendar-days')` – ein Lucide-Name; ohne Angabe ein neutrales Symbol. Dynamische Punkte können `'icon'` mitliefern.
- Dynamische Menüpunkte: `app(Navigation::class)->provider('mein-plugin', fn (Request $request, ?User $user) => [...])`;
feste Menüpunkte können mit `visible: fn (User $user) => …` je Person ausgeblendet werden.
- Benachrichtigungen (Glocke im Portal): `$user->notify(new App\Notifications\PortalNotification($titel, $text, $url))`.

View file

@ -25,7 +25,7 @@ class DownloadsPlugin extends Plugin
$this->app->singleton(FolderTree::class);
$this->app->make(Navigation::class)->add('downloads', 'Downloads', '/downloads', active: 'downloads.*', sort: 50);
$this->app->make(Navigation::class)->add('downloads', 'Downloads', '/downloads', active: 'downloads.*', sort: 50, icon: 'folder-down');
$abilities = $this->app->make(Abilities::class);
$abilities->define('downloads.manage', 'Downloads: gesamten Bereich verwalten', 'Downloads');

View file

@ -39,7 +39,7 @@ class EventsPlugin extends Plugin
$this->app->make(GlobalSearch::class)->add('events', 'Termine', 'calendar-days', fn (...$args) => app(EventSearch::class)(...$args), sort: 20);
$this->app->make(Navigation::class)->add('events', 'Termine', '/termine', active: 'events.*', sort: 30);
$this->app->make(Navigation::class)->add('events', 'Termine', '/termine', active: 'events.*', sort: 30, icon: 'calendar-days');
$this->app->make(Abilities::class)->define('events.manage', 'Termine verwalten', 'Termine', portal: true);
Gate::policy(Event::class, EventPolicy::class);

View file

@ -10,7 +10,7 @@ class GemeinsamPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('gemeinsam', 'Gemeinsam', '/gemeinsam', active: 'gemeinsam.*', sort: 65);
$this->app->make(Navigation::class)->add('gemeinsam', 'Gemeinsam', '/gemeinsam', active: 'gemeinsam.*', sort: 65, icon: 'handshake');
$this->app->make(Abilities::class)->define('gemeinsam.manage', 'Personalnachrichten pflegen (Gemeinsam feiern …)', 'Gemeinsam', portal: true);
}
}

View file

@ -11,7 +11,7 @@ class GlossarPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('glossar', 'Glossar', '/glossar', active: 'glossary.*', sort: 75);
$this->app->make(Navigation::class)->add('glossar', 'Glossar', '/glossar', active: 'glossary.*', sort: 75, icon: 'book-a');
$this->app->make(Abilities::class)->define('glossary.manage', 'Glossar pflegen', 'Glossar', portal: true);
$this->app->make(GlobalSearch::class)->add('glossar', 'Glossar', 'book-open', fn (...$args) => app(GlossarySearch::class)(...$args), sort: 45);
}

View file

@ -16,7 +16,7 @@ class IdeenPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('ideen', 'Ideenbox', '/ideen', active: 'ideas.*', sort: 76);
$this->app->make(Navigation::class)->add('ideen', 'Ideenbox', '/ideen', active: 'ideas.*', sort: 76, icon: 'lightbulb');
$this->app->make(Digest::class)->add('ideen', 'Neue Ideen', 40, fn (User $user, CarbonImmutable $since) => Idea::query()
->whereNull('hidden_at')->where('created_at', '>=', $since)->orderByDesc('supports_count')->latest()->limit(5)->get()
->map(fn (Idea $idea) => [

View file

@ -21,7 +21,7 @@ class ItServicePlugin extends Plugin
$this->app->singleton(Settings::class);
$this->app->make(Abilities::class)->define('it-service.manage', 'IT-Service (OpenNIT) einrichten', 'IT-Service');
$this->app->make(Navigation::class)->add('it-service', 'IT-Service', '/it-service', active: 'it-service.*', sort: 75);
$this->app->make(Navigation::class)->add('it-service', 'IT-Service', '/it-service', active: 'it-service.*', sort: 75, icon: 'headset');
// Knopf „Meine IT“ im Profilkasten der Startseite
Hooks::filter('greeting.actions', fn (array $actions, User $user) => app(Settings::class)->configured() && app(PluginAccess::class)->allows('it-service', $user)

View file

@ -60,7 +60,7 @@ class NewsPlugin extends Plugin
$this->app->make(GlobalSearch::class)->add('news', 'Neuigkeiten', 'newspaper', fn (...$args) => app(NewsSearch::class)(...$args), sort: 10);
$this->app->make(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: ['news.index', 'news.show'], sort: 20);
$this->app->make(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: ['news.index', 'news.show'], sort: 20, icon: 'newspaper');
$abilities = $this->app->make(Abilities::class);
$abilities->define('news.manage', 'Neuigkeiten: alle Kategorien verwalten', 'Neuigkeiten');

View file

@ -23,7 +23,7 @@ class QmPlugin extends Plugin
$this->app->singleton($class);
}
$this->app->make(Navigation::class)->add('qm', 'Qualitätsmanagement', '/qm', active: 'qm.*', sort: 55,
$this->app->make(Navigation::class)->add('qm', 'Qualitätsmanagement', '/qm', active: 'qm.*', sort: 55, icon: 'shield-check',
visible: fn (User $user) => $this->app->make(QmAccess::class)->allows($user));
// Startseite: noch zu bestätigende QM-Dokumente (nur wenn es welche gibt)

View file

@ -15,7 +15,7 @@ class SpeiseplanPlugin extends Plugin
public function register(): void
{
$this->app->make(Navigation::class)->add('speiseplan', 'Speiseplan', '/speiseplan', active: 'speiseplan.*', sort: 70);
$this->app->make(Navigation::class)->add('speiseplan', 'Speiseplan', '/speiseplan', active: 'speiseplan.*', sort: 70, icon: 'utensils');
$this->app->make(Abilities::class)->define('speiseplan.manage', 'Speiseplan hochladen', 'Speiseplan', portal: true);
}

View file

@ -19,7 +19,7 @@ class StellenPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('stellen', 'Stellen', '/stellen', active: 'jobs.*', sort: 72);
$this->app->make(Navigation::class)->add('stellen', 'Stellen', '/stellen', active: 'jobs.*', sort: 72, icon: 'briefcase');
$this->app->make(Digest::class)->add('stellen', 'Neue interne Stellen', 50, fn (User $user, CarbonImmutable $since) => JobPosting::query()
->open()->where('published_at', '>=', $since)->latest('published_at')->limit(5)->get()

View file

@ -19,7 +19,7 @@ class UmfragenPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('umfragen', 'Umfragen', '/umfragen', active: 'polls.*', sort: 74);
$this->app->make(Navigation::class)->add('umfragen', 'Umfragen', '/umfragen', active: 'polls.*', sort: 74, icon: 'vote');
$this->app->make(Digest::class)->add('umfragen', 'Ihre Meinung ist gefragt', 30, fn (User $user) => Poll::query()
->open()->visibleTo($user)->latest('published_at')->limit(10)->get()
->reject(fn (Poll $poll) => $poll->hasVoted($user))->take(5)

View file

@ -20,7 +20,7 @@ class {{studly}}Plugin extends Plugin
public function register(): void
{
// Menüpunkt im Portal („Mehr“ bzw. unter „Menü“ im Backend frei anordenbar)
$this->app->make(Navigation::class)->add('{{slug}}', '{{name}}', '/{{slug}}', active: '{{slug}}.*', sort: 80);
$this->app->make(Navigation::class)->add('{{slug}}', '{{name}}', '/{{slug}}', active: '{{slug}}.*', sort: 80, icon: 'sparkles');
// Kachel auf der Startseite – Vue-Komponente resources/js/widgets/Hello.vue
$this->app->make(Widgets::class)->add('{{slug}}.hello', '{{slug}}::Hello', 'aside', sort: 90,

View file

@ -22,13 +22,16 @@ class HeaderItemsTest extends TestCase
$items->add('forms', 'forms::Broken', fn () => throw new \RuntimeException('kaputt'));
$user = User::factory()->create();
$this->actingAs($user)->get('/')->assertInertia(fn (Assert $p) => $p
->has('headerItems', 1)->where('headerItems.0.component', 'news::Unread')->where('headerItems.0.props.unread', 3));
// Nur die hier angemeldeten Symbole betrachten – lokal installierte Plugins bringen ggf. eigene mit
$mine = fn (array $items) => collect($items)->whereIn('key', ['news', 'events', 'forms'])->values()->all();
$this->actingAs($user)->get('/')->assertInertia(fn (Assert $p) => $p->where('headerItems', fn ($items) => $mine($items->all()) === [
['key' => 'news', 'component' => 'news::Unread', 'props' => ['unread' => 3]],
]));
// Vom Modul ausgeschlossene Rollen sehen das Symbol nicht
$role = Role::query()->create(['name' => 'Extern']);
app(PluginAccess::class)->exclude('news', [$role->id]);
$external = User::factory()->withRoles([$role])->create();
$this->actingAs($external)->get('/')->assertInertia(fn (Assert $p) => $p->has('headerItems', 0));
$this->actingAs($external)->get('/')->assertInertia(fn (Assert $p) => $p->where('headerItems', fn ($items) => $mine($items->all()) === []));
}
}

View file

@ -45,6 +45,25 @@ class MenuTest extends TestCase
$this->assertContains('news', $keys);
}
public function test_every_top_level_item_of_the_automatic_menu_has_an_icon(): void
{
$navigation = app(Navigation::class);
$navigation->add('eigenes-plugin', 'Eigenes', '/eigenes', sort: 99);
$navigation->add('mit-symbol', 'Mit Symbol', '/mit', sort: 98, icon: 'rocket');
$navigation->add('falsches-symbol', 'Falsch', '/falsch', sort: 97, icon: 'gibt-es-nicht');
$this->page('Leitbild')->forceFill(['in_navigation' => true])->save();
$menu = collect($this->menuFor(User::factory()->admin()->create()))->keyBy('key');
$this->assertTrue($menu->every(fn ($item) => filled($item['icon'])), 'Jeder Hauptpunkt hat ein Symbol');
$this->assertSame('house', $menu['home']['icon']);
$this->assertSame('newspaper', $menu['news']['icon']);
$this->assertSame('rocket', $menu['mit-symbol']['icon']);
$this->assertSame(Navigation::FALLBACK_ICON, $menu['eigenes-plugin']['icon']);
$this->assertSame(Navigation::FALLBACK_ICON, $menu['falsches-symbol']['icon']);
$this->assertSame('file-text', $menu->first(fn ($i) => str_starts_with($i['key'], 'page-'))['icon']);
}
public function test_custom_menu_with_pages_subpages_groups_links_and_roles(): void
{
$mav = $this->page('Mitarbeitervertretung');
@ -101,6 +120,7 @@ class MenuTest extends TestCase
$component = Livewire::test(MenuSettings::class);
$items = $component->get('data.items');
$this->assertSame('home', collect($items)->first()['module']);
$this->assertSame('house', collect($items)->first()['icon'], 'Symbole des automatischen Menüs werden übernommen');
$component->set('data.items', [
'x' => ['id' => 'x', 'type' => 'module', 'module' => 'news', 'label' => 'News', 'icon' => 'newspaper', 'roles' => [], 'children' => [

View file

@ -3,7 +3,7 @@
'name' => 'inhaus/inhaus',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '93e83469f308f39f18f11899ba884a7a6f6f0f3e',
'reference' => 'a704d12d2ad19f8bf5d8c5f527f32ee4837f7f81',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@ -550,7 +550,7 @@
'inhaus/inhaus' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '93e83469f308f39f18f11899ba884a7a6f6f0f3e',
'reference' => 'a704d12d2ad19f8bf5d8c5f527f32ee4837f7f81',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),