From 9ee14a5e636e6b3ee1f17d457ef8294aa8e80fc6 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 1 Dec 2012 21:37:42 +0000 Subject: [PATCH] Network Map now shows all device neighbors and allows click-through nav --- Changes | 4 + Netdisco/lib/Netdisco/Web/Device.pm | 26 +++- Netdisco/public/css/netdisco.css | 9 +- Netdisco/views/ajax/device/netmap.tt | 171 ++++++++++++++++++++++----- 4 files changed, 175 insertions(+), 35 deletions(-) diff --git a/Changes b/Changes index 266ace19..ab4ced2c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ 0.8 - + [NEW FEATURES] + + * Network Map now shows all device neighbors and allows click-through nav + [BUG FIXES] * port cotrol user log check now looks for all actions diff --git a/Netdisco/lib/Netdisco/Web/Device.pm b/Netdisco/lib/Netdisco/Web/Device.pm index a5c5028c..397a7dbd 100644 --- a/Netdisco/lib/Netdisco/Web/Device.pm +++ b/Netdisco/lib/Netdisco/Web/Device.pm @@ -105,7 +105,7 @@ sub _add_children { next if exists var('seen')->{$c}; var('seen')->{$c}++; push @legit, $c; - push @{$ptr}, { name => _get_name($c) }; + push @{$ptr}, { name => _get_name($c), ip => $c }; } for (my $i = 0; $i < @legit; $i++) { @@ -136,17 +136,39 @@ get '/ajax/data/device/netmap' => sub { } my %tree = ( + ip => $start, name => _get_name($start), children => [], ); - var(seen => {}); + var(seen => {$start => 1}); _add_children($tree{children}, var('links')->{$start}); content_type('application/json'); return to_json(\%tree); }; +ajax '/ajax/data/device/alldevicelinks' => sub { + my @devices = schema->resultset('Device')->search({}, { + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + columns => ['ip', 'dns'], + })->all; + var(devices => { map { $_->{ip} => $_->{dns} } @devices }); + + my $rs = schema->resultset('Virtual::DeviceLinks')->search({}, { + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + }); + + my %tree = (); + while (my $l = $rs->next) { + push @{ $tree{ _get_name($l->{left_ip} )} }, + _get_name($l->{right_ip}); + } + + content_type('application/json'); + return to_json(\%tree); +}; + # device interface addresses ajax '/ajax/content/device/addresses' => sub { my $ip = param('q'); diff --git a/Netdisco/public/css/netdisco.css b/Netdisco/public/css/netdisco.css index 97ef7271..3b476c9a 100644 --- a/Netdisco/public/css/netdisco.css +++ b/Netdisco/public/css/netdisco.css @@ -381,8 +381,15 @@ form .clearfix.success input { .link { fill: none; - stroke: #ccc; + stroke: #eee; stroke-width: 1.5px; } +.neighbor { + fill: none; + stroke: #aaa; + stroke-width: 2px; + display: none; +} + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ diff --git a/Netdisco/views/ajax/device/netmap.tt b/Netdisco/views/ajax/device/netmap.tt index e35566a8..7671b04d 100644 --- a/Netdisco/views/ajax/device/netmap.tt +++ b/Netdisco/views/ajax/device/netmap.tt @@ -1,65 +1,172 @@