Navbar query for device with single hit redirects to Device details page

This commit is contained in:
Oliver Gorwits
2012-09-02 20:18:39 +01:00
parent ce9d1e3b6f
commit f04abd9125
2 changed files with 17 additions and 4 deletions

View File

@@ -2,7 +2,9 @@
[ENHANCEMENTS]
* Move DBIC virtual tables into Virtual:: namespace.
* Move DBIC virtual tables into Virtual:: namespace (closes #19)
* Maintain node search options when changing navbar query (closes #27)
* Navbar query for device with single hit redirects to Device details page
0.6 2012-08-28

View File

@@ -210,7 +210,13 @@ get '/search' => sub {
my $s = schema('netdisco');
if ($q =~ m{^[a-f0-9.:/]+$}i) {
my $ip = NetAddr::IP::Lite->new($q);
if ($ip and $s->resultset('Device')->search_by_field({ip => $q})->count) {
my $nd = $s->resultset('Device')->search_by_field({ip => $q});
if ($ip and $nd->count) {
if ($nd->count == 1) {
# redirect to device details for the one device
redirect uri_for('/device',
{tab => 'details', q => $q, f => ''});
}
params->{'tab'} = 'device';
}
else {
@@ -220,8 +226,13 @@ get '/search' => sub {
}
}
else {
if ($s->resultset('Device')
->search({dns => { '-ilike' => "\%$q\%" }})->count) {
my $nd = $s->resultset('Device')->search({dns => { '-ilike' => "\%$q\%" }});
if ($nd->count) {
if ($nd->count == 1) {
# redirect to device details for the one device
redirect uri_for('/device',
{tab => 'details', q => $nd->first->ip, f => ''});
}
params->{'tab'} = 'device';
}
elsif ($s->resultset('DevicePort')