DataTables for ports in half duplex mode report

This commit is contained in:
Eric A. Miller
2014-05-28 23:40:07 -04:00
parent 4df2b5d216
commit 0a5686b454
3 changed files with 64 additions and 34 deletions

View File

@@ -6,30 +6,39 @@ use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_report({
category => 'Port',
register_report(
{ category => 'Port',
tag => 'halfduplex',
label => 'Ports in Half Duplex Mode',
provides_csv => 1,
});
}
);
get '/ajax/content/report/halfduplex' => require_login sub {
my $format = param('format');
my $set = schema('netdisco')->resultset('DevicePort')->search(
my @results
= schema('netdisco')->resultset('DevicePort')
->columns( [qw/ ip port name duplex /] )->search(
{ up => 'up', duplex => { '-ilike' => 'half' } },
{ order_by => [qw/device.dns port/], prefetch => 'device' },
);
return unless $set->count;
{ '+columns' => [qw/ device.dns device.name /],
join => [qw/ device /],
collapse => 1,
}
)->order_by( [qw/ device.dns port /] )->hri->all;
return unless scalar @results;
if ( request->is_ajax ) {
template 'ajax/report/halfduplex.tt', { results => $set, },
my $json = to_json( \@results );
template 'ajax/report/halfduplex.tt', { results => $json },
{ layout => undef };
}
else {
header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/report/halfduplex_csv.tt', { results => $set, },
template 'ajax/report/halfduplex_csv.tt',
{ results => \@results },
{ layout => undef };
}
};
true;
1;

View File

@@ -1,23 +1,44 @@
<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>
<tr>
<th>Device</th>
<th class="nd_center-cell">Port</th>
<th class="nd_center-cell">Description</th>
<th class="nd_center-cell">Duplex</th>
<th>Port</th>
<th>Description</th>
<th>Duplex</th>
</tr>
</thead>
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td>[% row.device.dns || row.device.ip | html_entity %]</td>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.device.ip | uri %]&f=[% row.port | uri %]&c_duplex=on">
[% row.port | html_entity %]</a></td>
<td class="nd_center-cell">[% row.name | html_entity %]</td>
<td class="nd_center-cell">[% row.duplex.ucfirst | html_entity %]</td>
</tr>
[% END %]
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
var table = $('#data-table').dataTable({
"deferRender": true,
"data": [% results %],
"columns": [
{
"data": 'ip',
"render": function(data, type, row, meta) {
return he.encode(row.device.dns || row.device.name || row.ip);
}
}, {
"data": 'port',
"render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>';
}
}, {
"data": 'name',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, {
"data": 'duplex',
"searchable": false,
"orderable": false,
"render": function(data, type, full, meta) {
return he.encode(capitalizeFirstLetter(data));
}
}
]
});
});
</script>

View File

@@ -1,9 +1,9 @@
[% USE CSV -%]
[% CSV.dump([ 'Device' 'Port' 'Description' 'Duplex' ]) %]
[% WHILE (row = results.next) %]
[% FOREACH row IN results %]
[% mylist = [] %]
[% device = row.device.dns || row.device.ip %]
[% device = rrow.device.dns || row.device.name || row.ip %]
[% FOREACH col IN [ device row.port row.name row.duplex.ucfirst ] %]
[% mylist.push(col) %]
[% END %]