remove trivial search helpers
This commit is contained in:
@@ -66,187 +66,4 @@ sub with_vlan_count {
|
||||
});
|
||||
}
|
||||
|
||||
=head2 search_by_mac( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_mac({mac => '00:11:22:33:44:55'});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
DevicePort table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<mac> with
|
||||
the value to search for.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by the port's Device IP and Port fields.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_mac {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "mac address required for search_by_mac\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{mac};
|
||||
|
||||
$cond->{'me.mac'} = delete $cond->{mac};
|
||||
$attrs ||= {};
|
||||
|
||||
return $rs
|
||||
->search_rs({}, {
|
||||
# order_by => {'-desc' => 'me.creation'},
|
||||
order_by => [qw/ me.ip me.port /],
|
||||
})
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head2 search_by_ip( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_ip({ip => '192.0.2.1'});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
DevicePort table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<IP> with the IPv4
|
||||
or IPv6 value to search for in plain string form.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_ip {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "ip address required for search_by_ip\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{ip};
|
||||
|
||||
$cond->{'me.ip'} = delete $cond->{ip};
|
||||
$attrs ||= {};
|
||||
|
||||
return $rs->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head2 search_by_name( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_name({name => 'sniffer'});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
DevicePort table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<name> with the
|
||||
value to search for. The value may optionally include SQL wildcard characters.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by the port's Device IP and Port fields.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_name {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "name required for search_by_name\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{name};
|
||||
|
||||
$cond->{'me.name'} = { '-ilike' => delete $cond->{name} };
|
||||
$attrs ||= {};
|
||||
|
||||
return $rs
|
||||
->search_rs({}, {
|
||||
order_by => [qw/ me.ip me.port /],
|
||||
})
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head2 search_by_vlan( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_vlan({vlan => 123});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
DevicePort table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<vlan> with the
|
||||
value to search for.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by the port's Device IP and Port fields.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_vlan {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "vlan number required for search_by_vlan\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{vlan};
|
||||
|
||||
$cond->{'me.vlan'} = delete $cond->{vlan};
|
||||
$attrs ||= {};
|
||||
|
||||
return $rs
|
||||
->search_rs({}, {
|
||||
order_by => [qw/ me.ip me.port /],
|
||||
})
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head2 search_by_port( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_port({port => 'FastEthernet0/23'});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
DevicePort table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<port> with the
|
||||
value to search for.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by the port's Device IP.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_port {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "port required for search_by_port\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{port};
|
||||
|
||||
$cond->{'me.port'} = delete $cond->{port};
|
||||
$attrs ||= {};
|
||||
|
||||
return $rs
|
||||
->search_rs({}, {
|
||||
order_by => [qw/ me.ip /],
|
||||
})
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -58,7 +58,7 @@ ajax '/ajax/content/device/addresses' => sub {
|
||||
return unless $ip;
|
||||
|
||||
my $set = schema('netdisco')->resultset('DeviceIp')
|
||||
->search({ip => $ip}, { order_by => 'alias' });
|
||||
->search({ip => $ip}, {order_by => 'alias'});
|
||||
return unless $set->count;
|
||||
|
||||
content_type('text/html');
|
||||
@@ -73,21 +73,21 @@ ajax '/ajax/content/device/ports' => sub {
|
||||
return unless $ip;
|
||||
|
||||
my $set = schema('netdisco')->resultset('DevicePort')
|
||||
->search_by_ip({ip => $ip});
|
||||
->search({'me.ip' => $ip});
|
||||
|
||||
# refine by ports if requested
|
||||
my $q = param('f');
|
||||
if ($q) {
|
||||
if ($q =~ m/^\d+$/) {
|
||||
$set = $set->search_by_vlan({vlan => $q});
|
||||
$set = $set->search({'me.vlan' => $q});
|
||||
return unless $set->count;
|
||||
}
|
||||
else {
|
||||
if ($set->search_by_port({port => $q})->count) {
|
||||
$set = $set->search_by_port({port => $q});
|
||||
if ($set->search({'me.port' => $q})->count) {
|
||||
$set = $set->search({'me.port' => $q});
|
||||
}
|
||||
else {
|
||||
$set = $set->search_by_name({name => $q});
|
||||
$set = $set->search({'me.name' => $q});
|
||||
return unless $set->count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ ajax '/ajax/content/search/node' => sub {
|
||||
->search_by_mac({mac => $mac->as_IEEE, @active});
|
||||
|
||||
my $ports = schema('netdisco')->resultset('DevicePort')
|
||||
->search_by_mac({mac => $mac->as_IEEE});
|
||||
->search({mac => $mac->as_IEEE});
|
||||
|
||||
return unless $sightings->count
|
||||
or $ips->count
|
||||
@@ -161,10 +161,10 @@ ajax '/ajax/content/search/port' => sub {
|
||||
my $set;
|
||||
|
||||
if ($q =~ m/^\d+$/) {
|
||||
$set = schema('netdisco')->resultset('DevicePort')->search_by_vlan({vlan => $q});
|
||||
$set = schema('netdisco')->resultset('DevicePort')->search({vlan => $q});
|
||||
}
|
||||
else {
|
||||
$set = schema('netdisco')->resultset('DevicePort')->search_by_name({name => $q});
|
||||
$set = schema('netdisco')->resultset('DevicePort')->search({name => $q});
|
||||
}
|
||||
return unless $set->count;
|
||||
|
||||
@@ -213,7 +213,7 @@ get '/search' => sub {
|
||||
params->{'tab'} = 'device';
|
||||
}
|
||||
elsif ($s->resultset('DevicePort')
|
||||
->search_by_name({name => "\%$q\%"})->count) {
|
||||
->search({name => "\%$q\%"})->count) {
|
||||
params->{'tab'} = 'port';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user