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',
tag => 'halfduplex',
label => 'Ports in Half Duplex Mode',
provides_csv => 1,
});
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(
{ up => 'up', duplex => { '-ilike' => 'half' } },
{ order_by => [qw/device.dns port/], prefetch => 'device' },
);
return unless $set->count;
my @results
= schema('netdisco')->resultset('DevicePort')
->columns( [qw/ ip port name duplex /] )->search(
{ up => 'up', duplex => { '-ilike' => 'half' } },
{ '+columns' => [qw/ device.dns device.name /],
join => [qw/ device /],
collapse => 1,
}
)->order_by( [qw/ device.dns port /] )->hri->all;
if (request->is_ajax) {
template 'ajax/report/halfduplex.tt', { results => $set, },
return unless scalar @results;
if ( request->is_ajax ) {
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, },
{ layout => undef };
template 'ajax/report/halfduplex_csv.tt',
{ results => \@results },
{ layout => undef };
}
};
true;
1;