DataTables for access point channel distribution report
This commit is contained in:
@@ -7,33 +7,35 @@ use Dancer::Plugin::Auth::Extensible;
|
|||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
|
|
||||||
register_report(
|
register_report(
|
||||||
{ category => 'Wireless',
|
{ category => 'Wireless',
|
||||||
tag => 'apchanneldist',
|
tag => 'apchanneldist',
|
||||||
label => 'Access Point Channel Distribution',
|
label => 'Access Point Channel Distribution',
|
||||||
provides_csv => 1,
|
provides_csv => 1,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
get '/ajax/content/report/apchanneldist' => require_login sub {
|
get '/ajax/content/report/apchanneldist' => require_login sub {
|
||||||
my $set = schema('netdisco')->resultset('DevicePortWireless')->search(
|
my @results = schema('netdisco')->resultset('DevicePortWireless')->search(
|
||||||
{ channel => { '!=', '0' } },
|
{ channel => { '!=', '0' } },
|
||||||
{ select => [ 'channel', { count => 'channel' } ],
|
{ select => [ 'channel', { count => 'channel' } ],
|
||||||
as => [qw/ channel ch_count /],
|
as => [qw/ channel ch_count /],
|
||||||
group_by => [qw/channel/],
|
group_by => [qw/channel/],
|
||||||
order_by => { -desc => [qw/count/] },
|
order_by => { -desc => [qw/count/] },
|
||||||
},
|
},
|
||||||
);
|
)->hri->all;
|
||||||
return unless $set->count;
|
|
||||||
|
|
||||||
if (request->is_ajax) {
|
return unless scalar @results;
|
||||||
template 'ajax/report/apchanneldist.tt', { results => $set, },
|
|
||||||
|
if ( request->is_ajax ) {
|
||||||
|
my $json = to_json( \@results );
|
||||||
|
template 'ajax/report/apchanneldist.tt', { results => $json },
|
||||||
{ layout => undef };
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||||
template 'ajax/report/apchanneldist_csv.tt', { results => $set, },
|
template 'ajax/report/apchanneldist_csv.tt', { results => \@results },
|
||||||
{ layout => undef };
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
true;
|
1;
|
||||||
|
|||||||
@@ -1,17 +1,29 @@
|
|||||||
<table class="table table-bordered table-condensed table-striped nd_floatinghead">
|
<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="nd_center-cell">Channel</th>
|
<th>Channel</th>
|
||||||
<th class="nd_center-cell">Count</th>
|
<th>Count</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
</tbody>
|
|
||||||
[% WHILE (row = results.next) %]
|
|
||||||
<tr>
|
|
||||||
<td class="nd_center-cell">[% row.channel %]</td>
|
|
||||||
<td class="nd_center-cell">[% row.get_column('ch_count') %]</td>
|
|
||||||
</tr>
|
|
||||||
[% END %]
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
var table = $('#data-table').dataTable({
|
||||||
|
"deferRender": true,
|
||||||
|
"order": [[ 1, "desc" ]],
|
||||||
|
"data": [% results %],
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"data": 'channel'
|
||||||
|
}, {
|
||||||
|
"data": 'ch_count',
|
||||||
|
"searchable": false,
|
||||||
|
"render": function(data, type, full, meta) {
|
||||||
|
return data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
[% USE CSV -%]
|
[% USE CSV -%]
|
||||||
[% CSV.dump([ 'Channel' 'Count' ]) %]
|
[% CSV.dump([ 'Channel' 'Count' ]) %]
|
||||||
|
|
||||||
[% WHILE (row = results.next) %]
|
[% FOREACH row IN results %]
|
||||||
[% mylist = [] %]
|
[% mylist = [] %]
|
||||||
[% mylist.push(row.channel) %]
|
[% mylist.push(row.channel) %]
|
||||||
[% mylist.push(row.get_column('ch_count')) %]
|
[% mylist.push(row.ch_count) %]
|
||||||
[% CSV.dump(mylist) %]
|
[% CSV.dump(mylist) %]
|
||||||
|
|
||||||
[% END %]
|
[% END %]
|
||||||
|
|||||||
Reference in New Issue
Block a user