diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm index 8bdf8c07..851c1edc 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm @@ -7,33 +7,35 @@ use Dancer::Plugin::Auth::Extensible; use App::Netdisco::Web::Plugin; register_report( - { category => 'Wireless', - tag => 'apchanneldist', - label => 'Access Point Channel Distribution', + { category => 'Wireless', + tag => 'apchanneldist', + label => 'Access Point Channel Distribution', provides_csv => 1, } ); get '/ajax/content/report/apchanneldist' => require_login sub { - my $set = schema('netdisco')->resultset('DevicePortWireless')->search( + my @results = schema('netdisco')->resultset('DevicePortWireless')->search( { channel => { '!=', '0' } }, { select => [ 'channel', { count => 'channel' } ], as => [qw/ channel ch_count /], group_by => [qw/channel/], order_by => { -desc => [qw/count/] }, }, - ); - return unless $set->count; + )->hri->all; - if (request->is_ajax) { - template 'ajax/report/apchanneldist.tt', { results => $set, }, + return unless scalar @results; + + if ( request->is_ajax ) { + my $json = to_json( \@results ); + template 'ajax/report/apchanneldist.tt', { results => $json }, { layout => undef }; } else { header( 'Content-Type' => 'text/comma-separated-values' ); - template 'ajax/report/apchanneldist_csv.tt', { results => $set, }, + template 'ajax/report/apchanneldist_csv.tt', { results => \@results }, { layout => undef }; } }; -true; +1; diff --git a/Netdisco/share/views/ajax/report/apchanneldist.tt b/Netdisco/share/views/ajax/report/apchanneldist.tt index 2575d998..b5215228 100644 --- a/Netdisco/share/views/ajax/report/apchanneldist.tt +++ b/Netdisco/share/views/ajax/report/apchanneldist.tt @@ -1,17 +1,29 @@ - +
- - + + - - [% WHILE (row = results.next) %] - - - - - [% END %] -
ChannelCountChannelCount
[% row.channel %][% row.get_column('ch_count') %]
+ diff --git a/Netdisco/share/views/ajax/report/apchanneldist_csv.tt b/Netdisco/share/views/ajax/report/apchanneldist_csv.tt index 7c242777..a2ded4eb 100644 --- a/Netdisco/share/views/ajax/report/apchanneldist_csv.tt +++ b/Netdisco/share/views/ajax/report/apchanneldist_csv.tt @@ -1,10 +1,10 @@ [% USE CSV -%] [% CSV.dump([ 'Channel' 'Count' ]) %] -[% WHILE (row = results.next) %] +[% FOREACH row IN results %] [% mylist = [] %] [% mylist.push(row.channel) %] - [% mylist.push(row.get_column('ch_count')) %] + [% mylist.push(row.ch_count) %] [% CSV.dump(mylist) %] [% END %]