From f1eb6eb201f407742c8a1d7d7b615c0816232fe4 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 12 Jan 2012 22:19:17 +0000 Subject: [PATCH] implement ports list filtering --- .../lib/Netdisco/DB/ResultSet/DevicePort.pm | 18 ++++++++++++- Netdisco/lib/Netdisco/Web.pm | 25 ++++++++++++++++++- Netdisco/public/css/style.css | 5 ++++ Netdisco/views/ajax/device/ports.tt | 5 +--- Netdisco/views/inc/device/ports.tt | 2 +- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm b/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm index f4ded9bc..d8a0ffbe 100644 --- a/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm +++ b/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm @@ -64,7 +64,7 @@ sub by_name { # should match edge ports only sub by_vlan { my ($set, $vlan) = @_; - return $set unless $vlan and $vlan =~ m/^\d+$/;; + return $set unless $vlan and $vlan =~ m/^\d+$/; return $set->search( { @@ -78,5 +78,21 @@ sub by_vlan { ); } +sub by_port { + my ($set, $port) = @_; + return $set unless $port; + + return $set->search( + { + 'me.port' => $port, + }, + { + order_by => [qw/ me.ip me.port /], + columns => [qw/ ip port descr name vlan device.dns /], + join => 'device', + }, + ); +} + 1; diff --git a/Netdisco/lib/Netdisco/Web.pm b/Netdisco/lib/Netdisco/Web.pm index a260b7c2..aa1e7a29 100644 --- a/Netdisco/lib/Netdisco/Web.pm +++ b/Netdisco/lib/Netdisco/Web.pm @@ -94,9 +94,32 @@ ajax '/ajax/content/device/ports' => sub { return unless $ip; my $set = schema('netdisco')->resultset('DevicePort')->by_ip($ip); + + # refine by ports if requested + my $q = param('q'); + if ($q) { + if ($q =~ m/^\d+$/) { + $set = $set->by_vlan($q); + } + else { + my $c = schema('netdisco')->resultset('DevicePort')->by_ip($ip)->by_port($q); + if ($c->count) { + $set = $set->by_port($q); + } + else { + $set = $set->by_name($q); + } + } + } return unless $set->count; - my $results = [ sort { &netdisco::sort_port($a->port, $b->port) } $set->all ]; + # sort, and filter by free ports + # the filter could be in the template but here allows a 'no records' msg + my $results = [ sort { &netdisco::sort_port($a->port, $b->port) } + grep { not param('free') + or $_->is_free(param('age_num'), param('age_unit')) } $set->all ]; + + return unless scalar @$results; content_type('text/html'); template 'ajax/device/ports.tt', { diff --git a/Netdisco/public/css/style.css b/Netdisco/public/css/style.css index 7e48bad8..9ed3feb5 100644 --- a/Netdisco/public/css/style.css +++ b/Netdisco/public/css/style.css @@ -163,3 +163,8 @@ form .clearfix.success input { .center_cell { text-align: center; } + +/* for the tagged vlans total when hiding the full list */ +.vlan_total { + float: right; +} diff --git a/Netdisco/views/ajax/device/ports.tt b/Netdisco/views/ajax/device/ports.tt index 08a9a388..2bbd8654 100644 --- a/Netdisco/views/ajax/device/ports.tt +++ b/Netdisco/views/ajax/device/ports.tt @@ -9,10 +9,7 @@ - [% SET rownum = 0 %] [% FOREACH row in results %] - [% NEXT IF params.free AND NOT row.is_free(params.age_num, params.age_unit) %] - [% SET rownum = rownum + 1 %] [% IF row.up_admin == 'down' %] @@ -77,7 +74,7 @@ [% SET count = count + 1 %] [% END %] [% IF count > 10 %] - [% SET output = '
(' _ count _ ')
' + [% SET output = '
(' _ count _ ')
' _ 'Show VLANs
' _ output %] [% SET output = output _ '
' %] [% END %] diff --git a/Netdisco/views/inc/device/ports.tt b/Netdisco/views/inc/device/ports.tt index f06edf0c..649e4713 100644 --- a/Netdisco/views/inc/device/ports.tt +++ b/Netdisco/views/inc/device/ports.tt @@ -4,7 +4,7 @@