[#69] Add search by layers to device search

This commit is contained in:
Eric A. Miller
2014-01-26 10:44:27 -05:00
parent d6eafba762
commit 62cf1561e6
4 changed files with 34 additions and 2 deletions

View File

@@ -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} }) : ()),

View File

@@ -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) {