DataTables for ports in half duplex mode report
This commit is contained in:
@@ -6,30 +6,39 @@ use Dancer::Plugin::Auth::Extensible;
|
|||||||
|
|
||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
|
|
||||||
register_report({
|
register_report(
|
||||||
category => 'Port',
|
{ category => 'Port',
|
||||||
tag => 'halfduplex',
|
tag => 'halfduplex',
|
||||||
label => 'Ports in Half Duplex Mode',
|
label => 'Ports in Half Duplex Mode',
|
||||||
provides_csv => 1,
|
provides_csv => 1,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
get '/ajax/content/report/halfduplex' => require_login sub {
|
get '/ajax/content/report/halfduplex' => require_login sub {
|
||||||
my $format = param('format');
|
my $format = param('format');
|
||||||
my $set = schema('netdisco')->resultset('DevicePort')->search(
|
my @results
|
||||||
{ up => 'up', duplex => { '-ilike' => 'half' } },
|
= schema('netdisco')->resultset('DevicePort')
|
||||||
{ order_by => [qw/device.dns port/], prefetch => 'device' },
|
->columns( [qw/ ip port name duplex /] )->search(
|
||||||
);
|
{ up => 'up', duplex => { '-ilike' => 'half' } },
|
||||||
return unless $set->count;
|
{ '+columns' => [qw/ device.dns device.name /],
|
||||||
|
join => [qw/ device /],
|
||||||
|
collapse => 1,
|
||||||
|
}
|
||||||
|
)->order_by( [qw/ device.dns port /] )->hri->all;
|
||||||
|
|
||||||
if (request->is_ajax) {
|
return unless scalar @results;
|
||||||
template 'ajax/report/halfduplex.tt', { results => $set, },
|
|
||||||
|
if ( request->is_ajax ) {
|
||||||
|
my $json = to_json( \@results );
|
||||||
|
template 'ajax/report/halfduplex.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/halfduplex_csv.tt', { results => $set, },
|
template 'ajax/report/halfduplex_csv.tt',
|
||||||
{ layout => undef };
|
{ results => \@results },
|
||||||
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
true;
|
1;
|
||||||
|
|||||||
@@ -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>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Device</th>
|
<th>Device</th>
|
||||||
<th class="nd_center-cell">Port</th>
|
<th>Port</th>
|
||||||
<th class="nd_center-cell">Description</th>
|
<th>Description</th>
|
||||||
<th class="nd_center-cell">Duplex</th>
|
<th>Duplex</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</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>
|
</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>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
[% USE CSV -%]
|
[% USE CSV -%]
|
||||||
[% CSV.dump([ 'Device' 'Port' 'Description' 'Duplex' ]) %]
|
[% CSV.dump([ 'Device' 'Port' 'Description' 'Duplex' ]) %]
|
||||||
|
|
||||||
[% WHILE (row = results.next) %]
|
[% FOREACH row IN results %]
|
||||||
[% mylist = [] %]
|
[% 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 ] %]
|
[% FOREACH col IN [ device row.port row.name row.duplex.ucfirst ] %]
|
||||||
[% mylist.push(col) %]
|
[% mylist.push(col) %]
|
||||||
[% END %]
|
[% END %]
|
||||||
|
|||||||
Reference in New Issue
Block a user