add csv download to ap channel distribution report

This commit is contained in:
Eric A. Miller
2013-09-18 23:50:27 -04:00
parent 0824d7936a
commit 5d4df72a24
3 changed files with 36 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ register_report(
}
);
ajax '/ajax/content/report/apchanneldist' => require_login sub {
sub get_rs_apchdist {
my $set = schema('netdisco')->resultset('DevicePortWireless')->search(
{ channel => { '!=', '0' } },
{ select => [ 'channel', { count => 'channel' } ],
@@ -23,6 +23,11 @@ ajax '/ajax/content/report/apchanneldist' => require_login sub {
order_by => { -desc => [qw/count/] },
},
);
return $set;
}
ajax '/ajax/content/report/apchanneldist' => require_login sub {
my $set = get_rs_apchdist();
return unless $set->count;
@@ -31,4 +36,23 @@ ajax '/ajax/content/report/apchanneldist' => require_login sub {
{ layout => undef };
};
get '/ajax/content/report/apchanneldist' => require_login sub {
my $format = param('format');
my $set = get_rs_apchdist();
return unless $set->count;
if ( $format eq 'csv' ) {
header( 'Content-Type' => 'text/comma-separated-values' );
header( 'Content-Disposition' =>
"attachment; filename=\"apchanneldist.csv\"" );
template 'ajax/report/apchanneldist_csv.tt', { results => $set, },
{ layout => undef };
}
else {
return;
}
};
true;