DataTables for device by location report
This commit is contained in:
@@ -15,21 +15,24 @@ register_report(
|
|||||||
);
|
);
|
||||||
|
|
||||||
get '/ajax/content/report/devicebylocation' => require_login sub {
|
get '/ajax/content/report/devicebylocation' => require_login sub {
|
||||||
my $set
|
my @results
|
||||||
= schema('netdisco')->resultset('Device')
|
= schema('netdisco')->resultset('Device')
|
||||||
->search( {},
|
->columns( [qw/ ip dns name location vendor model /] )
|
||||||
{ order_by => [qw/ location name ip vendor model /], } );
|
->order_by( [qw/ location name ip vendor model /] )->hri->all;
|
||||||
return unless $set->count;
|
|
||||||
|
return unless scalar @results;
|
||||||
|
|
||||||
if ( request->is_ajax ) {
|
if ( request->is_ajax ) {
|
||||||
template 'ajax/report/devicebylocation.tt', { results => $set, },
|
my $results = to_json( \@results );
|
||||||
|
template 'ajax/report/devicebylocation.tt', { results => $results },
|
||||||
{ layout => undef };
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||||
template 'ajax/report/devicebylocation_csv.tt', { results => $set, },
|
template 'ajax/report/devicebylocation_csv.tt',
|
||||||
{ layout => undef };
|
{ results => \@results },
|
||||||
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
true;
|
1;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<table class="table table-bordered table-condensed table-striped nd_floatinghead">
|
<table id="data-table" class="table table-striped table-bordered nd_floatinghead" width="100%" cellspacing="0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="nd_center-cell">Location</th>
|
<th class="nd_center-cell">Location</th>
|
||||||
@@ -8,32 +8,47 @@
|
|||||||
<th class="nd_center-cell">Model</th>
|
<th class="nd_center-cell">Model</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
</tbody>
|
|
||||||
[% WHILE (row = results.next) %]
|
|
||||||
[% NEXT UNLESS row.vendor AND row.model %]
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
[% IF row.location %]
|
|
||||||
<a href="[% search_device %]&q=[% row.location | uri %]&location=[% row.location | uri %]">
|
|
||||||
[% row.location | html_entity %]</a>
|
|
||||||
[% ELSE %]
|
|
||||||
[Not Set]
|
|
||||||
[% END %]
|
|
||||||
</td>
|
|
||||||
<td><a href="[% uri_for('/device') %]?q=[% row.ip | uri %]">[% row.dns || row.ip | html_entity %]</a></td>
|
|
||||||
<td><a href="[% search_device %]&q=[% row.name | uri %]&name=[% row.name | uri %]">
|
|
||||||
[% row.name | html_entity %]</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="[% search_device %]&q=[% row.vendor | uri %]&vendor=[% row.vendor | uri %]">
|
|
||||||
[% row.vendor | html_entity %]</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="[% search_device %]&q=[% row.model | uri %]&model=[% row.model | uri %]">
|
|
||||||
[% row.model | html_entity %]</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
[% END %]
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
var table = $('#data-table').dataTable({
|
||||||
|
"deferRender": true,
|
||||||
|
"data": [% results %],
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
data: 'location',
|
||||||
|
render: function(data, type, row, meta) {
|
||||||
|
if (data) {
|
||||||
|
return '<a href="[% search_device %]&q=' + data + '&location=' + data + '">' + data + '</a>';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return '[Not Set]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
data: 'ip',
|
||||||
|
render: function(data, type, row, meta) {
|
||||||
|
return '<a href="[% uri_for('/device') %]?q=' + data + '">' + (row.dns || row.ip) + '</a>';
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
data: 'name',
|
||||||
|
render: function(data, type, row, meta) {
|
||||||
|
return '<a href="[% search_device %]&q=' + data + '&model=' + data + '">' + data + '</a>';
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
data: 'vendor',
|
||||||
|
render: function(data, type, row, meta) {
|
||||||
|
return '<a href="[% search_device %]&q=' + data + '&model=' + data + '">' + data + '</a>';
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
data: 'model',
|
||||||
|
render: function(data, type, row, meta) {
|
||||||
|
return '<a href="[% search_device %]&q=' + data + '&model=' + data + '">' + data + '</a>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[% USE CSV -%]
|
[% USE CSV -%]
|
||||||
[% CSV.dump([ 'Location' 'Device' 'System Name' 'Vendor' 'Model' ]) %]
|
[% CSV.dump([ 'Location' 'Device' 'System Name' 'Vendor' 'Model' ]) %]
|
||||||
|
|
||||||
[% WHILE (row = results.next) %]
|
[% FOREACH row IN results %]
|
||||||
[% mylist = [] %]
|
[% mylist = [] %]
|
||||||
[% device = row.dns || row.ip %]
|
[% device = row.dns || row.ip %]
|
||||||
[% FOREACH col IN [ row.location device row.name row.vendor row.model ] %]
|
[% FOREACH col IN [ row.location device row.name row.vendor row.model ] %]
|
||||||
|
|||||||
Reference in New Issue
Block a user