DataTables for admin user log report
This commit is contained in:
@@ -4,40 +4,63 @@ use Dancer ':syntax';
|
||||
use Dancer::Plugin::Ajax;
|
||||
use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
use App::Netdisco::Util::ExpandParams 'expand_hash';
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
|
||||
register_admin_task({
|
||||
tag => 'userlog',
|
||||
register_admin_task(
|
||||
{ tag => 'userlog',
|
||||
label => 'User Activity Log',
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
ajax '/ajax/control/admin/userlog/data' => require_role admin => sub {
|
||||
send_error( 'Missing parameter', 400 )
|
||||
unless ( param('draw') && param('draw') =~ /\d+/ );
|
||||
|
||||
my $rs = schema('netdisco')->resultset('UserLog');
|
||||
|
||||
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,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
ajax '/ajax/control/admin/userlog/del' => require_role admin => sub {
|
||||
send_error( 'Missing entry', 400 ) unless param('entry');
|
||||
|
||||
schema('netdisco')->txn_do(sub {
|
||||
schema('netdisco')->txn_do(
|
||||
sub {
|
||||
my $device = schema('netdisco')->resultset('UserLog')
|
||||
->search( { entry => param('entry') } )->delete;
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
ajax '/ajax/control/admin/userlog/delall' => require_role admin => sub {
|
||||
schema('netdisco')->txn_do(sub {
|
||||
schema('netdisco')->txn_do(
|
||||
sub {
|
||||
my $device = schema('netdisco')->resultset('UserLog')->delete;
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
ajax '/ajax/content/admin/userlog' => require_role admin => sub {
|
||||
my $set = schema('netdisco')->resultset('UserLog')
|
||||
->search({}, {
|
||||
order_by => { -desc => [qw/creation event/] },
|
||||
rows => 200,
|
||||
});
|
||||
|
||||
content_type('text/html');
|
||||
template 'ajax/admintask/userlog.tt', {
|
||||
results => $set,
|
||||
}, { layout => undef };
|
||||
template 'ajax/admintask/userlog.tt', {}, { layout => undef };
|
||||
};
|
||||
|
||||
true;
|
||||
1;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[% IF results.count == 0 %]
|
||||
<div class="span2 alert alert-info">The user activity log is empty.</div>
|
||||
[% ELSE %]
|
||||
<table class="table table-bordered table-condensed table-hover nd_floatinghead">
|
||||
<table id="aul-data-table" class="table table-bordered table-condensed table-hover" width="100%" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="nd_center-cell">Creation</th>
|
||||
@@ -11,20 +11,53 @@
|
||||
<th class="nd_center-cell">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</tbody>
|
||||
[% WHILE (row = results.next) %]
|
||||
<tr data-content="<pre>[% row.details | html_entity %]</pre>">
|
||||
<td class="nd_center-cell">[% row.creation | html_entity %]</td>
|
||||
<td class="nd_center-cell">[% row.username | html_entity %]</td>
|
||||
<td class="nd_center-cell">[% row.userip | html_entity %]</td>
|
||||
<td class="nd_center-cell">[% row.event | html_entity %]</td>
|
||||
<td class="nd_center-cell">
|
||||
<input data-form="del" name="entry" type="hidden" value="[% row.entry | html_entity %]">
|
||||
<button class="btn nd_adminbutton" name="del" type="submit"><i class="icon-trash text-error"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
[% END %]
|
||||
</tbody>
|
||||
</table>
|
||||
[% END %]
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#aul-data-table').dataTable( {
|
||||
"processing": true,
|
||||
"serverSide": true,
|
||||
"stateSave": true,
|
||||
"pageLength": 25,
|
||||
"order": [[ 0, "desc" ]],
|
||||
"ajax": "/ajax/control/admin/userlog/data",
|
||||
"columns": [{
|
||||
"data": 'creation',
|
||||
"className": "nd_center-cell",
|
||||
"render": function(data, type, row, meta) {
|
||||
return moment(data).format('YYYY-MM-DD HH:mm');
|
||||
}
|
||||
}, {
|
||||
"data": 'username',
|
||||
"className": "nd_center-cell",
|
||||
"render": function(data, type, row, meta) {
|
||||
return he.encode(data || '');
|
||||
}
|
||||
}, {
|
||||
"data": 'userip',
|
||||
"className": "nd_center-cell",
|
||||
"render": function(data, type, row, meta) {
|
||||
return he.encode(data || '');
|
||||
}
|
||||
}, {
|
||||
"data": 'event',
|
||||
"className": "nd_center-cell",
|
||||
"render": function(data, type, row, meta) {
|
||||
return he.encode(data || '');
|
||||
}
|
||||
}, {
|
||||
"data": 'entry',
|
||||
"className": "nd_center-cell",
|
||||
"searchable": false,
|
||||
"orderable": false,
|
||||
"render": function(data, type, row, meta) {
|
||||
return '<input data-form="del" name="entry" type="hidden" value="' + encodeURIComponent(data) +
|
||||
'"><button class="btn nd_adminbutton" name="del" type="submit"><i class="icon-trash text-error"></i></button>';
|
||||
}
|
||||
}
|
||||
]
|
||||
} );
|
||||
} );
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user