use simple find for device ip or name
This commit is contained in:
		| @@ -87,20 +87,21 @@ hook 'before_template' => sub { | ||||
| }; | ||||
|  | ||||
| get '/device' => sub { | ||||
|     my $ip = NetAddr::IP::Lite->new(param('q')); | ||||
|     if (! $ip) { | ||||
|         redirect uri_for('/', {nosuchdevice => 1}); | ||||
|         return; | ||||
|     } | ||||
|     my $q = param('q'); | ||||
|     my $dev = schema('netdisco')->resultset('Device')->single({ | ||||
|         -or => [ | ||||
|             ip => $q, | ||||
|             dns => $q, | ||||
|         ], | ||||
|     }); | ||||
|  | ||||
|     my $device = schema('netdisco')->resultset('Device')->find($ip->addr); | ||||
|     if (! $device) { | ||||
|     if (! $dev) { | ||||
|         redirect uri_for('/', {nosuchdevice => 1}); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     params->{'tab'} ||= 'details'; | ||||
|     template 'device', { d => $device }; | ||||
|     template 'device', { d => $dev }; | ||||
| }; | ||||
|  | ||||
| true; | ||||
|   | ||||
| @@ -66,7 +66,7 @@ get '/search' => sub { | ||||
|     my $s = schema('netdisco'); | ||||
|  | ||||
|     if (not param('tab')) { | ||||
|         if (not $q) { redirect uri_for('/') } | ||||
|         if (not $q) { return redirect uri_for('/') } | ||||
|  | ||||
|         # pick most likely tab for initial results | ||||
|         if ($q =~ m/^\d+$/) { | ||||
| @@ -78,7 +78,7 @@ get '/search' => sub { | ||||
|             if ($nd and $nd->count) { | ||||
|                 if ($nd->count == 1) { | ||||
|                     # redirect to device details for the one device | ||||
|                     redirect uri_for('/device', | ||||
|                     return redirect uri_for('/device', | ||||
|                         {tab => 'details', q => $q, f => ''}); | ||||
|                 } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user