« blib/lib/App/Netdisco/Web/Plugin/Report/DeviceAddrNoDNS.pm
↑ Summary
blib/lib/App/Netdisco/Web/Plugin/Report/DeviceDnsMismatch.pm »
| 1 | package App::Netdisco::Web::Plugin::Report::DeviceByLocation; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use Dancer::Plugin::DBIC; | ||
| 5 | use Dancer::Plugin::Auth::Extensible; | ||
| 6 | |||
| 7 | use App::Netdisco::Web::Plugin; | ||
| 8 | |||
| 9 | register_report( | ||
| 10 | { category => 'Device', | ||
| 11 | tag => 'devicebylocation', | ||
| 12 | label => 'Inventory by Location', | ||
| 13 | provides_csv => 1, | ||
| 14 | api_endpoint => 1, | ||
| 15 | } | ||
| 16 | ); | ||
| 17 | |||
| 18 | get '/ajax/content/report/devicebylocation' => require_login sub { | ||
| 19 | my @results | ||
| 20 | = schema(vars->{'tenant'})->resultset('Device') | ||
| 21 | ->columns( [qw/ ip dns name location vendor model /] ) | ||
| 22 | ->order_by( [qw/ location name ip vendor model /] )->hri->all; | ||
| 23 | |||
| 24 | return unless scalar @results; | ||
| 25 | |||
| 26 | if ( request->is_ajax ) { | ||
| 27 | my $json = to_json( \@results ); | ||
| 28 | template 'ajax/report/devicebylocation.tt', { results => $json }, { layout => 'noop' }; | ||
| 29 | } | ||
| 30 | else { | ||
| 31 | header( 'Content-Type' => 'text/comma-separated-values' ); | ||
| 32 | template 'ajax/report/devicebylocation_csv.tt', | ||
| 33 | { results => \@results }, { layout => 'noop' }; | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | 1; |