implement smart search tab selection, and Node search
This commit is contained in:
@@ -48,6 +48,11 @@ __PACKAGE__->set_primary_key("mac", "switch", "port");
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sGGyKEfUkoIFVtmj1wnH7A
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device',
|
||||
{ 'foreign.ip' => 'self.switch' } );
|
||||
__PACKAGE__->belongs_to( device_port => 'Netdisco::DB::Result::DevicePort',
|
||||
{ 'foreign.ip' => 'self.switch', 'foreign.port' => 'self.port' } );
|
||||
__PACKAGE__->has_many( ips => 'Netdisco::DB::Result::NodeIp',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
|
||||
@@ -39,6 +39,49 @@ __PACKAGE__->set_primary_key("mac", "ip");
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9+CuvuVWH88WxAf6IBij8g
|
||||
|
||||
__PACKAGE__->has_many( nodeips => 'Netdisco::DB::Result::NodeIp',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
__PACKAGE__->has_many( nodes => 'Netdisco::DB::Result::Node',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
sub tidy_nodeips {
|
||||
my ($row, $archive) = @_;
|
||||
|
||||
return $row->nodeips(
|
||||
{
|
||||
ip => { '!=' => $row->ip },
|
||||
($archive ? () : (active => 1)),
|
||||
},
|
||||
{
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
columns => [qw/ mac ip dns active /],
|
||||
'+select' => [
|
||||
\"to_char(time_first, 'YYYY-MM-DD HH24:MI')",
|
||||
\"to_char(time_last, 'YYYY-MM-DD HH24:MI')",
|
||||
],
|
||||
'+as' => [qw/ time_first time_last /],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
sub tidy_nodes {
|
||||
my ($row, $archive) = @_;
|
||||
|
||||
return $row->nodes(
|
||||
{
|
||||
($archive ? () : (active => 1)),
|
||||
},
|
||||
{
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
columns => [qw/ mac switch port oui active device.dns /],
|
||||
'+select' => [
|
||||
\"to_char(time_first, 'YYYY-MM-DD HH24:MI')",
|
||||
\"to_char(time_last, 'YYYY-MM-DD HH24:MI')",
|
||||
],
|
||||
'+as' => [qw/ time_first time_last /],
|
||||
join => 'device',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
|
||||
@@ -11,10 +11,10 @@ sub carrying_vlan {
|
||||
'port_vlans.vlan' => $vlan,
|
||||
},
|
||||
{
|
||||
join => [qw/ port_vlans vlans /],
|
||||
prefetch => 'vlans',
|
||||
order_by => [qw/ me.dns me.ip /],
|
||||
columns => [qw/ me.ip me.dns me.model me.os me.vendor /],
|
||||
join => 'port_vlans',
|
||||
prefetch => 'vlans',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
25
Netdisco/lib/Netdisco/DB/ResultSet/NodeIp.pm
Normal file
25
Netdisco/lib/Netdisco/DB/ResultSet/NodeIp.pm
Normal file
@@ -0,0 +1,25 @@
|
||||
package Netdisco::DB::ResultSet::NodeIp;
|
||||
use base 'DBIx::Class::ResultSet';
|
||||
|
||||
sub by_ip {
|
||||
my ($set, $ip, $archive) = @_;
|
||||
return $set unless $ip;
|
||||
|
||||
return $set->search(
|
||||
{
|
||||
ip => $ip,
|
||||
($archive ? () : (active => 1)),
|
||||
},
|
||||
{
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
columns => [qw/ mac ip dns active /],
|
||||
'+select' => [
|
||||
\"to_char(time_first, 'YYYY-MM-DD HH24:MI')",
|
||||
\"to_char(time_last, 'YYYY-MM-DD HH24:MI')",
|
||||
],
|
||||
'+as' => [qw/ time_first time_last /],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user