diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm index c31ee518..04ac0966 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm @@ -3,6 +3,7 @@ package App::Netdisco::Web::Plugin::Report::ModuleInventory; use Dancer ':syntax'; use Dancer::Plugin::DBIC; use Dancer::Plugin::Auth::Extensible; +use App::Netdisco::Util::ExpandParams 'expand_hash'; use App::Netdisco::Web::Plugin; use List::MoreUtils (); @@ -58,16 +59,59 @@ hook 'before_template' => sub { } }; +get '/ajax/content/report/moduleinventory/data' => require_login sub { + + my $rs = schema('netdisco')->resultset('DeviceModule'); + $rs = $rs->search( { -bool => 'fru' } ) if param('fruonly'); + + if ( param('device') ) { + my @ips = schema('netdisco')->resultset('Device') + ->search_fuzzy( param('device') )->get_column('ip')->all; + + params->{'ips'} = \@ips; + } + + $rs = $rs->search_by_field( scalar params )->columns( + [ 'ip', 'description', 'name', 'class', + 'type', 'serial', 'hw_ver', 'fw_ver', + 'sw_ver', 'model' + ] + )->search( + {}, + { '+columns' => [qw/ device.dns device.name /], + join => 'device', + collapse => 1, + } + ); + + my $exp_params = expand_hash( scalar params ); + + my $recordsTotal = $rs->count; + + my @data = $rs->get_datatables_data($exp_params)->hri->all; + + my $recordsFiltered = $rs->get_datatables_filtered_count($exp_params); + + content_type 'application/json'; + return to_json( + { draw => int( param('draw') ), + recordsTotal => int($recordsTotal), + recordsFiltered => int($recordsFiltered), + data => \@data, + } + ); +}; + get '/ajax/content/report/moduleinventory' => require_login sub { my $has_opt = List::MoreUtils::any { param($_) } qw/device description name type model serial class/; my $rs = schema('netdisco')->resultset('DeviceModule'); - $rs = $rs->search({-bool => 'fru'}) if param('fruonly'); + $rs = $rs->search( { -bool => 'fru' } ) if param('fruonly'); my @results; - if ($has_opt) { + if ( $has_opt && !request->is_ajax ) { if ( param('device') ) { my @ips = schema('netdisco')->resultset('Device') @@ -84,23 +128,25 @@ get '/ajax/content/report/moduleinventory' => require_login sub { { '+columns' => [qw/ device.dns device.name /], join => 'device', collapse => 1, - })->hri->all; - } + } + )->hri->all; + + return unless scalar @results; + } else { @results = $rs->search( - {class => { '!=', undef }}, + { class => { '!=', undef } }, { select => [ 'class', { count => 'class' } ], as => [qw/ class count /], group_by => [qw/ class /] } )->order_by( { -desc => 'count' } )->hri->all; - + + return unless scalar @results; } - return unless scalar @results; - if ( request->is_ajax ) { - my $json = to_json (\@results); + my $json = to_json( \@results ); template 'ajax/report/moduleinventory.tt', { results => $json, opt => $has_opt }, { layout => undef }; diff --git a/Netdisco/share/views/ajax/report/moduleinventory.tt b/Netdisco/share/views/ajax/report/moduleinventory.tt index a5453ff3..b149b93a 100644 --- a/Netdisco/share/views/ajax/report/moduleinventory.tt +++ b/Netdisco/share/views/ajax/report/moduleinventory.tt @@ -1,3 +1,4 @@ +[% USE url %] [% IF opt %] @@ -14,21 +15,6 @@ - - - - - - - - - - - - - - -
FW Version
DeviceDescriptionNameClassTypeModelSerialHW VersionSW VersionFW Version
[% ELSE %] @@ -44,10 +30,16 @@