add a new tab to device -> vlans (#483)

* first steps for vlan tab

* export sort_vlans, use strict/warnings

* update manifest, get worker closer to functioning

* remove ie 9 script & extra ./th

* make it work

* cleanup

* readd internet explorer code

* start for csv output

* move things to debug logging instead of info

* use message which was discussed

* fix for address table sorting

* link os

* final touches thx to ollyg

* fetch origin/master

* VLAN is the preferred style for user interface usage

* does a missing libexpat-dev make travis builds complain?

* Revert "does a missing libexpat-dev make travis builds complain?"

This reverts commit 0cebc66f42708ff0f946213aab4bcbcc1b1b1379.
This commit is contained in:
nick n
2019-01-14 22:57:37 +01:00
committed by Oliver Gorwits
parent c416e2505b
commit 6a36baa961
9 changed files with 85 additions and 4 deletions

View File

@@ -151,6 +151,7 @@ lib/App/Netdisco/Web/Plugin/Device/Details.pm
lib/App/Netdisco/Web/Plugin/Device/Modules.pm
lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm
lib/App/Netdisco/Web/Plugin/Device/Ports.pm
lib/App/Netdisco/Web/Plugin/Device/Vlans.pm
lib/App/Netdisco/Web/Plugin/Inventory.pm
lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm
lib/App/Netdisco/Web/Plugin/Report/ApClients.pm
@@ -391,6 +392,8 @@ share/views/ajax/device/modules.tt
share/views/ajax/device/netmap.tt
share/views/ajax/device/ports.tt
share/views/ajax/device/ports_csv.tt
share/views/ajax/device/vlans.tt
share/views/ajax/device/vlans_csv.tt
share/views/ajax/report/apchanneldist.tt
share/views/ajax/report/apchanneldist_csv.tt
share/views/ajax/report/apclients.tt

View File

@@ -0,0 +1,36 @@
package App::Netdisco::Web::Plugin::Device::Vlans;
use strict;
use warnings;
use Dancer ':syntax';
use Dancer::Plugin::Ajax;
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_device_tab({ tag => 'vlans', label => 'VLANs', provides_csv => 1 });
get '/ajax/content/device/vlans' => require_login sub {
my $q = param('q');
my $device = schema('netdisco')->resultset('Device')
->search_for_device($q) or send_error('Bad device', 400);
my @results = $device->vlans->search( {}, { order_by => 'vlan' } )->hri->all;
return unless scalar @results;
if (request->is_ajax) {
my $json = to_json( \@results );
template 'ajax/device/vlans.tt', { results => $json },
{ layout => undef };
}
else {
header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/device/vlans_csv.tt', { results => \@results },
{ layout => undef };
}
};
true;

View File

@@ -87,6 +87,7 @@ web_plugins:
- Device::Modules
- Device::Neighbors
- Device::Addresses
- Device::Vlans
extra_web_plugins: []
sidebar_defaults:
search_node:

View File

@@ -0,0 +1,31 @@
<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th>VLAN ID</th>
<th>VLAN Name</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$(document).ready(function() {
var table = $('#data-table').dataTable({
"deferRender": true,
"data": [% results %],
"columns": [
{
"data": 'vlan',
"render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + data + '</a>';
}
}, {
"data": 'description',
"render": function(data, type, row, meta) {
return '<a href="[% uri_for('/search') %]?tab=vlan&q=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
}
}
],
[% INCLUDE 'ajax/datatabledefaults.tt' -%]
});
});
</script>

View File

@@ -0,0 +1,10 @@
[% USE CSV -%]
[% CSV.dump([ 'VLAN ID' 'VLAN Name' ]) %]
[% FOREACH row IN results %]
[% mylist = [] %]
[% mylist.push(row.vlan) %]
[% mylist.push(row.description) %]
[% CSV.dump(mylist) %]
[% END %]

View File

@@ -4,7 +4,7 @@
<th>Status</th>
<th>Name</th>
<th>Port</th>
<th>Vlan</th>
<th>VLAN</th>
<th>Speed</th>
<th>Last Change</th>
</tr>

View File

@@ -1,5 +1,5 @@
[% USE CSV -%]
[% CSV.dump([ 'Name' 'Port' 'Description' 'Vlan' ]) %]
[% CSV.dump([ 'Name' 'Port' 'Description' 'VLAN' ]) %]
[% FOREACH row IN results %]
[% mylist = [] %]

View File

@@ -1,7 +1,7 @@
<table id="vs-data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th>Vlan</th>
<th>VLAN</th>
<th>Device</th>
<th>Description</th>
<th>Model</th>

View File

@@ -1,5 +1,5 @@
[% USE CSV -%]
[% CSV.dump([ 'Vlan' 'Device' 'Description' 'Model' 'OS' 'Vendor' ]) %]
[% CSV.dump([ 'VLAN' 'Device' 'Description' 'Model' 'OS' 'Vendor' ]) %]
[% FOREACH row IN results %]
[% mylist = [] %]