Datatables for IP Phones discovered through LLDP/CDP report

This commit is contained in:
Eric A. Miller
2014-05-29 23:00:28 -04:00
parent 14e401813b
commit 669333d490
3 changed files with 63 additions and 33 deletions

View File

@@ -7,26 +7,30 @@ use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin; use App::Netdisco::Web::Plugin;
register_report( register_report(
{ category => 'Node', { category => 'Node',
tag => 'phonesdiscovered', tag => 'phonesdiscovered',
label => 'IP Phones discovered through LLDP/CDP', label => 'IP Phones discovered through LLDP/CDP',
provides_csv => 1, provides_csv => 1,
} }
); );
get '/ajax/content/report/phonesdiscovered' => require_login sub { get '/ajax/content/report/phonesdiscovered' => require_login sub {
my $set = schema('netdisco')->resultset('Virtual::PhonesDiscovered'); my @results = schema('netdisco')->resultset('Virtual::PhonesDiscovered')
return unless $set->count; ->hri->all;
if (request->is_ajax) { return unless scalar @results;
template 'ajax/report/phonesdiscovered.tt', { results => $set, },
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/phonesdiscovered.tt', { results => $json },
{ layout => undef }; { layout => undef };
} }
else { else {
header( 'Content-Type' => 'text/comma-separated-values' ); header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/report/phonesdiscovered_csv.tt', { results => $set, }, template 'ajax/report/phonesdiscovered_csv.tt',
{ layout => undef }; { results => \@results },
{ layout => undef };
} }
}; };
true; 1;

View File

@@ -1,28 +1,54 @@
<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> <thead>
<tr> <tr>
<th class="nd_center-cell">Device</th> <th>Device</th>
<th class="nd_center-cell">Port</th> <th>Port</th>
<th class="nd_center-cell">Remote ID</th> <th>Remote ID</th>
<th class="nd_center-cell">Remote IP</th> <th>Remote IP</th>
<th class="nd_center-cell">Remote Port</th> <th>Remote Port</th>
<th class="nd_center-cell">Remote Type</th> <th>Remote Type</th>
</tr> </tr>
</thead> </thead>
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td class="nd_center-cell">[% row.dns || row.name || row.ip | html_entity %]</td>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.ip | uri %]&f=[% row.port | uri %]">
[% row.port | html_entity %]</a></td>
<td class="nd_center-cell">[% row.remote_id | html_entity %]</td>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% search_node %]&q=[% row.remote_ip | uri %]">[% row.remote_ip | html_entity %]</a></td>
<td class="nd_center-cell">[% row.remote_port | html_entity %]</td>
<td class="nd_center-cell">[% row.remote_type | html_entity %]</td>
</tr>
[% END %]
</tbody>
</table> </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.dns || row.name || data);
}
}, {
"data": 'port',
"render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
}
}, {
"data": 'remote_id',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, {
"data": 'remote_ip',
"render": function(data, type, row, meta) {
return '<a href="[% search_node %]&q=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
}
}, {
"data": 'remote_port',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, {
"data": 'remote_type',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}
]
});
});
</script>

View File

@@ -1,7 +1,7 @@
[% USE CSV -%] [% USE CSV -%]
[% CSV.dump([ 'Device' 'Port' 'Remote ID' 'Remote IP' 'Remote Port' 'Remote Type']) %] [% CSV.dump([ 'Device' 'Port' 'Remote ID' 'Remote IP' 'Remote Port' 'Remote Type']) %]
[% WHILE (row = results.next) %] [% FOREACH row IN results %]
[% mylist = [] %] [% mylist = [] %]
[% device = row.dns || row.name || row.ip %] [% device = row.dns || row.name || row.ip %]
[% FOREACH col IN [ device row.port row.remote_id row.remote_ip row.remote_port row.remote_type ] %] [% FOREACH col IN [ device row.port row.remote_id row.remote_ip row.remote_port row.remote_type ] %]