diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 3b06abd0..487c4425 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -145,6 +145,7 @@ hook 'before_template' => sub { # for templates to link to same page with modified query but same options my $self_uri = uri_for(request->path, scalar params); + $self_uri->query_param_delete('uuid'); $self_uri->query_param_delete('q'); $self_uri->query_param_delete('f'); $self_uri->query_param_delete('prefer'); @@ -152,13 +153,11 @@ hook 'before_template' => sub { }; get '/device' => require_login sub { - my $q = param('q'); - my $dev = schema('netdisco')->resultset('Device')->single({ - -or => [ - \[ 'host(me.ip) = ?' => [ bind_value => $q ] ], - 'me.dns' => $q, - ], - }); + my $uuid = param('uuid'); + + my $dev = schema('netdisco')->resultset('Device')->single( + \[ 'host(me.ip) = ?' => [ bind_value => $uuid ] ], + ); if (!defined $dev) { return redirect uri_for('/', {nosuchdevice => 1})->path_query; diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index 92f48675..36296d9a 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -78,10 +78,13 @@ get '/search' => require_login sub { if ($nd and $nd->count) { if ($nd->count == 1) { + my $row = $nd->first; + # redirect to device details for the one device return redirect uri_for('/device', { tab => 'details', - q => ($nd->first->dns || $nd->first->ip), + uuid => $row->ip, + q => ($row->dns || $row->ip), f => '', })->path_query; } diff --git a/Netdisco/share/public/javascripts/netdisco.js b/Netdisco/share/public/javascripts/netdisco.js index 2bfcb63f..4920458e 100644 --- a/Netdisco/share/public/javascripts/netdisco.js +++ b/Netdisco/share/public/javascripts/netdisco.js @@ -74,6 +74,9 @@ function update_content(from, to) { $('#' + to + '_search').toggleClass('active'); var to_form = '#' + to + '_form'; + var form = $(to_form).find('input[name!=q]') + .add('') + .add(''); var from_form = '#' + from + '_form'; // page title @@ -93,8 +96,8 @@ function update_content(from, to) { if (window.History && window.History.enabled && is_from_state_event == 0) { is_from_history_plugin = 1; window.History.pushState( - {name: to, fields: $(to_form).serializeArray()}, - pgtitle, uri_base + '/' + path + '?' + $(to_form).serialize() + {name: to, fields: form.serializeArray()}, + pgtitle, uri_base + '/' + path + '?' + form.serialize() ); is_from_history_plugin = 0; } diff --git a/Netdisco/share/views/js/common.js b/Netdisco/share/views/js/common.js index 578f4c03..e6a958c4 100644 --- a/Netdisco/share/views/js/common.js +++ b/Netdisco/share/views/js/common.js @@ -1,8 +1,10 @@ // csv download icon on any table page // needs to be dynamically updated to use current search options function update_csv_download_link (type, tab, show) { - var form = '#' + tab + '_form'; - var query = $(form).serialize(); + var form = $('#' + tab + '_form').find('input[name!=q]') + .add('') + .add(''); + var query = form.serialize(); if (show.length) { $('#nd_csv-download') @@ -29,8 +31,10 @@ // update browser search history with the new query. // support history add (push) or replace via push parameter function update_browser_history (tab, pgtitle, push) { - var form = '#' + tab + '_form'; - var query = $(form).serialize(); + var form = $('#' + tab + '_form').find('input[name!=q]') + .add('') + .add(''); + var query = form.serialize(); if (query.length) { query = '?' + query } if (window.History && window.History.enabled) { @@ -40,13 +44,13 @@ var target = uri_base + '/' + path + '/' + tab + query; if (location.pathname == target) { return }; window.History.pushState( - {name: tab, fields: $(form).serializeArray()}, pgtitle, target + {name: tab, fields: form.serializeArray()}, pgtitle, target ); } else { var target = uri_base + '/' + path + query; window.History.replaceState( - {name: tab, fields: $(form).serializeArray()}, pgtitle, target + {name: tab, fields: form.serializeArray()}, pgtitle, target ); } @@ -59,11 +63,11 @@ var form = '#' + tab + '_form'; // copy navbar value to currently active sidebar form - if ($('#nq').val()) { - $(form).find("input[name=q]").val( $('#nq').val() ); + if ($('#uuid').val()) { + $(form).find("input[name=q]").val( $('#uuid').val() ); } // then copy to all other inactive tab sidebars - $('form').find("input[name=q]").each( function() { + $('.nd_sidebar-form').find("input[name=q]").each( function() { $(this).val( $(form).find("input[name=q]").val() ); }); } @@ -105,13 +109,16 @@ // form reset icon on ports tab $('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&' + $('#ports_form') - .find('input[name="q"],input[name="f"],input[name="partial"],input[name="invert"]') + .find('input[name="f"],input[name="partial"],input[name="invert"]') + .add('') + .add('') .serialize()); [% ELSIF tab.tag == 'netmap' %] // form reset icon on netmap tab - $('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&' + - $('#netmap_form').find('input[name="q"]').serialize()); + $('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&' + + '&q=' + $('#nq').val() + + '&uuid=' + $('#uuid').val()); [% END %] do_search(event, '[% tab.tag %]'); diff --git a/Netdisco/share/views/layouts/main.tt b/Netdisco/share/views/layouts/main.tt index cdb17e84..8b159cf7 100644 --- a/Netdisco/share/views/layouts/main.tt +++ b/Netdisco/share/views/layouts/main.tt @@ -116,7 +116,8 @@