DataTables for ports in half duplex mode report
This commit is contained in:
		| @@ -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; | ||||
|   | ||||
| @@ -1,23 +1,44 @@ | ||||
| <table class="table table-bordered table-condensed table-striped nd_floatinghead"> | ||||
| <table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0"> | ||||
|   <thead> | ||||
|     <tr> | ||||
|       <th>Device</th> | ||||
|       <th class="nd_center-cell">Port</th> | ||||
|       <th class="nd_center-cell">Description</th> | ||||
|       <th class="nd_center-cell">Duplex</th> | ||||
|       <th>Port</th> | ||||
|       <th>Description</th> | ||||
|       <th>Duplex</th> | ||||
|     </tr> | ||||
|   </thead> | ||||
|   </tbody> | ||||
|     [% WHILE (row = results.next) %] | ||||
|     <tr> | ||||
|       <td>[% row.device.dns || row.device.ip | html_entity %]</td> | ||||
|       <td class="nd_center-cell"><a class="nd_linkcell" | ||||
|         href="[% device_ports %]&q=[% row.device.ip | uri %]&f=[% row.port | uri %]&c_duplex=on"> | ||||
|           [% row.port | html_entity %]</a></td> | ||||
|       <td class="nd_center-cell">[% row.name | html_entity %]</td> | ||||
|       <td class="nd_center-cell">[% row.duplex.ucfirst | html_entity %]</td> | ||||
|     </tr> | ||||
|     [% END %] | ||||
|   </tbody> | ||||
| </table> | ||||
|  | ||||
| <script type="text/javascript"> | ||||
| $(document).ready(function() { | ||||
|   var table = $('#data-table').dataTable({ | ||||
|     "deferRender": true, | ||||
|     "data": [% results %], | ||||
|     "columns": [ | ||||
|       { | ||||
|         "data": 'ip', | ||||
|         "render": function(data, type, row, meta) { | ||||
|           return he.encode(row.device.dns || row.device.name || row.ip); | ||||
|         } | ||||
|       }, { | ||||
|         "data": 'port', | ||||
|         "render": function(data, type, row, meta) { | ||||
|           return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>'; | ||||
|         } | ||||
|       }, { | ||||
|         "data": 'name', | ||||
|         "render": function(data, type, row, meta) { | ||||
|           return he.encode(data || ''); | ||||
|         } | ||||
|       }, { | ||||
|         "data": 'duplex', | ||||
|         "searchable": false, | ||||
|         "orderable": false, | ||||
|         "render": function(data, type, full, meta) { | ||||
|           return he.encode(capitalizeFirstLetter(data)); | ||||
|         } | ||||
|       } | ||||
|     ] | ||||
|   }); | ||||
| }); | ||||
| </script> | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| [% USE CSV -%] | ||||
| [% CSV.dump([ 'Device' 'Port' 'Description' 'Duplex' ]) %] | ||||
|  | ||||
| [% WHILE (row = results.next) %] | ||||
| [% FOREACH row IN results %] | ||||
|   [% mylist = [] %] | ||||
|   [% device = row.device.dns || row.device.ip %] | ||||
|   [% device = rrow.device.dns || row.device.name || row.ip %] | ||||
|   [% FOREACH col IN [ device row.port row.name row.duplex.ucfirst ] %] | ||||
|     [% mylist.push(col) %] | ||||
|   [% END %] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user