get rid of d3 v3/v4 and only have v3
This commit is contained in:
@@ -84,28 +84,26 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
grep { exists setting('host_groups')->{$_} }
|
grep { exists setting('host_groups')->{$_} }
|
||||||
grep { defined } @{ $devgrp };
|
grep { defined } @{ $devgrp };
|
||||||
|
|
||||||
my %id_for = ();
|
|
||||||
my %ok_dev = ();
|
my %ok_dev = ();
|
||||||
my %v3data = ( nodes => {}, links => [] );
|
my %metadata = ();
|
||||||
my %v4data = ( nodes => [], links => [] );
|
my %data = ( nodes => [], links => [] );
|
||||||
my $domain = quotemeta( setting('domain_suffix') || '' );
|
my $domain = quotemeta( setting('domain_suffix') || '' );
|
||||||
|
|
||||||
# LINKS
|
# LINKS
|
||||||
|
|
||||||
my $rs = schema('netdisco')->resultset('Virtual::DeviceLinks')->search({
|
my $links = schema('netdisco')->resultset('Virtual::DeviceLinks')->search({
|
||||||
($mapshow eq 'neighbors' ? ( -or => [
|
($mapshow eq 'neighbors' ? ( -or => [
|
||||||
{ left_ip => $qdev->ip },
|
{ left_ip => $qdev->ip },
|
||||||
{ right_ip => $qdev->ip },
|
{ right_ip => $qdev->ip },
|
||||||
]) : ())
|
]) : ())
|
||||||
}, {
|
}, {
|
||||||
columns => [qw/left_ip speed right_ip/],
|
columns => [qw/left_ip speed right_ip/],
|
||||||
'+select' => [\'row_number() over()'],
|
'+select' => [\'row_number() over()'], '+as' => ['row_number'],
|
||||||
'+as' => ['row_number'],
|
|
||||||
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
|
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($vlan) {
|
if ($vlan) {
|
||||||
$rs = $rs->search({
|
$links = $links->search({
|
||||||
-or => [
|
-or => [
|
||||||
{ 'left_vlans.vlan' => $vlan },
|
{ 'left_vlans.vlan' => $vlan },
|
||||||
{ 'right_vlans.vlan' => $vlan },
|
{ 'right_vlans.vlan' => $vlan },
|
||||||
@@ -115,17 +113,16 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
my @links = $rs->all; # because we have to run this twice
|
while (my $link = $links->next) {
|
||||||
foreach my $l (@links) {
|
push @{$data{'links'}}, {
|
||||||
push @{$v3data{'links'}}, {
|
FROMID => $link->{left_ip},
|
||||||
FROMID => $l->{left_ip},
|
TOID => $link->{right_ip},
|
||||||
TOID => $l->{right_ip},
|
SPEED => $link->{speed},
|
||||||
SPEED => $l->{speed},
|
ID => $link->{row_number},
|
||||||
ID => $l->{row_number},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
++$ok_dev{$l->{left_ip}};
|
++$ok_dev{$link->{left_ip}};
|
||||||
++$ok_dev{$l->{right_ip}};
|
++$ok_dev{$link->{right_ip}};
|
||||||
}
|
}
|
||||||
|
|
||||||
# DEVICES (NODES)
|
# DEVICES (NODES)
|
||||||
@@ -138,8 +135,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
|
|
||||||
my $devices = schema('netdisco')->resultset('Device')->search({}, {
|
my $devices = schema('netdisco')->resultset('Device')->search({}, {
|
||||||
columns => ['ip', 'dns', 'name'],
|
columns => ['ip', 'dns', 'name'],
|
||||||
'+select' => [\'row_number() over()', \'floor(log(throughput.total))'],
|
'+select' => [\'floor(log(throughput.total))'], '+as' => ['log'],
|
||||||
'+as' => ['row_number', 'log'],
|
|
||||||
join => 'throughput',
|
join => 'throughput',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -153,10 +149,8 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
first { check_acl_only($device, setting('host_groups')->{$_}) } @hgrplist;
|
first { check_acl_only($device, setting('host_groups')->{$_}) } @hgrplist;
|
||||||
next DEVICE if $mapshow eq 'only' and not $first_hgrp;
|
next DEVICE if $mapshow eq 'only' and not $first_hgrp;
|
||||||
|
|
||||||
$id_for{$device->ip} = $device->get_column('row_number');
|
|
||||||
(my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domain$//;
|
(my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domain$//;
|
||||||
|
my $node = {
|
||||||
$v3data{nodes}->{ ($device->get_column('row_number') - 1) } = {
|
|
||||||
ID => $device->ip,
|
ID => $device->ip,
|
||||||
SIZEVALUE => (param('dynamicsize') ?
|
SIZEVALUE => (param('dynamicsize') ?
|
||||||
(($device->get_column('log') || 1) * 1000) : 3000),
|
(($device->get_column('log') || 1) * 1000) : 3000),
|
||||||
@@ -168,32 +162,21 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if ($mapshow ne 'neighbors' and exists $pos_for->{$device->ip}) {
|
if ($mapshow ne 'neighbors' and exists $pos_for->{$device->ip}) {
|
||||||
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'};
|
++$metadata{'newnodes'};
|
||||||
}
|
}
|
||||||
|
|
||||||
$v3data{'centernode'} = $device->ip
|
push @{$data{'nodes'}}, $node;
|
||||||
|
$metadata{'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->get_column('row_number') - 1) };
|
|
||||||
}
|
|
||||||
|
|
||||||
# go back and do v4 links now we have row IDs
|
|
||||||
foreach my $l (@links) {
|
|
||||||
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),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content_type('application/json');
|
content_type('application/json');
|
||||||
to_json({ v3 => \%v3data, v4 => \%v4data});
|
to_json({ data => \%data, %metadata });
|
||||||
};
|
};
|
||||||
|
|
||||||
true;
|
true;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m
|
|||||||
.showLinkDirection(false)
|
.showLinkDirection(false)
|
||||||
.colorScheme('color20')
|
.colorScheme('color20')
|
||||||
.preventLabelOverlappingOnForceEnd(
|
.preventLabelOverlappingOnForceEnd(
|
||||||
(mapdata['v3']['newnodes'] && ('[% params.mapshow %]' == 'neighbors'))
|
(mapdata['newnodes'] && ('[% params.mapshow %]' == 'neighbors'))
|
||||||
? true : false
|
? true : false
|
||||||
)
|
)
|
||||||
.nodeEventToStopPinMode('none')
|
.nodeEventToStopPinMode('none')
|
||||||
@@ -118,13 +118,13 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m
|
|||||||
.gravity(0.3);
|
.gravity(0.3);
|
||||||
|
|
||||||
graph['nd2'] = {};
|
graph['nd2'] = {};
|
||||||
graph['nd2']['centernode'] = mapdata['v3']['centernode'];
|
graph['nd2']['centernode'] = mapdata['centernode'];
|
||||||
graph['nd2']['dragging'] = false;
|
graph['nd2']['dragging'] = false;
|
||||||
|
|
||||||
graph.inspect().main.force.on('end.setupfornetdisco', function() {
|
graph.inspect().main.force.on('end.setupfornetdisco', function() {
|
||||||
graph.inspect().main.nodes.each(function(n) { n.fixed = true });
|
graph.inspect().main.nodes.each(function(n) { n.fixed = true });
|
||||||
|
|
||||||
if (mapdata['v3']['newnodes'] && ('[% params.mapshow %]' != 'neighbors')) {
|
if (mapdata['newnodes'] && ('[% params.mapshow %]' != 'neighbors')) {
|
||||||
$.post(
|
$.post(
|
||||||
'[% uri_for('/ajax/data/device/netmappositions') %]'
|
'[% uri_for('/ajax/data/device/netmappositions') %]'
|
||||||
,$("#nd_vlan-entry, #nd_devgrp-select, input[name='mapshow']").serialize()
|
,$("#nd_vlan-entry, #nd_devgrp-select, input[name='mapshow']").serialize()
|
||||||
@@ -206,14 +206,7 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m
|
|||||||
.append("path")
|
.append("path")
|
||||||
.attr("id", "nd2_netmap-spinner");
|
.attr("id", "nd2_netmap-spinner");
|
||||||
|
|
||||||
var netmapdata = {'data': {
|
graph.start(mapdata);
|
||||||
'nodes': mapdata['v4']['nodes'].map(function(node) {
|
|
||||||
var index = node['index'];
|
|
||||||
return mapdata['v3']['nodes'][index];
|
|
||||||
}),
|
|
||||||
'links': mapdata['v3']['links']
|
|
||||||
}};
|
|
||||||
graph.start(netmapdata);
|
|
||||||
d3.select("#nd2_netmap-spinner").call(spin);
|
d3.select("#nd2_netmap-spinner").call(spin);
|
||||||
|
|
||||||
graph.inspect().main.links.each(function(l) {
|
graph.inspect().main.links.each(function(l) {
|
||||||
|
|||||||
Reference in New Issue
Block a user