on call to /device, check for duplicates by dns
This commit is contained in:
@@ -154,20 +154,29 @@ hook 'before_template' => sub {
|
||||
|
||||
get '/device' => require_login sub {
|
||||
my $q = param('q');
|
||||
my $dev = schema('netdisco')->resultset('Device')->single({
|
||||
my $schema = schema('netdisco')->resultset('Device');
|
||||
|
||||
# we are passed either dns or ip
|
||||
my $dev = $schema->search({
|
||||
-or => [
|
||||
\[ 'host(me.ip) = ?' => [ bind_value => $q ] ],
|
||||
'me.dns' => $q,
|
||||
],
|
||||
});
|
||||
|
||||
if (!defined $dev) {
|
||||
if ($dev->count == 0) {
|
||||
return redirect uri_for('/', {nosuchdevice => 1})->path_query;
|
||||
}
|
||||
|
||||
# if passed dns, need to check for duplicates
|
||||
# and use only ip for q param, if there are duplicates.
|
||||
my $first = $dev->first;
|
||||
my $others = ($schema->search({dns => $first->dns})->count() - 1);
|
||||
|
||||
params->{'tab'} ||= 'details';
|
||||
template 'device', {
|
||||
d => $dev,
|
||||
display_name => ($others ? $first->ip : $first->dns),
|
||||
device => params->{'tab'},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -81,7 +81,7 @@ get '/search' => require_login sub {
|
||||
# redirect to device details for the one device
|
||||
return redirect uri_for('/device', {
|
||||
tab => 'details',
|
||||
q => ($nd->first->dns || $nd->first->ip),
|
||||
q => $nd->first->ip,
|
||||
f => '',
|
||||
})->path_query;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
</ul>
|
||||
<form class="navbar-search pull-left" method="get" action="[% uri_for('/search') %]">
|
||||
<input placeholder="Find Anything" class="search-query span3"
|
||||
id="nq" name="q" type="text" autocomplete="off"/>
|
||||
id="nq" name="q" value="[% display_name %]" type="text" autocomplete="off"/>
|
||||
<div class="btn-group nd_navbar-search-group">
|
||||
<button class="btn btn-inverse nd_navbar-search-icon">
|
||||
<span style="font-size: 18px;">
|
||||
|
||||
Reference in New Issue
Block a user