diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm index 98e5d21b..56935d48 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm @@ -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; diff --git a/Netdisco/share/views/ajax/report/apchanneldist.tt b/Netdisco/share/views/ajax/report/apchanneldist.tt index 2575d998..11d547e6 100644 --- a/Netdisco/share/views/ajax/report/apchanneldist.tt +++ b/Netdisco/share/views/ajax/report/apchanneldist.tt @@ -1,3 +1,4 @@ +[% INCLUDE "download_as.tt" %] diff --git a/Netdisco/share/views/ajax/report/apchanneldist_csv.tt b/Netdisco/share/views/ajax/report/apchanneldist_csv.tt new file mode 100644 index 00000000..7c242777 --- /dev/null +++ b/Netdisco/share/views/ajax/report/apchanneldist_csv.tt @@ -0,0 +1,10 @@ +[% USE CSV -%] +[% CSV.dump([ 'Channel' 'Count' ]) %] + +[% WHILE (row = results.next) %] + [% mylist = [] %] + [% mylist.push(row.channel) %] + [% mylist.push(row.get_column('ch_count')) %] + [% CSV.dump(mylist) %] + +[% END %]