wooo device group selection is working
This commit is contained in:
@@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC;
|
|||||||
use Dancer::Plugin::Auth::Extensible;
|
use Dancer::Plugin::Auth::Extensible;
|
||||||
|
|
||||||
use List::MoreUtils ();
|
use List::MoreUtils ();
|
||||||
|
use App::Netdisco::Util::Permission 'check_acl_only';
|
||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
|
|
||||||
register_device_tab({ tag => 'netmap', label => 'Neighbors' });
|
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
|
# colorgroups
|
||||||
# dynamicsize
|
# dynamicsize
|
||||||
|
|
||||||
@@ -100,9 +96,6 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
|
|
||||||
my @links = $rs->all; # because we have to run this twice
|
my @links = $rs->all; # because we have to run this twice
|
||||||
foreach my $l (@links) {
|
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'}}, {
|
push @{$v3data{'links'}}, {
|
||||||
FROMID => $l->{left_ip},
|
FROMID => $l->{left_ip},
|
||||||
TOID => $l->{right_ip},
|
TOID => $l->{right_ip},
|
||||||
@@ -119,46 +112,55 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
vlan => ($vlan || 0)});
|
vlan => ($vlan || 0)});
|
||||||
my $pos_for = from_json( $posrow ? $posrow->positions : '{}' );
|
my $pos_for = from_json( $posrow ? $posrow->positions : '{}' );
|
||||||
|
|
||||||
my @devices = schema('netdisco')->resultset('Device')->search({}, {
|
my $devices = schema('netdisco')->resultset('Device')->search({}, {
|
||||||
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
|
|
||||||
columns => ['ip', 'dns', 'name'],
|
columns => ['ip', 'dns', 'name'],
|
||||||
'+select' => [\'row_number() over()'], '+as' => ['row_number'],
|
'+select' => [\'row_number() over()'], '+as' => ['row_number'],
|
||||||
})->all;
|
});
|
||||||
|
|
||||||
foreach my $device (@devices) {
|
NODE: while (my $device = $devices->next) {
|
||||||
next unless $ok_dev{$device->{ip}}; # vlan filter's effect
|
# 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'};
|
# if in only mode then use ACLs to filter
|
||||||
(my $name = ($device->{dns} || lc($device->{name}) || $device->{ip})) =~ s/$domain$//;
|
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_for{$device->ip} = $device->get_column('row_number');
|
||||||
ID => $device->{ip},
|
(my $name = ($device->dns || lc($device->name) || $device->ip)) =~ s/$domain$//;
|
||||||
|
|
||||||
|
$v3data{nodes}->{ ($device->get_column('row_number') - 1) } = {
|
||||||
|
ID => $device->ip,
|
||||||
SIZEVALUE => 3000,
|
SIZEVALUE => 3000,
|
||||||
(param('colorgroups') ? (COLORVALUE => 10) : ()),
|
(param('colorgroups') ? (COLORVALUE => 10) : ()),
|
||||||
LABEL => $name,
|
LABEL => $name,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (exists $pos_for->{$device->{ip}}) {
|
if (exists $pos_for->{$device->ip}) {
|
||||||
my $node = $v3data{nodes}->{ ($device->{row_number} - 1) };
|
my $node = $v3data{nodes}->{ ($device->get_column('row_number') - 1) };
|
||||||
$node->{'fixed'} = 1;
|
$node->{'fixed'} = 1;
|
||||||
$node->{'x'} = $pos_for->{$device->{ip}}->{'x'};
|
$node->{'x'} = $pos_for->{$device->ip}->{'x'};
|
||||||
$node->{'y'} = $pos_for->{$device->{ip}}->{'y'};
|
$node->{'y'} = $pos_for->{$device->ip}->{'y'};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
++$v3data{'newnodes'};
|
++$v3data{'newnodes'};
|
||||||
}
|
}
|
||||||
|
|
||||||
$v3data{'centernode'} = $device->{ip}
|
$v3data{'centernode'} = $device->ip
|
||||||
if $qdev and $qdev->in_storage and $device->{ip} eq $qdev->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
|
# go back and do v4 links now we have row IDs
|
||||||
foreach my $l (@links) {
|
foreach my $l (@links) {
|
||||||
next if (($mapshow eq 'neighbors')
|
next unless $id_for{$l->{left_ip}} and $id_for{$l->{right_ip}};
|
||||||
and (($l->{left_ip} ne $qdev->ip) and ($l->{right_ip} ne $qdev->ip)));
|
|
||||||
|
|
||||||
push @{$v4data{'links'}}, {
|
push @{$v4data{'links'}}, {
|
||||||
source => ($id_for{$l->{left_ip}} - 1),
|
source => ($id_for{$l->{left_ip}} - 1),
|
||||||
target => ($id_for{$l->{right_ip}} - 1),
|
target => ($id_for{$l->{right_ip}} - 1),
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ td > form.nd_inline-form {
|
|||||||
vertical-align: text-bottom;
|
vertical-align: text-bottom;
|
||||||
}
|
}
|
||||||
#nd_vlan-entry {
|
#nd_vlan-entry {
|
||||||
width: 57px;
|
width: 56px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fixup for prepended checkbox in sidebar */
|
/* fixup for prepended checkbox in sidebar */
|
||||||
@@ -634,8 +634,8 @@ form .clearfix.success input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nd_netmap-sidebar {
|
.nd_netmap-sidebar {
|
||||||
/* margin-top: 7px; */
|
margin-top: 0px;
|
||||||
margin-left: -9px;
|
margin-left: -8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nd_netmap-sidebar > .input-prepend {
|
.nd_netmap-sidebar > .input-prepend {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
<div id="nd_vlan-label" class="control-group">
|
<div id="nd_vlan-label" class="control-group">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<label><span id="nd_vlan-label-text">Carrying VLAN: </span>
|
<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"/>
|
value="[% params.vlan | html_entity %]" type="text"/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user