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