wooo device group selection is working

This commit is contained in:
Oliver Gorwits
2017-12-23 23:42:17 +00:00
parent b1b22c9811
commit e23594b041
3 changed files with 33 additions and 31 deletions

View File

@@ -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),

View File

@@ -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 {

View File

@@ -85,7 +85,7 @@
<div id="nd_vlan-label" class="control-group">
<div class="controls">
<label><span id="nd_vlan-label-text">Carrying VLAN: </span>
<input name="vlan" id="nd_vlan-entry" class="input-mini" type="number" placeholder="number"
<input name="vlan" id="nd_vlan-entry" class="input-mini" type="number" placeholder="ID"
value="[% params.vlan | html_entity %]" type="text"/>
</label>
</div>