diff --git a/Netdisco/Changes b/Netdisco/Changes index 6468d7f5..7f107709 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -2,7 +2,11 @@ [NEW FEATURES] - * [#86] Use Vendor abbrevs to enhance node display in device port view + * [#86] Use Vendor abbrevs to enhance node display in device port view + + [ENHANCEMENTS] + + * [#69] Add search by layers to device search 2.022000 - 2014-01-26 diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm index f0c8bd69..2c263710 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -204,6 +204,23 @@ sub search_by_field { || NetAddr::IP::Lite->new('255.255.255.255') ); } + # For Search on Layers + my @layer_search = ( '_', '_', '_', '_', '_', '_', '_' ); + # @layer_search is computer indexed, left->right + my $layers = $p->{layers}; + if ( defined $layers && ref $layers ) { + foreach my $layer (@$layers) { + next unless defined $layer and length($layer); + next if ( $layer < 1 || $layer > 7 ); + $layer_search[ $layer - 1 ] = 1; + } + } + elsif ( defined $layers ) { + $layer_search[ $layers - 1 ] = 1; + } + # the database field is in order 87654321 + my $layer_string = join( '', reverse @layer_search ); + return $rs ->search_rs({}, $attrs) ->search({ @@ -214,6 +231,8 @@ sub search_by_field { { '-ilike' => "\%$p->{location}\%" }) : ()), ($p->{description} ? ('me.description' => { '-ilike' => "\%$p->{description}\%" }) : ()), + ($p->{layers} ? ('me.layers' => + { '-ilike' => "\%$layer_string" }) : ()), ($p->{model} ? ('me.model' => { '-in' => $p->{model} }) : ()), diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm index 98dc6561..596b83dd 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm @@ -15,7 +15,7 @@ my $headers = ['Device','Contact','Location','System Name','Model','OS Version', # device with various properties or a default match-all get '/ajax/content/search/device' => require_login sub { my $has_opt = List::MoreUtils::any {param($_)} - qw/name location dns ip description model os_ver vendor/; + qw/name location dns ip description model os_ver vendor layers/; my $set; if ($has_opt) { diff --git a/Netdisco/share/views/sidebar/search/device.tt b/Netdisco/share/views/sidebar/search/device.tt index a78b5f55..97722f72 100644 --- a/Netdisco/share/views/sidebar/search/device.tt +++ b/Netdisco/share/views/sidebar/search/device.tt @@ -68,6 +68,15 @@ [% END %] +
+ +