DataTables for Access Point Radios Channel and Power report
Optimize SQL for ap_radio_channel_power virtual table Convert mW to dBm via the database query
This commit is contained in:
@@ -10,30 +10,38 @@ __PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
|||||||
__PACKAGE__->table('ap_radio_channel_power');
|
__PACKAGE__->table('ap_radio_channel_power');
|
||||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||||
SELECT distinct d.name as device_name, d.ip, d.dns, d.model, d.location,
|
SELECT w.channel,
|
||||||
dp.port, dp.name as port_name, dp.descr, w.channel, w.power
|
w.power,
|
||||||
FROM device AS d, device_port_wireless AS w, device_port AS dp
|
w.ip,
|
||||||
WHERE dp.port = w.port AND d.ip = w.ip
|
w.port,
|
||||||
ORDER BY d.name
|
dp.name AS port_name,
|
||||||
|
dp.descr,
|
||||||
|
d.name AS device_name,
|
||||||
|
d.dns,
|
||||||
|
d.model,
|
||||||
|
d.location,
|
||||||
|
CASE
|
||||||
|
WHEN w.power > 0 THEN round((10.0 * log(w.power) / log(10))::numeric, 1)
|
||||||
|
ELSE NULL
|
||||||
|
END AS power2
|
||||||
|
FROM device_port_wireless AS w
|
||||||
|
JOIN device_port AS dp ON dp.port = w.port
|
||||||
|
AND dp.ip = w.ip
|
||||||
|
JOIN device AS d ON d.ip = w.ip
|
||||||
|
WHERE w.channel != '0'
|
||||||
ENDSQL
|
ENDSQL
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
'device_name' => {
|
'channel' => {
|
||||||
data_type => 'text',
|
data_type => 'integer',
|
||||||
|
},
|
||||||
|
'power' => {
|
||||||
|
data_type => 'integer',
|
||||||
},
|
},
|
||||||
'ip' => {
|
'ip' => {
|
||||||
data_type => 'inet',
|
data_type => 'inet',
|
||||||
},
|
},
|
||||||
'dns' => {
|
|
||||||
data_type => 'text',
|
|
||||||
},
|
|
||||||
'model' => {
|
|
||||||
data_type => 'text',
|
|
||||||
},
|
|
||||||
'location' => {
|
|
||||||
data_type => 'text',
|
|
||||||
},
|
|
||||||
'port' => {
|
'port' => {
|
||||||
data_type => 'text',
|
data_type => 'text',
|
||||||
},
|
},
|
||||||
@@ -43,11 +51,20 @@ __PACKAGE__->add_columns(
|
|||||||
'descr' => {
|
'descr' => {
|
||||||
data_type => 'text',
|
data_type => 'text',
|
||||||
},
|
},
|
||||||
'channel' => {
|
'device_name' => {
|
||||||
data_type => 'integer',
|
data_type => 'text',
|
||||||
},
|
},
|
||||||
'power' => {
|
'dns' => {
|
||||||
data_type => 'integer',
|
data_type => 'text',
|
||||||
|
},
|
||||||
|
'model' => {
|
||||||
|
data_type => 'text',
|
||||||
|
},
|
||||||
|
'location' => {
|
||||||
|
data_type => 'text',
|
||||||
|
},
|
||||||
|
'power2' => {
|
||||||
|
data_type => 'numeric',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package App::Netdisco::Web::Plugin::Report::ApRadioChannelPower;
|
|||||||
use Dancer ':syntax';
|
use Dancer ':syntax';
|
||||||
use Dancer::Plugin::DBIC;
|
use Dancer::Plugin::DBIC;
|
||||||
use Dancer::Plugin::Auth::Extensible;
|
use Dancer::Plugin::Auth::Extensible;
|
||||||
|
use App::Netdisco::Util::ExpandParams 'expand_hash';
|
||||||
|
|
||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
|
|
||||||
@@ -47,20 +48,48 @@ sub port_tree {
|
|||||||
return \%ports;
|
return \%ports;
|
||||||
}
|
}
|
||||||
|
|
||||||
get '/ajax/content/report/apradiochannelpower' => require_login sub {
|
get '/ajax/content/report/apradiochannelpower/data' => require_role admin =>
|
||||||
my @set
|
sub {
|
||||||
= schema('netdisco')->resultset('Virtual::ApRadioChannelPower')->all;
|
send_error( 'Missing parameter', 400 )
|
||||||
|
unless ( param('draw') && param('draw') =~ /\d+/ );
|
||||||
|
|
||||||
my $results = port_tree( \@set );
|
my $rs = schema('netdisco')->resultset('Virtual::ApRadioChannelPower');
|
||||||
return unless scalar %$results;
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
get '/ajax/content/report/apradiochannelpower' => require_login sub {
|
||||||
|
|
||||||
if ( request->is_ajax ) {
|
if ( request->is_ajax ) {
|
||||||
template 'ajax/report/apradiochannelpower.tt', { results => $results, },
|
template 'ajax/report/apradiochannelpower.tt', {},
|
||||||
{ layout => undef };
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
my @results
|
||||||
|
= schema('netdisco')->resultset('Virtual::ApRadioChannelPower')
|
||||||
|
->hri->all;
|
||||||
|
|
||||||
|
return unless scalar @results;
|
||||||
|
|
||||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||||
template 'ajax/report/apradiochannelpower_csv.tt', { results => $results, },
|
template 'ajax/report/apradiochannelpower_csv.tt',
|
||||||
|
{ results => \@results, },
|
||||||
{ layout => undef };
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,23 +1,9 @@
|
|||||||
<div class="accordion" id="accordion-radio-pwr">
|
<table id="data-table" class="table table-bordered table-hover" width="100%" cellspacing="0">
|
||||||
[% count = 0 %]
|
|
||||||
[% FOREACH row IN results.keys.sort %]
|
|
||||||
[% count = count + 1 %]
|
|
||||||
<div class="accordion-group">
|
|
||||||
<div class="accordion-heading">
|
|
||||||
<a class="accordion-toggle" data-toggle="collapse" data-target="#collapse-[% count %]" href="#collapse-[% count %]">
|
|
||||||
<i class="[% results.$row.ports.size < 10 ? 'icon-chevron-down' : 'icon-chevron-up' %]"></i>
|
|
||||||
[% results.$row.device.dns || results.$row.device.name %]
|
|
||||||
( [% results.$row.device.model %] )
|
|
||||||
[% IF results.$row.device.location %]
|
|
||||||
Location: [% results.$row.device.location %]
|
|
||||||
[% END %]
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div id="collapse-[% count %]" class="accordion-body collapse[% ' in' IF results.$row.ports.size < 10 %]">
|
|
||||||
<div class="accordion-inner">
|
|
||||||
<table class="table table-bordered table-condensed">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>IP</th>
|
||||||
|
<th>DNS</th>
|
||||||
|
<th>Device</th>
|
||||||
<th>Port</th>
|
<th>Port</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Description</th>
|
<th>Description</th>
|
||||||
@@ -25,29 +11,107 @@
|
|||||||
<th class="nd_center-cell">Tx Power (mW/dBm)</th>
|
<th class="nd_center-cell">Tx Power (mW/dBm)</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
|
||||||
[% FOREACH p IN results.$row.ports %]
|
|
||||||
[% NEXT UNLESS p.channel # No channel port is admin down %]
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<a href="[% device_ports %]&q=[% results.$row.device.ip | uri %]&f=[% p.port | uri %]">
|
|
||||||
[% p.port | html_entity %]</a></td>
|
|
||||||
<td>[% p.name %]</td>
|
|
||||||
<td>[% p.descr %]</td>
|
|
||||||
<td class="nd_center-cell">[% p.channel %]</td>
|
|
||||||
<td class="nd_center-cell">[% IF p.power or p.power2 %][% p.power %] / [% p.power2 %][% END %]</td>
|
|
||||||
</tr>
|
|
||||||
[% END %]
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
|
||||||
</div>
|
<style>
|
||||||
</div>
|
tr.group,
|
||||||
[%END%]
|
tr.group:hover {
|
||||||
</div>
|
background-color: #ddd !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$('.accordion').on('show hide', function (n) {
|
function groupString(d) {
|
||||||
$(n.target).siblings('.accordion-heading').find('.accordion-toggle i').toggleClass('icon-chevron-up icon-chevron-down');
|
"use strict";
|
||||||
|
var s = '';
|
||||||
|
s = s + 'Device: ';
|
||||||
|
s = s + '<a href="[% uri_for('/device') %]?tab=details&q=' + encodeURIComponent(d.ip) + '">';
|
||||||
|
s = s + he.encode(d.dns || d.device_name || d.ip);
|
||||||
|
if (d.dns || d.device_name) {
|
||||||
|
s = s + ' (' + he.encode(d.ip) + ') ';
|
||||||
|
}
|
||||||
|
s = s + '</a> Model: ' + he.encode(d.model || '');
|
||||||
|
s = s + he.encode(d.location ? ' Location: ' + d.location : '');
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
var table = $('#data-table').DataTable({
|
||||||
|
"processing": true,
|
||||||
|
"stateSave": true,
|
||||||
|
"pageLength": 25,
|
||||||
|
"language": {
|
||||||
|
"search": 'Filter records: '
|
||||||
|
},
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": '/ajax/content/report/apradiochannelpower/data',
|
||||||
|
"order": [[ 0, 'asc' ]],
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
// Grouping column
|
||||||
|
"data": 'ip',
|
||||||
|
"visible": false
|
||||||
|
}, {
|
||||||
|
// Included for filtering
|
||||||
|
"data": 'dns',
|
||||||
|
"visible": false
|
||||||
|
}, {
|
||||||
|
// Included for filtering
|
||||||
|
"data": 'device_name',
|
||||||
|
"visible": false
|
||||||
|
}, {
|
||||||
|
"data": 'port',
|
||||||
|
"render": function(data, type, row, meta) {
|
||||||
|
return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"data": 'port_name',
|
||||||
|
"render": function(data, type, row, meta) {
|
||||||
|
return he.encode(data || '');
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"data": 'descr',
|
||||||
|
"render": function(data, type, row, meta) {
|
||||||
|
return he.encode(data || '');
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"data": 'channel',
|
||||||
|
"className": "nd_center-cell"
|
||||||
|
}, {
|
||||||
|
"data": 'power',
|
||||||
|
"className": "nd_center-cell",
|
||||||
|
"render": function(data, type, row, meta) {
|
||||||
|
return (row.power2 ? data + ' / ' + row.power2 : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"drawCallback": function ( settings ) {
|
||||||
|
var api = this.api();
|
||||||
|
var rows = api.rows( {page:'current'} ).nodes();
|
||||||
|
var last=null;
|
||||||
|
|
||||||
|
api.column(0, {page:'current'} ).data().each( function ( group, i ) {
|
||||||
|
if ( last !== group ) {
|
||||||
|
var row_data = api.row( i ).data();
|
||||||
|
$(rows).eq( i ).before(
|
||||||
|
'<tr class="group"><td colspan="5">' + groupString(row_data) + '</td></tr>'
|
||||||
|
);
|
||||||
|
last = group;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
// Order by the grouping
|
||||||
|
$('#data-table tbody').on( 'click', 'tr.group', function () {
|
||||||
|
var currentOrder = table.order()[0];
|
||||||
|
if ( currentOrder[0] === 0 && currentOrder[1] === 'asc' ) {
|
||||||
|
table.order( [ 0, 'desc' ] ).draw();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
table.order( [ 0, 'asc' ] ).draw();
|
||||||
|
}
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user