From e23594b0418e603c1a33f54bcc8692f9e6d9ca1f Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 23 Dec 2017 23:42:17 +0000 Subject: [PATCH] wooo device group selection is working --- .../Netdisco/Web/Plugin/Device/Neighbors.pm | 56 ++++++++++--------- share/public/css/netdisco.css | 6 +- share/views/sidebar/device/netmap.tt | 2 +- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index 5d9f6aa3..95bfaf43 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC; use Dancer::Plugin::Auth::Extensible; use List::MoreUtils (); +use App::Netdisco::Util::Permission 'check_acl_only'; use App::Netdisco::Web::Plugin; register_device_tab({ tag => 'netmap', label => 'Neighbors' }); @@ -49,11 +50,6 @@ ajax '/ajax/data/device/netmappositions' => require_login sub { } }; -# q -# vlan -# mapshow=all,neighbors,only - -# devgrp[] # colorgroups # dynamicsize @@ -100,9 +96,6 @@ ajax '/ajax/data/device/netmap' => require_login sub { my @links = $rs->all; # because we have to run this twice foreach my $l (@links) { - next if (($mapshow eq 'neighbors') - and (($l->{left_ip} ne $qdev->ip) and ($l->{right_ip} ne $qdev->ip))); - push @{$v3data{'links'}}, { FROMID => $l->{left_ip}, TOID => $l->{right_ip}, @@ -119,46 +112,55 @@ ajax '/ajax/data/device/netmap' => require_login sub { vlan => ($vlan || 0)}); my $pos_for = from_json( $posrow ? $posrow->positions : '{}' ); - my @devices = schema('netdisco')->resultset('Device')->search({}, { - result_class => 'DBIx::Class::ResultClass::HashRefInflator', + my $devices = schema('netdisco')->resultset('Device')->search({}, { columns => ['ip', 'dns', 'name'], '+select' => [\'row_number() over()'], '+as' => ['row_number'], - })->all; + }); - foreach my $device (@devices) { - next unless $ok_dev{$device->{ip}}; # vlan filter's effect + NODE: while (my $device = $devices->next) { + # if in neighbors or vlan mode then use %ok_dev to filter + next NODE if (($mapshow eq 'neighbors') or $vlan) + and (not $ok_dev{$device->ip}); - $id_for{$device->{ip}} = $device->{'row_number'}; - (my $name = ($device->{dns} || lc($device->{name}) || $device->{ip})) =~ s/$domain$//; + # if in only mode then use ACLs to filter + if ($mapshow eq 'only') { + my $devgrp = (ref [] eq ref param('devgrp') ? param('devgrp') : [param('devgrp')]); + next NODE unless scalar grep { check_acl_only($device, $_) } + grep { defined } + map { setting('host_groups')->{$_} } + grep { defined } + @{ $devgrp }; + } - $v3data{nodes}->{ ($device->{row_number} - 1) } = { - ID => $device->{ip}, + $id_for{$device->ip} = $device->get_column('row_number'); + (my $name = ($device->dns || lc($device->name) || $device->ip)) =~ s/$domain$//; + + $v3data{nodes}->{ ($device->get_column('row_number') - 1) } = { + ID => $device->ip, SIZEVALUE => 3000, (param('colorgroups') ? (COLORVALUE => 10) : ()), LABEL => $name, }; - if (exists $pos_for->{$device->{ip}}) { - my $node = $v3data{nodes}->{ ($device->{row_number} - 1) }; + if (exists $pos_for->{$device->ip}) { + my $node = $v3data{nodes}->{ ($device->get_column('row_number') - 1) }; $node->{'fixed'} = 1; - $node->{'x'} = $pos_for->{$device->{ip}}->{'x'}; - $node->{'y'} = $pos_for->{$device->{ip}}->{'y'}; + $node->{'x'} = $pos_for->{$device->ip}->{'x'}; + $node->{'y'} = $pos_for->{$device->ip}->{'y'}; } else { ++$v3data{'newnodes'}; } - $v3data{'centernode'} = $device->{ip} - if $qdev and $qdev->in_storage and $device->{ip} eq $qdev->ip; + $v3data{'centernode'} = $device->ip + if $qdev and $qdev->in_storage and $device->ip eq $qdev->ip; - push @{$v4data{'nodes'}}, { index => ($device->{row_number} - 1) }; + push @{$v4data{'nodes'}}, { index => ($device->get_column('row_number') - 1) }; } # go back and do v4 links now we have row IDs foreach my $l (@links) { - next if (($mapshow eq 'neighbors') - and (($l->{left_ip} ne $qdev->ip) and ($l->{right_ip} ne $qdev->ip))); - + next unless $id_for{$l->{left_ip}} and $id_for{$l->{right_ip}}; push @{$v4data{'links'}}, { source => ($id_for{$l->{left_ip}} - 1), target => ($id_for{$l->{right_ip}} - 1), diff --git a/share/public/css/netdisco.css b/share/public/css/netdisco.css index f5553fbf..1783160f 100644 --- a/share/public/css/netdisco.css +++ b/share/public/css/netdisco.css @@ -454,7 +454,7 @@ td > form.nd_inline-form { vertical-align: text-bottom; } #nd_vlan-entry { - width: 57px; + width: 56px; } /* fixup for prepended checkbox in sidebar */ @@ -634,8 +634,8 @@ form .clearfix.success input { } .nd_netmap-sidebar { - /* margin-top: 7px; */ - margin-left: -9px; + margin-top: 0px; + margin-left: -8px; } .nd_netmap-sidebar > .input-prepend { diff --git a/share/views/sidebar/device/netmap.tt b/share/views/sidebar/device/netmap.tt index d6240cac..1081c3cb 100644 --- a/share/views/sidebar/device/netmap.tt +++ b/share/views/sidebar/device/netmap.tt @@ -85,7 +85,7 @@