diff --git a/Netdisco/Changes b/Netdisco/Changes index a2b9971c..a861e0aa 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -16,8 +16,10 @@ [BUG FIXES] - * Workaround for https://rt.cpan.org/Ticket/Display.html?id=93244 (ECR) - * Fix for crash when selecting Last Change column in device ports view (ECR) + * Workaround for https://rt.cpan.org/Ticket/Display.html?id=93244 + * Fix for crash when selecting Last Change column in device ports view + * Fix IP Inventory Report to work without daterange + * Fix "list IPs never seen" to work without daterange in IP Inventory Report 2.023002 - 2014-02-17 diff --git a/Netdisco/lib/App/Netdisco/Web.pm b/Netdisco/lib/App/Netdisco/Web.pm index f07b988d..e04aa6b7 100644 --- a/Netdisco/lib/App/Netdisco/Web.pm +++ b/Netdisco/lib/App/Netdisco/Web.pm @@ -10,6 +10,7 @@ use Socket6 (); # to ensure dependency is met use HTML::Entities (); # to ensure dependency is met use URI::QueryParam (); # part of URI, to add helper methods use Path::Class 'dir'; +use App::Netdisco::Util::Web 'interval_to_daterange'; use App::Netdisco::Web::AuthN; use App::Netdisco::Web::Static; @@ -62,6 +63,9 @@ hook 'before_template' => sub { # access to logged in user's roles $tokens->{user_has_role} = sub { user_has_role(@_) }; + # create date ranges from within templates + $tokens->{to_daterange} = sub { interval_to_daterange(@_) }; + # fix Plugin Template Variables to be only path+query $tokens->{$_} = $tokens->{$_}->path_query for qw/search_node search_device device_ports/; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm index db826538..a7ad1216 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm @@ -15,24 +15,6 @@ register_report( } ); -# Following two Perl Core 5.10+ -use Time::Piece; -use Time::Seconds; - -hook 'before' => sub { - - return - unless ( request->path eq uri_for('/report/ipinventory')->path - or index( request->path, uri_for('/ajax/content/report/ipinventory')->path ) - == 0 ); - - my $start = Time::Piece->new - ONE_DAY * 29; - - params->{'limit'} ||= 256; - params->{'daterange'} - ||= $start->ymd . " to " . Time::Piece->new->ymd; -}; - get '/ajax/content/report/ipinventory' => require_login sub { # Default to something simple with no results to prevent @@ -53,7 +35,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { # 'never' is true. TODO: Need better input validation, both JS and # server-side to provide user feedback $limit = 8192 if $limit > 8192; - $order = $order eq 'IP' ? \'ip ASC' : \'age DESC'; + $order = $order eq 'IP' ? {-asc => 'ip'} : [{-desc => 'age'}, {-asc => 'ip'}]; my $rs1 = schema('netdisco')->resultset('DeviceIp')->search( undef, @@ -114,8 +96,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { my $rs_sub = $rs_union->search( { ip => { '<<' => $subnet->cidr } }, - { order_by => [qw( ip time_last )], - select => [ + { select => [ \'DISTINCT ON (ip) ip', 'dns', \qq/date_trunc('second', time_last) AS time_last/, @@ -148,10 +129,16 @@ get '/ajax/content/report/ipinventory' => require_login sub { } else { $rs = $rs_union->search( - { -and => [ - time_last => { '>=', $start }, - time_last => { '<=', $end }, - ] + { -or => [ + -and => [ + time_first => undef, + time_last => undef, + ], + -and => [ + time_last => { '>=', $start }, + time_last => { '<=', $end }, + ], + ], }, { from => { me => $rs_sub }, } ); diff --git a/Netdisco/share/views/sidebar/report/ipinventory.tt b/Netdisco/share/views/sidebar/report/ipinventory.tt index 6cd903e0..fae0d22d 100644 --- a/Netdisco/share/views/sidebar/report/ipinventory.tt +++ b/Netdisco/share/views/sidebar/report/ipinventory.tt @@ -21,7 +21,8 @@