[#66] Fix display of vlan membership
This commit is contained in:
		| @@ -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: | ||||
|   | ||||
| @@ -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 | ||||
|         }, | ||||
|       }); | ||||
|   | ||||
| @@ -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' }, | ||||
|   | ||||
| @@ -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? | ||||
|   | ||||
| @@ -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', | ||||
|     ); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user