From 77690513b8dcdb2bc4082f4b6c7b6a9e8c0a0405 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 10 Sep 2013 23:26:08 +0100 Subject: [PATCH] much better wildcard/partial port search This does not require silly quoting. It adds a "partial" checkbox in the ports sidebar. If this is ticked, simple wildcarding * and ? are also supported. --- .../lib/App/Netdisco/Web/Plugin/Device/Ports.pm | 13 ++++++++++--- Netdisco/share/public/css/netdisco.css | 17 +++++++++++++++++ Netdisco/share/views/sidebar/device/ports.tt | 9 +++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm index 89bf0a23..e7204188 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm @@ -31,9 +31,16 @@ ajax '/ajax/content/device/ports' => require_login sub { return unless $set->count; } else { - $f =~ s/\*/%/g if index($f, '*') >= 0; - $f =~ s/\?/_/g if index($f, '?') >= 0; - $f = { '-ilike' => $f }; + if (param('partial')) { + # change wildcard chars to SQL + $f =~ s/\*/%/g; + $f =~ s/\?/_/g; + # set wilcards at param boundaries + $f =~ s/^\%*/%/; + $f =~ s/\%*$/%/; + # enable ILIKE op + $f = { '-ilike' => $f }; + } if ($set->search({'me.port' => $f})->count) { $set = $set->search({'me.port' => $f}); diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index e43de784..84d8da40 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -385,6 +385,23 @@ td > form.nd_inline-form { cursor: pointer; } +/* fixup for prepended partial port name checkbox in sidebar */ +.nd_port-partial-checkbox { + width: 136px; + padding: 0px 0px 0px 11px !important; + cursor: pointer; +} + +.nd_port-partial-label { + padding: 0px !important; +} + +.nd_port-partial { + margin-left: 5px !important; + margin-top: -5px; + margin-bottom: 5px !important; +} + /* fixup for prepended checkbox in sidebar */ .nd_sidebar .input-prepend { margin-left: -2px; diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index 9af7a4c5..46022683 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -7,6 +7,15 @@ +
+ + +