port search tries vlan edge port match first
This commit is contained in:
		| @@ -61,5 +61,22 @@ sub by_name { | ||||
|     ); | ||||
| } | ||||
|  | ||||
| # should match edge ports only | ||||
| sub by_vlan { | ||||
|     my ($set, $vlan) = @_; | ||||
|     return $set unless $vlan and $vlan =~ m/^\d+$/;; | ||||
|  | ||||
|     return $set->search( | ||||
|       { | ||||
|         'me.vlan' => $vlan, | ||||
|       }, | ||||
|       { | ||||
|         order_by => [qw/ me.ip me.port /], | ||||
|         columns => [qw/ ip port descr name vlan device.dns /], | ||||
|         join => 'device', | ||||
|       }, | ||||
|     ); | ||||
| } | ||||
|  | ||||
| 1; | ||||
|  | ||||
|   | ||||
| @@ -234,10 +234,16 @@ ajax '/ajax/content/search/vlan' => sub { | ||||
|  | ||||
| # device ports with a description (er, name) matching | ||||
| ajax '/ajax/content/search/port' => sub { | ||||
|     my $name = param('q'); | ||||
|     return unless $name; | ||||
|     my $q = param('q'); | ||||
|     return unless $q; | ||||
|     my $set; | ||||
|  | ||||
|     my $set = schema('netdisco')->resultset('DevicePort')->by_name($name); | ||||
|     if ($q =~ m/^\d+$/) { | ||||
|         $set = schema('netdisco')->resultset('DevicePort')->by_vlan($q); | ||||
|     } | ||||
|     else { | ||||
|         $set = schema('netdisco')->resultset('DevicePort')->by_name($q); | ||||
|     } | ||||
|     return unless $set->count; | ||||
|  | ||||
|     content_type('text/html'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user