diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/HalfDuplex.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/HalfDuplex.pm index 64a41186..065786ac 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/HalfDuplex.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/HalfDuplex.pm @@ -1,7 +1,6 @@ package App::Netdisco::Web::Plugin::Report::HalfDuplex; use Dancer ':syntax'; -use Dancer::Plugin::Ajax; use Dancer::Plugin::DBIC; use Dancer::Plugin::Auth::Extensible; @@ -13,19 +12,6 @@ register_report({ label => 'Ports in Half Duplex Mode', }); -ajax '/ajax/content/report/halfduplex' => require_login sub { - my $set = schema('netdisco')->resultset('DevicePort')->search( - { up => 'up', duplex => { '-ilike' => 'half' } }, - { order_by => [qw/device.dns port/], prefetch => 'device' }, - ); - return unless $set->count; - - content_type('text/html'); - template 'ajax/report/halfduplex.tt', { - results => $set, - }, { layout => undef }; -}; - get '/ajax/content/report/halfduplex' => require_login sub { my $format = param('format'); my $set = schema('netdisco')->resultset('DevicePort')->search( @@ -34,16 +20,14 @@ get '/ajax/content/report/halfduplex' => require_login sub { ); return unless $set->count; - if ( $format eq 'csv' ) { - - header( 'Content-Type' => 'text/comma-separated-values' ); - header( 'Content-Disposition' => - "attachment; filename=\"halfduplex.csv\"" ); - template 'ajax/report/halfduplex_csv.tt', { results => $set, }, + if (request->is_ajax) { + template 'ajax/report/halfduplex.tt', { results => $set, }, { layout => undef }; } else { - return; + header( 'Content-Type' => 'text/comma-separated-values' ); + template 'ajax/report/halfduplex_csv.tt', { results => $set, }, + { layout => undef }; } }; diff --git a/Netdisco/share/views/ajax/report/halfduplex.tt b/Netdisco/share/views/ajax/report/halfduplex.tt index 178e1594..f5594292 100644 --- a/Netdisco/share/views/ajax/report/halfduplex.tt +++ b/Netdisco/share/views/ajax/report/halfduplex.tt @@ -1,4 +1,3 @@ -[% INCLUDE "download_as.tt" %] diff --git a/Netdisco/share/views/js/common.js b/Netdisco/share/views/js/common.js index d66e9e64..48098ad8 100644 --- a/Netdisco/share/views/js/common.js +++ b/Netdisco/share/views/js/common.js @@ -1,3 +1,18 @@ + // csv download icon on any table page + // needs to be dynamically updated to use current search options + function update_csv_download_link (type, tab) { + var form = '#' + tab + '_form'; + var query = $(form).serialize(); + + // this is needed otherwise we can 404 on url with traling slash + if (query.length) { query = '/' + query } + + $('#nd_csv-download').attr('href', '/ajax/content/' + type + '/' + tab + query); + } + + // page title includes tab name and possibly device name + // this is nice for when you have multiple netdisco pages open in the + // browser function update_page_title (tab) { var pgtitle = 'Netdisco'; if ($('#nd_device-name').text().length) { @@ -74,7 +89,8 @@ [% IF report %] // for the report pages $('[% "#${report.tag}_form" %]').submit(function (event) { - update_page_title('[% tab.tag %]'); + update_page_title('[% report.tag %]'); + update_csv_download_link('report', '[% report.tag %]'); do_search(event, '[% report.tag %]'); }); [% END -%] @@ -82,7 +98,7 @@ [% IF task %] // for the admin pages $('[% "#${task.tag}_form" %]').submit(function (event) { - update_page_title('[% tab.tag %]'); + update_page_title('[% task.tag %]'); do_search(event, '[% task.tag %]'); }); [% END %] diff --git a/Netdisco/share/views/report.tt b/Netdisco/share/views/report.tt index b3cb963b..6db3dce0 100644 --- a/Netdisco/share/views/report.tt +++ b/Netdisco/share/views/report.tt @@ -28,6 +28,10 @@