« blib/lib/App/Netdisco/Web/Plugin/Report/DeviceDnsMismatch.pm
↑ Summary
blib/lib/App/Netdisco/Web/Plugin/Report/DuplexMismatch.pm »
| 1 | package App::Netdisco::Web::Plugin::Report::DevicePoeStatus; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use Dancer::Plugin::DBIC; | ||
| 5 | use Dancer::Plugin::Auth::Extensible; | ||
| 6 | use App::Netdisco::Util::ExpandParams 'expand_hash'; | ||
| 7 | |||
| 8 | use App::Netdisco::Web::Plugin; | ||
| 9 | |||
| 10 | register_report( | ||
| 11 | { category => 'Device', | ||
| 12 | tag => 'devicepoestatus', | ||
| 13 | label => 'Power over Ethernet (PoE) Status', | ||
| 14 | provides_csv => 1, | ||
| 15 | api_endpoint => 1, | ||
| 16 | } | ||
| 17 | ); | ||
| 18 | |||
| 19 | get '/ajax/content/report/devicepoestatus/data' => require_login sub { | ||
| 20 | send_error( 'Missing parameter', 400 ) | ||
| 21 | unless ( param('draw') && param('draw') =~ /\d+/ ); | ||
| 22 | |||
| 23 | my $rs = schema(vars->{'tenant'})->resultset('Virtual::DevicePoeStatus'); | ||
| 24 | |||
| 25 | my $exp_params = expand_hash( scalar params ); | ||
| 26 | my $recordsTotal = $rs->count; | ||
| 27 | my @data = $rs->get_datatables_data($exp_params)->hri->all; | ||
| 28 | my $recordsFiltered = $rs->get_datatables_filtered_count($exp_params); | ||
| 29 | |||
| 30 | content_type 'application/json'; | ||
| 31 | return to_json( | ||
| 32 | { draw => int( param('draw') ), | ||
| 33 | recordsTotal => int($recordsTotal), | ||
| 34 | recordsFiltered => int($recordsFiltered), | ||
| 35 | data => \@data, | ||
| 36 | } | ||
| 37 | ); | ||
| 38 | }; | ||
| 39 | |||
| 40 | get '/ajax/content/report/devicepoestatus' => require_login sub { | ||
| 41 | |||
| 42 | if ( request->is_ajax ) { | ||
| 43 | template 'ajax/report/devicepoestatus.tt', {}, { layout => 'noop' }; | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | my @results | ||
| 47 | = schema(vars->{'tenant'})->resultset('Virtual::DevicePoeStatus') | ||
| 48 | ->hri->all; | ||
| 49 | |||
| 50 | return unless scalar @results; | ||
| 51 | |||
| 52 | header( 'Content-Type' => 'text/comma-separated-values' ); | ||
| 53 | template 'ajax/report/devicepoestatus_csv.tt', | ||
| 54 | { results => \@results, }, { layout => 'noop' }; | ||
| 55 | } | ||
| 56 | }; | ||
| 57 | |||
| 58 | 1; |