implement ports list filtering
This commit is contained in:
@@ -64,7 +64,7 @@ sub by_name {
|
|||||||
# should match edge ports only
|
# should match edge ports only
|
||||||
sub by_vlan {
|
sub by_vlan {
|
||||||
my ($set, $vlan) = @_;
|
my ($set, $vlan) = @_;
|
||||||
return $set unless $vlan and $vlan =~ m/^\d+$/;;
|
return $set unless $vlan and $vlan =~ m/^\d+$/;
|
||||||
|
|
||||||
return $set->search(
|
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;
|
1;
|
||||||
|
|
||||||
|
|||||||
@@ -94,9 +94,32 @@ ajax '/ajax/content/device/ports' => sub {
|
|||||||
return unless $ip;
|
return unless $ip;
|
||||||
|
|
||||||
my $set = schema('netdisco')->resultset('DevicePort')->by_ip($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;
|
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');
|
content_type('text/html');
|
||||||
template 'ajax/device/ports.tt', {
|
template 'ajax/device/ports.tt', {
|
||||||
|
|||||||
@@ -163,3 +163,8 @@ form .clearfix.success input {
|
|||||||
.center_cell {
|
.center_cell {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* for the tagged vlans total when hiding the full list */
|
||||||
|
.vlan_total {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,10 +9,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
</tbody>
|
</tbody>
|
||||||
[% SET rownum = 0 %]
|
|
||||||
[% FOREACH row in results %]
|
[% FOREACH row in results %]
|
||||||
[% NEXT IF params.free AND NOT row.is_free(params.age_num, params.age_unit) %]
|
|
||||||
[% SET rownum = rownum + 1 %]
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
[% IF row.up_admin == 'down' %]
|
[% IF row.up_admin == 'down' %]
|
||||||
@@ -77,7 +74,7 @@
|
|||||||
[% SET count = count + 1 %]
|
[% SET count = count + 1 %]
|
||||||
[% END %]
|
[% END %]
|
||||||
[% IF count > 10 %]
|
[% 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 %]
|
_ 'Show VLANs</a><div class="nd_collapse_pre_hidden">' _ output %]
|
||||||
[% SET output = output _ '</div>' %]
|
[% SET output = output _ '</div>' %]
|
||||||
[% END %]
|
[% END %]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<input name="ip" value="[% params.ip %]" type="hidden"/>
|
<input name="ip" value="[% params.ip %]" type="hidden"/>
|
||||||
<div class="clearfix">
|
<div class="clearfix">
|
||||||
<input class="nd_port_query span3" placeholder="Port, Name or VLAN"
|
<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"/>
|
rel="twipsy" data-placement="right" data-offset="5" title="Filter by Port, Name or VLAN"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix">
|
<div class="clearfix">
|
||||||
|
|||||||
Reference in New Issue
Block a user