add uuid support to device page sidebar

This commit is contained in:
Oliver Gorwits
2014-01-22 23:06:19 +00:00
parent f711047a33
commit 12e1446c99
5 changed files with 36 additions and 23 deletions

View File

@@ -145,6 +145,7 @@ hook 'before_template' => sub {
# for templates to link to same page with modified query but same options # for templates to link to same page with modified query but same options
my $self_uri = uri_for(request->path, scalar params); 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('q');
$self_uri->query_param_delete('f'); $self_uri->query_param_delete('f');
$self_uri->query_param_delete('prefer'); $self_uri->query_param_delete('prefer');
@@ -152,13 +153,11 @@ hook 'before_template' => sub {
}; };
get '/device' => require_login sub { get '/device' => require_login sub {
my $q = param('q'); my $uuid = param('uuid');
my $dev = schema('netdisco')->resultset('Device')->single({
-or => [ my $dev = schema('netdisco')->resultset('Device')->single(
\[ 'host(me.ip) = ?' => [ bind_value => $q ] ], \[ 'host(me.ip) = ?' => [ bind_value => $uuid ] ],
'me.dns' => $q, );
],
});
if (!defined $dev) { if (!defined $dev) {
return redirect uri_for('/', {nosuchdevice => 1})->path_query; return redirect uri_for('/', {nosuchdevice => 1})->path_query;

View File

@@ -78,10 +78,13 @@ get '/search' => require_login sub {
if ($nd and $nd->count) { if ($nd and $nd->count) {
if ($nd->count == 1) { if ($nd->count == 1) {
my $row = $nd->first;
# redirect to device details for the one device # redirect to device details for the one device
return redirect uri_for('/device', { return redirect uri_for('/device', {
tab => 'details', tab => 'details',
q => ($nd->first->dns || $nd->first->ip), uuid => $row->ip,
q => ($row->dns || $row->ip),
f => '', f => '',
})->path_query; })->path_query;
} }

View File

@@ -74,6 +74,9 @@ function update_content(from, to) {
$('#' + to + '_search').toggleClass('active'); $('#' + to + '_search').toggleClass('active');
var to_form = '#' + to + '_form'; var to_form = '#' + to + '_form';
var form = $(to_form).find('input[name!=q]')
.add('<input name="q" type="hidden" value="' + $('#nq').val() + '"/>')
.add('<input name="uuid" type="hidden" value="' + $('#uuid').val() + '"/>');
var from_form = '#' + from + '_form'; var from_form = '#' + from + '_form';
// page title // page title
@@ -93,8 +96,8 @@ function update_content(from, to) {
if (window.History && window.History.enabled && is_from_state_event == 0) { if (window.History && window.History.enabled && is_from_state_event == 0) {
is_from_history_plugin = 1; is_from_history_plugin = 1;
window.History.pushState( window.History.pushState(
{name: to, fields: $(to_form).serializeArray()}, {name: to, fields: form.serializeArray()},
pgtitle, uri_base + '/' + path + '?' + $(to_form).serialize() pgtitle, uri_base + '/' + path + '?' + form.serialize()
); );
is_from_history_plugin = 0; is_from_history_plugin = 0;
} }

View File

@@ -1,8 +1,10 @@
// csv download icon on any table page // csv download icon on any table page
// needs to be dynamically updated to use current search options // needs to be dynamically updated to use current search options
function update_csv_download_link (type, tab, show) { function update_csv_download_link (type, tab, show) {
var form = '#' + tab + '_form'; var form = $('#' + tab + '_form').find('input[name!=q]')
var query = $(form).serialize(); .add('<input name="q" type="hidden" value="' + $('#nq').val() + '"/>')
.add('<input name="uuid" type="hidden" value="' + $('#uuid').val() + '"/>');
var query = form.serialize();
if (show.length) { if (show.length) {
$('#nd_csv-download') $('#nd_csv-download')
@@ -29,8 +31,10 @@
// update browser search history with the new query. // update browser search history with the new query.
// support history add (push) or replace via push parameter // support history add (push) or replace via push parameter
function update_browser_history (tab, pgtitle, push) { function update_browser_history (tab, pgtitle, push) {
var form = '#' + tab + '_form'; var form = $('#' + tab + '_form').find('input[name!=q]')
var query = $(form).serialize(); .add('<input name="q" type="hidden" value="' + $('#nq').val() + '"/>')
.add('<input name="uuid" type="hidden" value="' + $('#uuid').val() + '"/>');
var query = form.serialize();
if (query.length) { query = '?' + query } if (query.length) { query = '?' + query }
if (window.History && window.History.enabled) { if (window.History && window.History.enabled) {
@@ -40,13 +44,13 @@
var target = uri_base + '/' + path + '/' + tab + query; var target = uri_base + '/' + path + '/' + tab + query;
if (location.pathname == target) { return }; if (location.pathname == target) { return };
window.History.pushState( window.History.pushState(
{name: tab, fields: $(form).serializeArray()}, pgtitle, target {name: tab, fields: form.serializeArray()}, pgtitle, target
); );
} }
else { else {
var target = uri_base + '/' + path + query; var target = uri_base + '/' + path + query;
window.History.replaceState( 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'; var form = '#' + tab + '_form';
// copy navbar value to currently active sidebar form // copy navbar value to currently active sidebar form
if ($('#nq').val()) { if ($('#uuid').val()) {
$(form).find("input[name=q]").val( $('#nq').val() ); $(form).find("input[name=q]").val( $('#uuid').val() );
} }
// then copy to all other inactive tab sidebars // 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() ); $(this).val( $(form).find("input[name=q]").val() );
}); });
} }
@@ -105,13 +109,16 @@
// form reset icon on ports tab // form reset icon on ports tab
$('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&' + $('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&' +
$('#ports_form') $('#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('<input name="q" type="hidden" value="' + $('#nq').val() + '"/>')
.add('<input name="uuid" type="hidden" value="' + $('#uuid').val() + '"/>')
.serialize()); .serialize());
[% ELSIF tab.tag == 'netmap' %] [% ELSIF tab.tag == 'netmap' %]
// form reset icon on netmap tab // form reset icon on netmap tab
$('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&' + $('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&'
$('#netmap_form').find('input[name="q"]').serialize()); + '&q=' + $('#nq').val()
+ '&uuid=' + $('#uuid').val());
[% END %] [% END %]
do_search(event, '[% tab.tag %]'); do_search(event, '[% tab.tag %]');

View File

@@ -116,7 +116,8 @@
</ul> </ul>
<form class="navbar-search pull-left" method="get" action="[% uri_for('/search') %]"> <form class="navbar-search pull-left" method="get" action="[% uri_for('/search') %]">
<input placeholder="Find Anything" class="search-query span3" <input placeholder="Find Anything" class="search-query span3"
id="nq" name="q" type="text" autocomplete="off"/> id="nq" name="q" value="[% params.q %]" type="text" autocomplete="off"/>
<input id="uuid" name="uuid" value="[% params.uuid %]" type="hidden"/>
<div class="btn-group nd_navbar-search-group"> <div class="btn-group nd_navbar-search-group">
<button class="btn btn-inverse nd_navbar-search-icon"> <button class="btn btn-inverse nd_navbar-search-icon">
<span style="font-size: 18px;"> <span style="font-size: 18px;">