From f62646bbe43619e3aee34af30aec563f28c7b9ab Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 17 Aug 2014 23:41:50 +0100 Subject: [PATCH] fix bug in selection of Port Free state - was accidentally applying date filter to all ports rather than just those not up --- .../App/Netdisco/Web/Plugin/Device/Ports.pm | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm index 39eaca63..dfae0a0f 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm @@ -97,42 +97,28 @@ get '/ajax/content/device/ports' => require_login sub { : () ); + # user deseleted all port states. that means no ports. return unless scalar keys %port_state; - if ( exists $port_state{free} ) { - my $age_num = ( param('age_num') || 3 ); - my $age_unit = ( param('age_unit') || 'months' ); - my $interval = "$age_num $age_unit"; - if ( scalar keys %port_state == 1 ) { - $rs = $rs->search( - { 'me.up' => { '!=' => 'up' }, }, - { where => \[ - "age(now(), to_timestamp(extract(epoch from me.device_last_discover) " - . "- (me.device_uptime - me.lastchange)/100)) " - . "> ?::interval", - [ {} => $interval ] - ] - } - ); - } - else { - $rs = $rs->search( - {}, - { where => \[ - "age(now(), to_timestamp(extract(epoch from me.device_last_discover) " - . "- (me.device_uptime - me.lastchange)/100)) " - . "> ?::interval", - [ {} => $interval ] - ] - } - ); - } - delete $port_state{free}; - } - - if ( scalar keys %port_state < 3 ) { + # if four keys, that's shorthand for everything. + # so only add these filters if user deselected something. + if (scalar keys %port_state != 4) { my @combi = (); + if ( exists $port_state{free} ) { + my $age_num = ( param('age_num') || 3 ); + my $age_unit = ( param('age_unit') || 'months' ); + my $interval = "$age_num $age_unit"; + + push @combi, { -and => [ + { 'me.up_admin' => 'up', 'me.up' => { '!=' => 'up' } }, + \[ "age(now(), to_timestamp(extract(epoch from me.device_last_discover) " + . "- (me.device_uptime - me.lastchange)/100)) " + . "> ?::interval", + [ {} => $interval ] ], + ]}; + } + push @combi, { 'me.up' => 'up' } if exists $port_state{up}; push @combi, { 'me.up_admin' => 'up', 'me.up' => { '!=' => 'up' } }