[#66] Fix display of vlan membership

This commit is contained in:
Oliver Gorwits
2014-01-11 09:44:35 +00:00
parent 1e0c6b9598
commit 862f2ba5b1
10 changed files with 53 additions and 63 deletions

View File

@@ -80,16 +80,29 @@ Returns the Device table entry to which the given Port is related.
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
=head2 vlans
=head2 port_vlans
Returns the set of C<device_port_vlan> entries associated with this Port.
These will be both tagged and untagged. Use this relation in search conditions.
These will be both tagged and untagged. See also C<port_vlans_tagged> and
C<tagged_vlans>.
See also C<all_port_vlans>.
=cut
__PACKAGE__->has_many( vlans => 'App::Netdisco::DB::Result::DevicePortVlan',
__PACKAGE__->has_many( port_vlans => 'App::Netdisco::DB::Result::DevicePortVlan',
{ 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' } );
=head2 all_port_vlans
Returns the set of C<device_port_vlan> entries associated with this Port.
These will be both tagged and untagged. Use this relation when prefetching related
C<device_port_vlan> rows.
See also C<port_vlans>.
=cut
__PACKAGE__->has_many( all_port_vlans => 'App::Netdisco::DB::Result::DevicePortVlan',
{ 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' } );
=head2 nodes / active_nodes / nodes_with_age / active_nodes_with_age
@@ -183,39 +196,17 @@ __PACKAGE__->has_many( neighbor_alias => 'App::Netdisco::DB::Result::DeviceIp',
{ join_type => 'LEFT' },
);
=head2 port_vlans_tagged
=head2 vlans
Returns a set of rows from the C<device_port_vlan> table relating to this
port, where the VLANs are all tagged.
=cut
__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::DevicePortVlan',
sub {
my $args = shift;
return {
"$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
"$args->{foreign_alias}.port" => { -ident => "$args->{self_alias}.port" },
-not_bool => "$args->{foreign_alias}.native",
};
},
{
join_type => 'LEFT',
cascade_copy => 0, cascade_update => 0, cascade_delete => 0,
},
);
=head2 tagged_vlans
As compared to C<port_vlans_tagged>, this relationship returns a set of VLAN
As compared to C<port_vlans>, this relationship returns a set of VLAN
row objects for the VLANs on the given port, which might be more useful if you
want to find out details such as the VLAN name.
See also C<tagged_vlans_count>.
See also C<vlan_count>.
=cut
__PACKAGE__->many_to_many( tagged_vlans => 'port_vlans_tagged', 'vlan' );
__PACKAGE__->many_to_many( vlans => 'all_port_vlans', 'vlan' );
=head2 oui
@@ -259,26 +250,26 @@ sub neighbor {
=head2 native
An alias for the C<pvid> column, which stores the PVID (that is, the VLAN
An alias for the C<vlan> column, which stores the PVID (that is, the VLAN
ID assigned to untagged frames received on the port).
=cut
sub native { return (shift)->pvid }
sub native { return (shift)->vlan }
=head2 tagged_vlans_count
=head2 vlan_count
Returns the number of tagged VLANs active on this device port. Enable this
column by applying the C<with_vlan_count()> modifier to C<search()>.
Returns the number of VLANs active on this device port. Enable this column by
applying the C<with_vlan_count()> modifier to C<search()>.
=cut
sub tagged_vlans_count { return (shift)->get_column('tagged_vlans_count') }
sub vlan_count { return (shift)->get_column('vlan_count') }
=head2 lastchange_stamp
Formatted version of the C<lastchange> field, accurate to the minute. Enable
this column by applying the C<with_vlan_count()> modifier to C<search()>.
this column by applying the C<with_times()> modifier to C<search()>.
The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T>
between the date stamp and time stamp. That is:

View File

@@ -111,7 +111,7 @@ will add the following additional synthesized columns to the result set:
=over 4
=item tagged_vlans_count
=item vlan_count
=back
@@ -124,15 +124,14 @@ sub with_vlan_count {
->search_rs($cond, $attrs)
->search({},
{
'+columns' => { tagged_vlans_count =>
'+columns' => { vlan_count =>
$rs->result_source->schema->resultset('DevicePortVlan')
->search(
{
'dpvt.ip' => { -ident => 'me.ip' },
'dpvt.port' => { -ident => 'me.port' },
-not_bool => { -ident => 'dpvt.native' },
'dpv.ip' => { -ident => 'me.ip' },
'dpv.port' => { -ident => 'me.port' },
},
{ alias => 'dpvt' }
{ alias => 'dpv' }
)->count_rs->as_query
},
});

View File

@@ -21,8 +21,8 @@ hook 'before' => sub {
{ name => 'c_speed', label => 'Speed', default => '' },
{ name => 'c_mac', label => 'Port MAC', default => '' },
{ name => 'c_mtu', label => 'MTU', default => '' },
{ name => 'c_vlan', label => 'Native VLAN', default => 'on' },
{ name => 'c_vmember', label => 'Tagged VLANs', default => 'on' },
{ name => 'c_pvid', label => 'Native VLAN', default => 'on' },
{ name => 'c_vmember', label => 'VLAN Membership', default => 'on' },
{ name => 'c_power', label => 'PoE', default => '' },
{ name => 'c_nodes', label => 'Connected Nodes', default => '' },
{ name => 'c_neighbors', label => 'Connected Devices', default => 'on' },

View File

@@ -27,18 +27,18 @@ get '/ajax/content/device/ports' => require_login sub {
if (param('invert')) {
$set = $set->search({
'me.vlan' => { '!=' => $f },
'port_vlans_tagged.vlan' => [
'port_vlans.vlan' => [
'-or' => { '!=' => $f }, { '=' => undef }
],
}, { join => 'port_vlans_tagged' });
}, { join => 'port_vlans' });
}
else {
$set = $set->search({
-or => {
'me.vlan' => $f,
'port_vlans_tagged.vlan' => $f,
'port_vlans.vlan' => $f,
},
}, { join => 'port_vlans_tagged' });
}, { join => 'port_vlans' });
}
return unless $set->count;
@@ -116,7 +116,7 @@ get '/ajax/content/device/ports' => require_login sub {
# run single collapsed query for all relations, but only if we're not
# also fetching archived data (tests show it's better this way)
$set = $set->search_rs({}, { prefetch => [{ port_vlans_tagged => 'vlan'}] })
$set = $set->search_rs({}, { prefetch => 'all_port_vlans' })
if param('c_vmember') and not (param('c_nodes') and param('n_archived'));
# what kind of nodes are we interested in?

View File

@@ -18,7 +18,7 @@ ajax '/ajax/portcontrol' => require_role port_control => sub {
'contact' => 'contact',
'c_port' => 'portcontrol',
'c_name' => 'portname',
'c_vlan' => 'vlan',
'c_pvid' => 'vlan',
'c_power' => 'power',
);

View File

@@ -146,7 +146,7 @@ $(document).ready(function() {
else if (nl) {
event.preventDefault();
if (td.data('field') == 'c_vlan') {
if (td.data('field') == 'c_pvid') {
$('#nd_portlog').one('hidden', function() {
port_control(cell); // save
});

View File

@@ -129,10 +129,10 @@
<td>[% row.mtu | html_entity %]</td>
[% END %]
[% IF params.c_vlan %]
[% IF params.c_pvid %]
[% IF user_can_port_control AND params.c_admin %]
<td class="nd_editable-cell" contenteditable="true" data-default="[% row.vlan | html_entity %]"
data-field="c_vlan" data-for-device="[% device.ip | html_entity %]" data-for-port="[% row.port | html_entity %]">
data-field="c_pvid" data-for-device="[% device.ip | html_entity %]" data-for-port="[% row.port | html_entity %]">
<i class="icon-edit nd_edit-icon"></i>
<div class="nd_editable-cell-content">
[% IF row.vlan %][% row.vlan | html_entity %][% END %]
@@ -149,17 +149,17 @@
[% IF params.c_vmember %]
<td>
[% IF row.tagged_vlans_count %]
[% IF row.vlan_count %]
[% SET output = '' %]
[% SET vlanlist = [] %]
[% FOREACH vlan IN row.tagged_vlans %][% vlanlist.push(vlan.vlan) %][% END %]
[% FOREACH vlan IN row.all_port_vlans %][% vlanlist.push(vlan.get_column('vlan')) %][% END %]
[% FOREACH vlan IN vlanlist.nsort %]
[% SET output = output _
'<a href="' _ uri_for('/search') _ '?tab=vlan&q=' _ vlan _ '">' _ vlan _ '</a>' %]
[% SET output = output _ ', ' IF NOT loop.last %]
[% END %]
[% IF row.tagged_vlans_count > 10 %] [%# TODO make this a settable variable %]
[% SET output = '<div class="nd_vlan-total">(' _ row.tagged_vlans_count
[% IF row.vlan_count > 10 %] [%# TODO make this a settable variable %]
[% SET output = '<div class="nd_vlan-total">(' _ row.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 %]

View File

@@ -95,15 +95,15 @@
[% myport.push(row.mtu) %]
[% END %]
[% IF params.c_vlan %]
[% IF params.c_pvid %]
[% myport.push(row.vlan) %]
[% END %]
[% IF params.c_vmember %]
[% IF row.tagged_vlans_count %]
[% IF row.vlan_count %]
[% SET output = '' %]
[% SET vlanlist = [] %]
[% FOREACH vlan IN row.tagged_vlans %][% vlanlist.push(vlan.vlan) %][% END %]
[% FOREACH vlan IN row.all_port_vlans %][% vlanlist.push(vlan.get_column('vlan')) %][% END %]
[% FOREACH vlan IN vlanlist.nsort %]
[% SET output = output _ ',' IF NOT loop.first %]
[% SET output = output _ vlan %]