From 10a6e3356105f46927e9917405a39dd7e75a6dac Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 9 Apr 2014 21:22:56 +0100 Subject: [PATCH] Add FRU filter option to Module Inventory Report --- Netdisco/Changes | 6 ++++ .../Web/Plugin/Report/ModuleInventory.pm | 30 +++++++++---------- Netdisco/lib/App/Netdisco/Web/Report.pm | 8 +++++ .../views/sidebar/report/moduleinventory.tt | 9 ++++++ 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 9045c4d5..637198c6 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,3 +1,9 @@ +2.025002 - + + [ENHANCEMENTS] + + * Add FRU filter option to Module Inventory Report + 2.025001 - 2014-04-08 [NEW FEATURES] diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm index 4e955512..4d07ef43 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm @@ -16,16 +16,6 @@ register_report( ); hook 'before' => sub { - - # view settings - var('module_options' => [ - { name => 'matchall', - label => 'Match All Options', - default => 'on' - }, - ] - ); - return unless ( request->path eq uri_for('/report/moduleinventory')->path @@ -33,13 +23,20 @@ hook 'before' => sub { uri_for('/ajax/content/report/moduleinventory')->path ) == 0 ); + # view settings + var('module_options' => [ + { name => 'fruonly', + label => 'FRU Only', + default => 'on' + }, + { name => 'matchall', + label => 'Match All Options', + default => 'on' + }, + ] + ); + params->{'limit'} ||= 1024; - - foreach my $col ( @{ var('module_options') } ) { - next unless $col->{default} eq 'on'; - params->{ $col->{name} } = 'checked'; - } - }; hook 'before_template' => sub { @@ -69,6 +66,7 @@ get '/ajax/content/report/moduleinventory' => require_login sub { qw/device description name type model serial class/; my $rs = schema('netdisco')->resultset('DeviceModule'); + $rs = $rs->search({-bool => 'fru'}) if param('fruonly'); if ($has_opt) { diff --git a/Netdisco/lib/App/Netdisco/Web/Report.pm b/Netdisco/lib/App/Netdisco/Web/Report.pm index 15ddf2ba..25d18515 100644 --- a/Netdisco/lib/App/Netdisco/Web/Report.pm +++ b/Netdisco/lib/App/Netdisco/Web/Report.pm @@ -17,6 +17,14 @@ get '/report/*' => require_login sub { elsif ( $tag eq 'moduleinventory' ) { $class_list = [ schema('netdisco')->resultset('DeviceModule') ->get_distinct_col('class') ]; + + # this is a bit fragile... three params currently + if (3 == scalar keys params()) { + foreach my $col ( @{ var('module_options') } ) { + next unless $col->{default} eq 'on'; + params->{ $col->{name} } = 'checked'; + } + } } elsif ( $tag eq 'portssid' ) { $ssid_list = [ schema('netdisco')->resultset('DevicePortSsid') diff --git a/Netdisco/share/views/sidebar/report/moduleinventory.tt b/Netdisco/share/views/sidebar/report/moduleinventory.tt index 5156a086..6399580f 100644 --- a/Netdisco/share/views/sidebar/report/moduleinventory.tt +++ b/Netdisco/share/views/sidebar/report/moduleinventory.tt @@ -59,6 +59,15 @@ [% END %] +
+ + +