From 42ff577cb84f59f1acbadbf641381ef63e2588b4 Mon Sep 17 00:00:00 2001 From: Triopsi Date: Fri, 23 Oct 2026 04:08:44 +0000 Subject: [PATCH 1/2] feat: add search bar --- README.md | 1 + .../Resources/Devices/DeviceResource.php | 38 +++++ .../IpAddresses/IpAddressResource.php | 38 +++++ app/Providers/Filament/AdminPanelProvider.php | 2 + .../filament-panels/de/global-search.php | 11 ++ tests/Feature/Filament/GlobalSearchTest.php | 152 ++++++++++++++++++ 6 files changed, 242 insertions(+) create mode 100644 resources/lang/vendor/filament-panels/de/global-search.php create mode 100644 tests/Feature/Filament/GlobalSearchTest.php diff --git a/README.md b/README.md index 7ecf38d..226d6e2 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Once a homelab grows beyond a handful of devices, remembering which IP belongs t - **See subnet occupancy at a glance.** Open the subnet grid to distinguish free, assigned and reserved addresses, then assign a free host to a device with a click, creating the device inline if needed. - **Find the next free address.** See available, assigned and reserved IPs, and assign an available address to a device without searching through a spreadsheet. - **Keep devices and addresses together.** Record hostnames, MAC addresses, device types, locations, descriptions and service URLs. Associate multiple addresses with a device and mark its primary IP. +- **Find records from anywhere.** Use the topbar search or press **⌘K / Ctrl+K** to find devices and IP addresses. Search names, hostnames, MAC addresses or address fragments, then open a matching record directly. - **Use your own device types.** Click **+** beside **Type** when creating or editing a device to add a type such as NAS or Smart plug. It is selected immediately and becomes available to every other device, including in filters. - **Give your network some structure.** Organize IPv4 and IPv6 addresses into groups, document subnets and VLAN IDs, and create address ranges in bulk. - **Bring your existing inventory.** Import device lists from CSV with column mapping and export selected devices when you need to share or process them elsewhere. diff --git a/app/Filament/Resources/Devices/DeviceResource.php b/app/Filament/Resources/Devices/DeviceResource.php index 62f09f8..bc4c9d6 100644 --- a/app/Filament/Resources/Devices/DeviceResource.php +++ b/app/Filament/Resources/Devices/DeviceResource.php @@ -22,6 +22,8 @@ use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; /** * DeviceResource @@ -44,6 +46,42 @@ class DeviceResource extends Resource { protected static ?string $model = Device::class; + protected static ?string $recordTitleAttribute = 'name'; + + protected static ?bool $isGlobalSearchForcedCaseInsensitive = true; + + protected static int $globalSearchResultsLimit = 20; + + /** + * Search device identifiers and assigned addresses from the panel's topbar. + * + * @return array Columns and relationships supported by native global search. + */ + public static function getGloballySearchableAttributes(): array + { + return ['name', 'hostname', 'mac_address', 'location', 'ipAddresses.ip_address']; + } + + /** Eager-load address labels to avoid a separate query for each search result. */ + public static function getGlobalSearchEloquentQuery(): Builder + { + return parent::getGlobalSearchEloquentQuery()->with('ipAddresses:id,ip_address'); + } + + /** + * Show identifying context alongside each device title using current-locale labels. + * + * @return array Nonempty details, with at most three address labels. + */ + public static function getGlobalSearchResultDetails(Model $record): array + { + return array_filter([ + __('devices.fields.hostname') => $record->hostname, + __('devices.fields.mac_address') => $record->mac_address, + __('ip_addresses.plural_model_label') => $record->ipAddresses->take(3)->pluck('ip_address')->implode(', '), + ], fn ($value): bool => filled($value)); + } + protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-server'; protected static ?string $navigationLabel = null; diff --git a/app/Filament/Resources/IpAddresses/IpAddressResource.php b/app/Filament/Resources/IpAddresses/IpAddressResource.php index 7f08818..308388e 100644 --- a/app/Filament/Resources/IpAddresses/IpAddressResource.php +++ b/app/Filament/Resources/IpAddresses/IpAddressResource.php @@ -24,6 +24,8 @@ use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; /** * Resource for managing IP address records within the Filament admin panel. @@ -48,6 +50,42 @@ class IpAddressResource extends Resource { protected static ?string $model = IpAddress::class; + protected static ?string $recordTitleAttribute = 'ip_address'; + + protected static ?bool $isGlobalSearchForcedCaseInsensitive = true; + + protected static int $globalSearchResultsLimit = 20; + + /** + * Find addresses by their value, network context or linked device identifiers. + * + * @return array Columns and relationships supported by native global search. + */ + public static function getGloballySearchableAttributes(): array + { + return ['ip_address', 'subnet', 'description', 'group.name', 'devices.name', 'devices.hostname']; + } + + /** Eager-load group and device labels so result details do not issue per-row queries. */ + public static function getGlobalSearchEloquentQuery(): Builder + { + return parent::getGlobalSearchEloquentQuery()->with(['group:id,name', 'devices:id,name']); + } + + /** + * Add localized network and device context to an address search result. + * + * @return array Nonempty details, with at most three device names. + */ + public static function getGlobalSearchResultDetails(Model $record): array + { + return array_filter([ + __('ip_addresses.fields.subnet') => $record->subnet, + __('ip_addresses.fields.group') => $record->group?->name, + __('devices.plural_model_label') => $record->devices->take(3)->pluck('name')->implode(', '), + ], fn ($value): bool => filled($value)); + } + protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-globe-alt'; protected static ?string $navigationLabel = null; diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index eed0a19..2c4525a 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -39,6 +39,8 @@ public function panel(Panel $panel): Panel ->brandName('OpenIPAM') ->brandLogo(fn () => view('filament.admin.logo')) ->brandLogoHeight('auto') + ->globalSearchKeyBindings(['command+k', 'ctrl+k']) + ->globalSearchFieldKeyBindingSuffix() ->favicon(asset('images/favicon.png')) ->colors([ 'primary' => Color::Blue, diff --git a/resources/lang/vendor/filament-panels/de/global-search.php b/resources/lang/vendor/filament-panels/de/global-search.php new file mode 100644 index 0000000..11d03c9 --- /dev/null +++ b/resources/lang/vendor/filament-panels/de/global-search.php @@ -0,0 +1,11 @@ + [ + 'instructions' => 'Drücke die Pfeiltaste nach unten, um die Ergebnisse zu durchsuchen. Mit den Pfeiltasten nach oben und unten wechselst du zwischen Treffern, mit Tab erreichst du deren Aktionen. Mit Escape schließt du die Ergebnisse.', + ], + 'results_label' => 'Ergebnisse der globalen Suche', + 'results_count' => ':count Ergebnis angezeigt.|:count Ergebnisse angezeigt.', + 'loading_message' => 'Suche läuft …', + 'failure_message' => 'Die Suche konnte nicht abgeschlossen werden. Lade die Seite neu, um es erneut zu versuchen.', +]; diff --git a/tests/Feature/Filament/GlobalSearchTest.php b/tests/Feature/Filament/GlobalSearchTest.php new file mode 100644 index 0000000..a65de41 --- /dev/null +++ b/tests/Feature/Filament/GlobalSearchTest.php @@ -0,0 +1,152 @@ +actingAs(User::factory()->withoutTwoFactor()->create()); + Filament::setCurrentPanel(Filament::getPanel('admin')); + } + + /** + * Render the native search field in the authenticated panel header. + * + * Expect: The topbar contains the search input and supports the same Mac and Windows shortcuts as SplitNest. + */ + public function test_search_is_available_in_the_topbar(): void + { + $panel = Filament::getPanel('admin'); + $this->assertSame(GlobalSearchPosition::Topbar, $panel->getGlobalSearchPosition()); + $this->assertSame(['command+k', 'ctrl+k'], $panel->getGlobalSearchKeyBindings()); + $this->get('/admin')->assertOk()->assertSee('type="search"', false); + } + + /** + * Search device identifiers and related IPv4/IPv6 values with mixed-case input. + * + * Expect: Each supported identifier finds only the matching device and links directly to its editor. + */ + public function test_devices_are_found_by_identifiers_and_assigned_addresses(): void + { + $device = Device::factory()->create([ + 'name' => 'Storage NAS', 'hostname' => 'nas.lab.example', + 'mac_address' => 'AA:BB:CC:DD:EE:01', 'location' => 'Lab rack', + ]); + Device::factory()->create(['name' => 'Unrelated device', 'hostname' => 'other.example', 'location' => 'Office']); + foreach (['192.0.2.42', '2001:db8::42'] as $address) { + $ip = IpAddress::factory()->create(['ip_address' => $address]); + $device->ipAddresses()->attach($ip); + } + + foreach (['storage nas', 'NAS.LAB', 'aa:bb:cc:dd:ee:01', 'lab rack', '192.0.2.42', '2001:DB8::42'] as $term) { + $result = DeviceResource::getGlobalSearchResults($term)->sole(); + $this->assertSame('Storage NAS', $result->title); + $this->assertSame(DeviceResource::getUrl('edit', ['record' => $device]), $result->url); + $this->assertEqualsCanonicalizing(['192.0.2.42', '2001:db8::42'], explode(', ', $result->details[__('ip_addresses.plural_model_label')])); + } + } + + /** + * Find address records through network metadata and linked devices. + * + * Expect: Partial addresses, subnets, notes, groups, device names and hostnames return the matching IP editor link. + */ + public function test_addresses_are_found_by_network_context_and_linked_devices(): void + { + $group = IpAddressGroup::factory()->create(['name' => 'Homelab servers']); + $ip = IpAddress::factory()->create([ + 'ip_address' => '192.0.2.42', 'subnet' => '192.0.2.0/24', + 'description' => 'Backup endpoint', 'group_id' => $group->id, + ]); + $device = Device::factory()->create(['name' => 'Storage NAS', 'hostname' => 'nas.lab.example']); + $device->ipAddresses()->attach($ip); + IpAddress::factory()->create(['ip_address' => '198.51.100.10', 'subnet' => '198.51.100.0/24', 'description' => 'Unrelated']); + + foreach (['192.0.2.', '192.0.2.0/24', 'BACKUP', 'homelab servers', 'storage nas', 'NAS.LAB'] as $term) { + $result = IpAddressResource::getGlobalSearchResults($term)->sole(); + $this->assertSame('192.0.2.42', $result->title); + $this->assertSame(IpAddressResource::getUrl('edit', ['record' => $ip]), $result->url); + $this->assertSame('Storage NAS', $result->details[__('devices.plural_model_label')]); + } + } + + /** + * Search from the Livewire field and render localized result categories. + * + * Expect: Both resource categories and their links appear in English and German, while unmatched searches show the native empty state. + */ + public function test_live_search_groups_results_and_handles_empty_searches_in_both_languages(): void + { + $device = Device::factory()->create(['name' => 'Storage NAS', 'hostname' => 'nas.lab.example']); + $ip = IpAddress::factory()->create(['ip_address' => '192.0.2.42']); + $device->ipAddresses()->attach($ip); + + foreach (['en', 'de'] as $locale) { + app()->setLocale($locale); + $page = Livewire::test(GlobalSearch::class)->set('search', 'NAS.LAB') + ->assertSee(__('devices.plural_model_label')) + ->assertSee(__('ip_addresses.plural_model_label')) + ->assertSee('Storage NAS')->assertSee('192.0.2.42') + ->assertSeeHtml(DeviceResource::getUrl('edit', ['record' => $device])) + ->assertSeeHtml(IpAddressResource::getUrl('edit', ['record' => $ip])); + $this->assertCount(2, $page->instance()->getResults()->getCategories()); + if ($locale === 'de') { + $page->assertSee('2 Ergebnisse angezeigt.') + ->assertSee('Pfeiltaste nach unten') + ->assertDontSee('Press Down arrow'); + } + $page->set('search', 'no-such-inventory-record') + ->assertSee(__('filament-panels::global-search.no_results_message')); + $page->set('search', ' '); + $this->assertNull($page->instance()->getResults()); + } + } + + /** + * Search a broad term that matches more records than the dropdown can display. + * + * Expect: Each resource returns at most twenty results to keep the header dropdown bounded. + */ + public function test_each_search_category_has_a_bounded_result_count(): void + { + Device::factory()->count(21)->create(['name' => 'Limit test device']); + IpAddress::factory()->count(21)->create(['description' => 'Limit test address']); + $this->assertCount(20, DeviceResource::getGlobalSearchResults('Limit test device')); + $this->assertCount(20, IpAddressResource::getGlobalSearchResults('Limit test address')); + } + + /** + * Deny resource access using the application's authorization layer. + * + * Expect: The native provider omits both resource categories when the user cannot view inventory. + */ + public function test_search_respects_resource_access_checks(): void + { + Device::factory()->create(['name' => 'Private inventory']); + IpAddress::factory()->create(['description' => 'Private inventory']); + Gate::before(fn (User $user, string $ability): ?bool => $ability === 'viewAny' ? false : null); + + $this->assertTrue(Filament::getGlobalSearchProvider()->getResults('Private inventory')->getCategories()->isEmpty()); + } +} From c8f0407fe2dd0f751d955a20d55c33b73a169b17 Mon Sep 17 00:00:00 2001 From: Triopsi Date: Fri, 23 Oct 2026 04:17:19 +0000 Subject: [PATCH 2/2] feat: show actual version on footer --- app/Providers/Filament/AdminPanelProvider.php | 1 + config/app.php | 3 +++ resources/views/filament/version-footer.blade.php | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 resources/views/filament/version-footer.blade.php diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 2c4525a..814bccf 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -77,6 +77,7 @@ public function panel(Panel $panel): Panel ->databaseNotifications() ->databaseNotificationsPolling('30s') ->viteTheme('resources/css/filament/admin/theme.css') + ->renderHook(PanelsRenderHook::FOOTER, fn (): View => view('filament.version-footer')) ->userMenuItems([ 'profile' => fn (Action $action): Action => $action ->label(fn (): string => __('common.navigation.profile')) diff --git a/config/app.php b/config/app.php index 980d907..6ed341d 100644 --- a/config/app.php +++ b/config/app.php @@ -17,6 +17,9 @@ 'name' => env('APP_NAME', 'Laravel'), + // Release images receive APP_VERSION from the build pipeline; source checkouts show dev. + 'version' => env('APP_VERSION', 'dev'), + /* |-------------------------------------------------------------------------- | Application Environment diff --git a/resources/views/filament/version-footer.blade.php b/resources/views/filament/version-footer.blade.php new file mode 100644 index 0000000..580df73 --- /dev/null +++ b/resources/views/filament/version-footer.blade.php @@ -0,0 +1,3 @@ +