« blib/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm
↑ Summary
blib/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm »
| 1 | package App::Netdisco::Web::Plugin::AdminTask::UserLog; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use Dancer::Plugin::Ajax; | ||
| 5 | use Dancer::Plugin::DBIC; | ||
| 6 | use Dancer::Plugin::Auth::Extensible; | ||
| 7 | use App::Netdisco::Util::ExpandParams 'expand_hash'; | ||
| 8 | |||
| 9 | use App::Netdisco::Web::Plugin; | ||
| 10 | |||
| 11 | register_admin_task( | ||
| 12 | { tag => 'userlog', | ||
| 13 | label => 'User Activity Log', | ||
| 14 | } | ||
| 15 | ); | ||
| 16 | |||
| 17 | ajax '/ajax/control/admin/userlog/data' => require_role admin => sub { | ||
| 18 | send_error( 'Missing parameter', 400 ) | ||
| 19 | unless ( param('draw') && param('draw') =~ /\d+/ ); | ||
| 20 | |||
| 21 | my $rs = schema(vars->{'tenant'})->resultset('UserLog'); | ||
| 22 | |||
| 23 | my $exp_params = expand_hash( scalar params ); | ||
| 24 | |||
| 25 | my $recordsTotal = $rs->count; | ||
| 26 | |||
| 27 | my @data = $rs->get_datatables_data($exp_params)->hri->all; | ||
| 28 | |||
| 29 | my $recordsFiltered = $rs->get_datatables_filtered_count($exp_params); | ||
| 30 | |||
| 31 | content_type 'application/json'; | ||
| 32 | return to_json( | ||
| 33 | { draw => int( param('draw') ), | ||
| 34 | recordsTotal => int($recordsTotal), | ||
| 35 | recordsFiltered => int($recordsFiltered), | ||
| 36 | data => \@data, | ||
| 37 | } | ||
| 38 | ); | ||
| 39 | }; | ||
| 40 | |||
| 41 | ajax '/ajax/content/admin/userlog' => require_role admin => sub { | ||
| 42 | |||
| 43 | content_type('text/html'); | ||
| 44 | template 'ajax/admintask/userlog.tt', {}, { layout => undef }; | ||
| 45 | }; | ||
| 46 | |||
| 47 | 1; |