implement ports list filtering

This commit is contained in:
Oliver Gorwits
2012-01-12 22:19:17 +00:00
parent e817220856
commit f1eb6eb201
5 changed files with 48 additions and 7 deletions

View File

@@ -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;

View File

@@ -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', {

View File

@@ -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;
}

View File

@@ -9,10 +9,7 @@
</tr>
</thead>
</tbody>
[% 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 %]
<tr>
<td>
[% IF row.up_admin == 'down' %]
@@ -77,7 +74,7 @@
[% SET count = count + 1 %]
[% END %]
[% IF count > 10 %]
[% SET output = '<div style="float: right">(' _ count _ ')</div><a href="#" class="nd_linkcell nd_collapse_vlans">'
[% SET output = '<div class="vlan_total">(' _ count _ ')</div><a href="#" class="nd_linkcell nd_collapse_vlans">'
_ 'Show VLANs</a><div class="nd_collapse_pre_hidden">' _ output %]
[% SET output = output _ '</div>' %]
[% END %]

View File

@@ -4,7 +4,7 @@
<input name="ip" value="[% params.ip %]" type="hidden"/>
<div class="clearfix">
<input class="nd_port_query span3" placeholder="Port, Name or VLAN"
name="q" value="[% params.port || params.vlan %]" type="text"
name="q" value="[% params.q %]" type="text"
rel="twipsy" data-placement="right" data-offset="5" title="Filter by Port, Name or VLAN"/>
</div>
<div class="clearfix">