From a2ce65c8b89eb73d3a115d57aba5a0891b16d438 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 19 Mar 2018 17:47:22 +0000 Subject: [PATCH] working folters and colors for host group and location --- .../DB/Result/Virtual/DevicePortSpeed.pm | 5 +-- lib/App/Netdisco/Web/Device.pm | 4 +-- .../Netdisco/Web/Plugin/Device/Neighbors.pm | 32 +++++++++++-------- share/config.yml | 3 +- share/views/ajax/device/netmap.tt | 2 +- share/views/sidebar/device/netmap.tt | 23 +++++++------ 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/lib/App/Netdisco/DB/Result/Virtual/DevicePortSpeed.pm b/lib/App/Netdisco/DB/Result/Virtual/DevicePortSpeed.pm index aa1e6fd8..aa2ac93d 100644 --- a/lib/App/Netdisco/DB/Result/Virtual/DevicePortSpeed.pm +++ b/lib/App/Netdisco/DB/Result/Virtual/DevicePortSpeed.pm @@ -14,8 +14,9 @@ __PACKAGE__->result_source_instance->view_definition(< sub { } # used in the device search sidebar template to set selected items - foreach my $opt (qw/hgroup location/) { + foreach my $opt (qw/hgroup lgroup/) { my $p = (ref [] eq ref param($opt) ? param($opt) : (param($opt) ? [param($opt)] : [])); $tokens->{"${opt}_lkp"} = { map { $_ => 1 } @$p }; @@ -82,7 +82,7 @@ get '/device' => require_login sub { params->{'tab'} ||= 'details'; template 'device', { display_name => ($others ? $first->ip : ($first->dns || $first->ip)), - location_list => [ schema('netdisco')->resultset('Device')->get_distinct_col('location') ], + lgroup_list => [ schema('netdisco')->resultset('Device')->get_distinct_col('location') ], hgroup_list => setting('host_group_displaynames'), device => params->{'tab'}, }; diff --git a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index 5a150592..c6f5e6d4 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -109,8 +109,9 @@ ajax '/ajax/data/device/netmap' => require_login sub { my $vlan = param('vlan'); undef $vlan if (defined $vlan and $vlan !~ m/^\d+$/); + my $colorby = (param('colorby') || 'speed'); my $mapshow = (param('mapshow') || 'neighbors'); - $mapshow = 'neighbors' if $mapshow !~ m/^(?:all|neighbors|location|hgroup)$/; + $mapshow = 'neighbors' if $mapshow !~ m/^(?:all|neighbors)$/; $mapshow = 'all' unless $qdev->in_storage; # list of groups selected by user and passed in param @@ -181,27 +182,30 @@ ajax '/ajax/data/device/netmap' => require_login sub { next DEVICE if (($mapshow eq 'neighbors') or $vlan) and (not $ok_dev{$device->ip}); - # if in locations mode then filter - next DEVICE if $mapshow eq 'location' and ((!defined $device->location) - or (0 == scalar grep {$_ eq $device->location} @lgrplist)); + # if location picked then filter + next DEVICE if ((scalar @lgrplist) and ((!defined $device->location) + or (0 == scalar grep {$_ eq $device->location} @lgrplist))); - # if in host group mode then use ACLs to filter + # if host groups piked then use ACLs to filter my $first_hgrp = first { check_acl_only($device, setting('host_groups')->{$_}) } @hgrplist; - next DEVICE if $mapshow eq 'hgroup' and not $first_hgrp; + next DEVICE if ((scalar @hgrplist) and (not $first_hgrp)); ++$logvals{ $device->get_column('log') || 1 }; (my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domain$//; + my %color_lkp = ( + speed => (($device->get_column('log') || 1) * 1000), + hgroup => ($first_hgrp ? + setting('host_group_displaynames')->{$first_hgrp} : 'Other'), + lgroup => ($device->location || 'Other'), + ); + my $node = { ID => $device->ip, - SIZEVALUE => (param('dynamicsize') ? - (($device->get_column('log') || 1) * 1000) : 3000), - (param('colorgroups') ? - (COLORVALUE => ($first_hgrp ? setting('host_group_displaynames')->{$first_hgrp} - : 'Other')) : ()), - LABEL => (param('showips') - ? (($name eq $device->ip) ? $name : ($name .' '. $device->ip)) : $name), + SIZEVALUE => (param('dynamicsize') ? $color_lkp{speed} : 3000), + ((exists $color_lkp{$colorby}) ? (COLORVALUE => $color_lkp{$colorby}) : ()), + LABEL => $name, ORIG_LABEL => $name, INFOSTRING => make_node_infostring($device), LINK => uri_for('/device', { @@ -211,7 +215,7 @@ ajax '/ajax/data/device/netmap' => require_login sub { })->path_query, }; - if ($mapshow ne 'neighbors' and exists $pos_for->{$device->ip}) { + if (exists $pos_for->{$device->ip}) { $node->{'fixed'} = 1; $node->{'x'} = $pos_for->{$device->ip}->{'x'}; $node->{'y'} = $pos_for->{$device->ip}->{'y'}; diff --git a/share/config.yml b/share/config.yml index 092398d4..2f8eb9a4 100644 --- a/share/config.yml +++ b/share/config.yml @@ -139,8 +139,7 @@ sidebar_defaults: showips: { default: null } showspeed: { default: null } mapshow: { default: neighbors } - colorby: { default: location } - colorgroups: { default: checked } + colorby: { default: speed } dynamicsize: { default: checked } report_moduleinventory: fruonly: { default: checked } diff --git a/share/views/ajax/device/netmap.tt b/share/views/ajax/device/netmap.tt index 1bc1d00f..aff44636 100644 --- a/share/views/ajax/device/netmap.tt +++ b/share/views/ajax/device/netmap.tt @@ -18,7 +18,7 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m .dragMode(true) .zoomMode(true) .pinMode(true) - [% '.showLegend(false)' IF NOT params.colorgroups %] + [% '.showLegend(false)' UNLESS (params.colorby == 'hgroup' OR params.colorby == 'lgroup') %] .showLinkDirection(false) .colorScheme('color10') //.preventLabelOverlappingOnForceEnd( diff --git a/share/views/sidebar/device/netmap.tt b/share/views/sidebar/device/netmap.tt index 7d871ade..aa4812c6 100644 --- a/share/views/sidebar/device/netmap.tt +++ b/share/views/sidebar/device/netmap.tt @@ -86,12 +86,12 @@ [% END %] [% END %] - [% IF location_list.size %] - @@ -99,16 +99,21 @@
- [% IF hgroup_list.size OR location_list.size %] + [% IF hgroup_list.size OR lgroup_list.size %]