diff --git a/Netdisco/Changes b/Netdisco/Changes index 035774b7..c4b7b99c 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -19,6 +19,9 @@ * Port MAC query now only returns distinct MAC's * Keep a hint to SNMP community if new style snmp_auth config is in use * [#43] Add doc note about PostgreSQL MD5 authN + * [#49] Allow device port searching with preference for port/name/vlan. + This is to support some devices (HP?) which have plain numbers for port names + and Netdisco defaults to assuming this is a VLAN number (R. Kerr) [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 63574069..8f08c336 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -146,6 +146,7 @@ hook 'before_template' => sub { my $self_uri = uri_for(request->path, scalar params); $self_uri->query_param_delete('q'); $self_uri->query_param_delete('f'); + $self_uri->query_param_delete('prefer'); $tokens->{self_options} = $self_uri->query_form_hash; }; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm index ccff9d5b..d41cd194 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm @@ -12,6 +12,9 @@ register_device_tab({ tag => 'ports', label => 'Ports', provides_csv => 1 }); # device ports with a description (er, name) matching get '/ajax/content/device/ports' => require_login sub { my $q = param('q'); + my $prefer = param('prefer'); + $prefer = '' + unless defined $prefer and $prefer =~ m/^(?:port|name|vlan)$/; my $device = schema('netdisco')->resultset('Device') ->search_for_device($q) or send_error('Bad device', 400); @@ -20,7 +23,7 @@ get '/ajax/content/device/ports' => require_login sub { # refine by ports if requested my $f = param('f'); if ($f) { - if ($f =~ m/^\d+$/) { + if (($prefer eq 'vlan') or not $prefer and $f =~ m/^\d+$/) { if (param('invert')) { $set = $set->search({ 'me.vlan' => { '!=' => $f }, @@ -57,7 +60,9 @@ get '/ajax/content/device/ports' => require_login sub { $f = { '!=' => $f }; } - if ($set->search({'me.port' => $f})->count) { + if (($prefer eq 'port') or not $prefer and + $set->search({'me.port' => $f})->count) { + $set = $set->search({'me.port' => $f}); } else { diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index dbb223d7..44b3302d 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -526,12 +526,23 @@ td > form.nd_inline-form { } /* sidebar submit button width and spacing */ -.nd_sidebar button { + +/* when the sidebar submit button DOES NOT HAVE a dropdown */ +.nd_sidebar button:not(.nd_sidebar-btn-drop, .nd_sidebar-btn-drop-drop ) { margin-top: 9px; margin-left: -3px; width: 165px; } +/* when the sidebar submit button HAS a dropdown */ +.nd_sidebar-btn-drop { + width: 138px; +} +.nd_sidebar-btn-drop-drop { + height: 28px; + width: 28px; +} + /* little icon inside of search input fields */ .nd_field-clear-icon, .nd_field-copy-icon { position: absolute; diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index 47294d7e..d253d150 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -67,7 +67,7 @@ [% END %] + self_options) %]&q=[% params.q | uri %]&f=[% row.port | uri %]&prefer=port"> [% row.port | html_entity %] [% END %] diff --git a/Netdisco/share/views/js/device.js b/Netdisco/share/views/js/device.js index 072065c5..dfd60002 100644 --- a/Netdisco/share/views/js/device.js +++ b/Netdisco/share/views/js/device.js @@ -29,6 +29,7 @@ $(document).ready(function() { var tab = '[% tab.tag %]' var target = '#' + tab + '_pane'; + var portfilter = $('#ports_form').find("input[name=f]"); // sidebar form fields should change colour and have trash/copy icon form_inputs.each(function() {device_form_state($(this))}); @@ -45,14 +46,25 @@ .toggleClass('icon-chevron-up icon-chevron-down'); }); + // if the user edits the filter box, revert to automagical search + $('#ports_form').on('input', "input[name=f]", function() { + $('#nd_ports-form-prefer-field').attr('value', ''); + }); + // handler for trashcan icon in port filter box - var portfilter = $('#ports_form').find("input[name=f]"); $('.nd_field-clear-icon').click(function() { portfilter.val(''); $('#ports_form').trigger('submit'); device_form_state(portfilter); // will hide copy icons }); + // allow port filter to have a preference for port/name/vlan + $('#ports_form').on('click', '.nd_device-port-submit-prefer', function() { + event.preventDefault(); + $('#nd_ports-form-prefer-field').attr('value', $(this).data('prefer')); + $(this).parents('form').submit(); + }); + // clickable device port names can simply resubmit AJAX rather than // fetch the whole page again. $('#ports_pane').on('click', '.nd_this-port-only', function(event) { @@ -61,8 +73,11 @@ var port = $(this).text(); port = $.trim(port); portfilter.val(port); - $('.nd_field-clear-icon').show(); + + // make sure we're preferring a port filter + $('#nd_ports-form-prefer-field').attr('value', 'port'); + $('#ports_form').trigger('submit'); device_form_state(portfilter); // will hide copy icons }); diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index 553cf649..bf15a56e 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -1,5 +1,6 @@ +
- +
+ + + +
+