Typeahead on the main navbar search (for devices only)

This commit is contained in:
Oliver Gorwits
2012-08-27 19:54:31 +01:00
parent 4cd0c06567
commit 8ae1bb1d6d
3 changed files with 19 additions and 0 deletions

View File

@@ -171,6 +171,15 @@ ajax '/ajax/content/device/details' => sub {
}, { layout => undef };
};
# support typeahead with simple AJAX query for device names
ajax '/ajax/data/device/typeahead' => sub {
my $q = param('query');
my $set = schema('netdisco')->resultset('Device')->search_fuzzy($q);
content_type 'application/json';
return to_json [map {$_->dns || $_->name || $_->ip} $set->all];
};
get '/device' => sub {
my $ip = NetAddr::IP::Lite->new(param('q'));
if (! $ip) {