#882 option to display vlan names instead of numbers in device ports table
This commit is contained in:
@@ -203,6 +203,26 @@ __PACKAGE__->might_have(
|
||||
}
|
||||
);
|
||||
|
||||
=head2 native_vlan
|
||||
|
||||
Returns the row from the C<device_vlan> table corresponding to the native
|
||||
vlan of this port.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
native_vlan => 'App::Netdisco::DB::Result::DeviceVlan',
|
||||
sub {
|
||||
my $args = shift;
|
||||
return {
|
||||
"$args->{foreign_alias}.ip" =>
|
||||
{ '-ident' => "$args->{self_alias}.ip" },
|
||||
"$args->{self_alias}.vlan" =>
|
||||
{ '=' => \"cast($args->{foreign_alias}.vlan as text)" }
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
=head2 agg_master
|
||||
|
||||
Returns another row from the C<device_port> table if this port is slave
|
||||
|
||||
@@ -60,14 +60,14 @@ __PACKAGE__->belongs_to( port => 'App::Netdisco::DB::Result::DevicePort', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port',
|
||||
});
|
||||
|
||||
=head2 vlan
|
||||
=head2 vlan_entry
|
||||
|
||||
Returns the entry from the C<device_vlan> table describing this VLAN in
|
||||
detail, typically in order that the C<name> can be retrieved.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( vlan => 'App::Netdisco::DB::Result::DeviceVlan', {
|
||||
__PACKAGE__->belongs_to( vlan_entry => 'App::Netdisco::DB::Result::DeviceVlan', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan',
|
||||
});
|
||||
|
||||
|
||||
@@ -108,10 +108,11 @@ get '/ajax/content/device/ports' => require_login sub {
|
||||
my $vlans = $set->search({}, {
|
||||
select => [
|
||||
'port',
|
||||
{ array_agg => 'port_vlans.vlan', -as => 'vlan_set' },
|
||||
{ count => 'port_vlans.vlan', -as => 'vlan_count' },
|
||||
{ array_agg => 'port_vlans.vlan', -as => 'vlan_set' },
|
||||
{ array_agg => 'vlan_entry.description', -as => 'vlan_name_set' },
|
||||
],
|
||||
join => 'port_vlans',
|
||||
join => {'port_vlans' => 'vlan_entry'},
|
||||
group_by => 'me.port',
|
||||
});
|
||||
|
||||
@@ -119,12 +120,21 @@ get '/ajax/content/device/ports' => require_login sub {
|
||||
$vlans = { map {(
|
||||
$_->port => {
|
||||
# DBIC smart enough to work out this should be an arrayref :)
|
||||
vlan_set => $_->get_column('vlan_set'),
|
||||
vlan_count => $_->get_column('vlan_count'),
|
||||
vlan_set => $_->get_column('vlan_set'),
|
||||
vlan_name_set => $_->get_column('vlan_name_set'),
|
||||
},
|
||||
)} $vlans->all };
|
||||
}
|
||||
|
||||
if (param('c_vlan_names')) {
|
||||
$set = $set->search({}, {
|
||||
'join' => 'native_vlan',
|
||||
'+select' => [qw/native_vlan.description/],
|
||||
'+as' => [qw/native_vlan_name/],
|
||||
});
|
||||
}
|
||||
|
||||
# get aggregate master status (self join)
|
||||
$set = $set->search({}, {
|
||||
'join' => 'agg_master',
|
||||
|
||||
@@ -126,12 +126,13 @@ sidebar_defaults:
|
||||
c_mtu: { label: 'MTU', default: null, idx: 12 }
|
||||
c_pvid: { label: 'Native VLAN', default: checked, idx: 13 }
|
||||
c_vmember: { label: 'VLAN Membership', default: checked, idx: 14 }
|
||||
c_power: { label: 'PoE', default: null, idx: 15 }
|
||||
c_ssid: { label: 'SSID', default: null, idx: 16 }
|
||||
c_nodes: { label: 'Connected Nodes', default: null, idx: 17 }
|
||||
c_neighbors: { label: 'Connected Devices', default: checked, idx: 18 }
|
||||
c_stp: { label: 'Spanning Tree', default: null, idx: 19 }
|
||||
c_up: { label: 'Status', default: null, idx: 20 }
|
||||
c_vlan_names: { label: 'use VLAN Names', default: null, idx: 15 }
|
||||
c_power: { label: 'PoE', default: null, idx: 16 }
|
||||
c_ssid: { label: 'SSID', default: null, idx: 17 }
|
||||
c_nodes: { label: 'Connected Nodes', default: null, idx: 18 }
|
||||
c_neighbors: { label: 'Connected Devices', default: checked, idx: 19 }
|
||||
c_stp: { label: 'Spanning Tree', default: null, idx: 20 }
|
||||
c_up: { label: 'Status', default: null, idx: 21 }
|
||||
mac_format: { default: IEEE }
|
||||
n_inventory: { label: 'Remote Inventory', default: checked, idx: 0 }
|
||||
n_detailed_inventory: { label: 'Remote Advertisement', default: null, idx: 1 }
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
[% FOREACH item IN settings.port_columns %]
|
||||
[% NEXT IF item.name == 'c_admin' %]
|
||||
[% NEXT IF item.name == 'c_admin' OR item.name == 'c_vlan_names' %]
|
||||
[% NEXT IF item.name == 'c_nodes' AND params.c_nodes AND params.c_neighbors %]
|
||||
[% NEXT UNLESS params.${item.name} %]
|
||||
[% SET th_class = '' %]
|
||||
@@ -204,8 +204,13 @@
|
||||
<td>
|
||||
[% IF row.vlan AND row.vlan > 0 %]
|
||||
<a class="nd_linkcell"
|
||||
href="[% uri_for('/search') | none %]?tab=vlan&q=[% row.vlan | uri %]">
|
||||
[% row.vlan | html_entity %]</a>
|
||||
[% IF params.c_vlan_names %]
|
||||
href="[% uri_for('/search') | none %]?tab=vlan&q=[% row.get_column('native_vlan_name') | uri %]">
|
||||
[% row.get_column('native_vlan_name') | html_entity %]</a>
|
||||
[% ELSE %]
|
||||
href="[% uri_for('/search') | none %]?tab=vlan&q=[% row.vlan | uri %]">
|
||||
[% row.vlan | html_entity %]</a>
|
||||
[% END %]
|
||||
[% END %]
|
||||
</td>
|
||||
[% END %]
|
||||
@@ -215,21 +220,20 @@
|
||||
<td>
|
||||
[% IF vlans.$portname.vlan_count <= settings.devport_vlan_limit %]
|
||||
[% SET vlan_count = vlans.$portname.vlan_count %]
|
||||
[% SET output = '' %]
|
||||
[% FOREACH vlan IN vlans.$portname.vlan_set.nsort %]
|
||||
[% IF vlan == 0 %][% SET vlan_count = (vlan_count - 1) %][% NEXT %][% END %]
|
||||
[% SET output = output _
|
||||
'<a href="' _ uri_for('/search') _ '?tab=vlan&q=' _ vlan _ '">' _ vlan _ '</a>' %]
|
||||
[% IF NOT loop.last %][% SET output = output _ ', ' %][% END %]
|
||||
[% IF params.c_vlan_names %][% SET vlanlist = vlans.$portname.vlan_name_set.sort %]
|
||||
[% ELSE %][% SET vlanlist = vlans.$portname.vlan_set.nsort %][% END %]
|
||||
[% IF vlan_count > 10 %] [%# TODO make this a settable variable %]
|
||||
<div class="nd_vlan-total">([% vlan_count %])</div><span class="nd_linkcell nd_collapse-vlans">
|
||||
<div class="nd_arrow-up-down-left icon-chevron-up icon-large"></div>Show VLANs</span>
|
||||
<div class="nd_collapsing nd_collapse-pre-hidden">
|
||||
[% END %]
|
||||
[% FOREACH vlan IN vlanlist %]
|
||||
<a href="[% uri_for('/search') %]?tab=vlan&q=[% vlan | uri %]">[% vlan | html_entity %]</a>
|
||||
[% ', ' IF NOT loop.last %]
|
||||
[% END %]
|
||||
[% IF vlan_count > 10 %] [%# TODO make this a settable variable %]
|
||||
[% SET output = '<div class="nd_vlan-total">(' _ vlan_count
|
||||
_ ')</div><span class="nd_linkcell nd_collapse-vlans">
|
||||
<div class="nd_arrow-up-down-left icon-chevron-up icon-large"></div>Show VLANs</span>
|
||||
<div class="nd_collapsing nd_collapse-pre-hidden">' _ output %]
|
||||
[% SET output = output _ '</div>' %]
|
||||
</div>
|
||||
[% END %]
|
||||
[% output | none %]
|
||||
[% ELSE %]
|
||||
<i class="icon-asterisk text-warning"></i> ([% vlans.$portname.vlan_count %] is too many to list)
|
||||
[% END %]
|
||||
|
||||
Reference in New Issue
Block a user