diff --git a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index d18265eb..52bb588b 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -25,6 +25,19 @@ ajax '/ajax/data/device/netmappositions' => require_login sub { my $vlan = param('vlan'); undef $vlan if (defined $vlan and $vlan !~ m/^\d+$/); + my $mapshow = param('mapshow'); + return if !defined $mapshow or $mapshow !~ m/^(?:all|only)$/; + + # list of groups selected by user and passed in param + my $devgrp = (ref [] eq ref param('devgrp') ? param('devgrp') : [param('devgrp')]); + # list of groups validated as real host groups and named host groups + my @hgrplist = List::MoreUtils::uniq + grep { exists setting('host_group_displaynames')->{$_} } + grep { exists setting('host_groups')->{$_} } + grep { defined } @{ $devgrp }; + return if $mapshow eq 'only' and 0 == scalar @hgrplist; + push(@hgrplist, '__ANY__') if 0 == scalar @hgrplist; + my %clean = (); POSITION: foreach my $pos (@$positions) { next unless ref {} eq ref $pos; @@ -34,24 +47,23 @@ ajax '/ajax/data/device/netmappositions' => require_login sub { } $clean{$pos->{ID}} = { x => $pos->{x}, y => $pos->{y} }; } - return unless scalar keys %clean; + my $posrow = schema('netdisco')->resultset('NetmapPositions')->find({ - device_groups => \[ '= ?', [device_groups => [sort (List::MoreUtils::uniq( '__ANY__' )) ]] ], + device_groups => \[ '= ?', [device_groups => [sort @hgrplist]] ], vlan => ($vlan || 0)}); if ($posrow) { $posrow->update({ positions => to_json(\%clean) }); } else { schema('netdisco')->resultset('NetmapPositions')->create({ - device_groups => [sort (List::MoreUtils::uniq( '__ANY__' )) ], + device_groups => [sort @hgrplist], vlan => ($vlan || 0), positions => to_json(\%clean), }); } }; -# colorgroups # dynamicsize ajax '/ajax/data/device/netmap' => require_login sub { @@ -66,6 +78,14 @@ ajax '/ajax/data/device/netmap' => require_login sub { $mapshow = 'neighbors' if $mapshow !~ m/^(?:all|neighbors|only)$/; $mapshow = 'all' unless $qdev->in_storage; + # list of groups selected by user and passed in param + my $devgrp = (ref [] eq ref param('devgrp') ? param('devgrp') : [param('devgrp')]); + # list of groups validated as real host groups and named host groups + my @hgrplist = List::MoreUtils::uniq + grep { exists setting('host_group_displaynames')->{$_} } + grep { exists setting('host_groups')->{$_} } + grep { defined } @{ $devgrp }; + my %id_for = (); my %ok_dev = (); my %v3data = ( nodes => {}, links => [] ); @@ -109,7 +129,8 @@ ajax '/ajax/data/device/netmap' => require_login sub { # DEVICES (NODES) my $posrow = schema('netdisco')->resultset('NetmapPositions')->find({ - device_groups => \[ '= ?', [device_groups => [sort (List::MoreUtils::uniq( '__ANY__' )) ]] ], + device_groups => \[ '= ?', + [device_groups => [$mapshow eq 'all' ? '__ANY__' : (sort @hgrplist)]] ], vlan => ($vlan || 0)}); my $pos_for = from_json( $posrow ? $posrow->positions : '{}' ); @@ -118,13 +139,6 @@ ajax '/ajax/data/device/netmap' => require_login sub { '+select' => [\'row_number() over()'], '+as' => ['row_number'], }); - # list of groups selected by user and passed in param - my $devgrp = (ref [] eq ref param('devgrp') ? param('devgrp') : [param('devgrp')]); - # list of groups validated as real host groups and named host groups - my @hgrplist = grep { exists setting('host_group_displaynames')->{$_} } - grep { exists setting('host_groups')->{$_} } - grep { defined } @{ $devgrp }; - DEVICE: while (my $device = $devices->next) { # if in neighbors or vlan mode then use %ok_dev to filter next DEVICE if (($mapshow eq 'neighbors') or $vlan) diff --git a/share/views/ajax/device/netmap.tt b/share/views/ajax/device/netmap.tt index 57547d87..554bbe39 100644 --- a/share/views/ajax/device/netmap.tt +++ b/share/views/ajax/device/netmap.tt @@ -70,12 +70,11 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m if (mapdata['v3']['newnodes']) { $.post( '[% uri_for('/ajax/data/device/netmappositions') %]' - ,'vlan=[% params.vlan %]&positions=' + JSON.stringify(graph.positions()) + ,$("#nd_vlan-entry, #nd_devgrp-select, input[name='mapshow']").serialize() + + '&positions=' + JSON.stringify(graph.positions()) ); } - // else { - // graph.zoomToFit(); - // } + // else { graph.zoomToFit() } graph.inspect().main.nodes.on('mouseup.dragall', function(n) { graph['nd2']['dragging'] = false; diff --git a/share/views/js/device.js b/share/views/js/device.js index 5ec3838f..ffcfbffb 100644 --- a/share/views/js/device.js +++ b/share/views/js/device.js @@ -123,7 +123,8 @@ // if user enters vlan but does not submit this will save wrong data $.post( '[% uri_for('/ajax/data/device/netmappositions') %]' - ,'vlan=' + $('#nd_vlan-entry').val() + '&positions=' + JSON.stringify(graph.positions()) + ,$("#nd_vlan-entry, #nd_devgrp-select, input[name='mapshow']").serialize() + + '&positions=' + JSON.stringify(graph.positions()) ); }); $('#nd_netmap-zoomtodevice').on('click', function(event) { diff --git a/share/views/sidebar/device/netmap.tt b/share/views/sidebar/device/netmap.tt index 1081c3cb..dc9f50f5 100644 --- a/share/views/sidebar/device/netmap.tt +++ b/share/views/sidebar/device/netmap.tt @@ -70,7 +70,7 @@ [% IF devgrp_list.size %]