diff --git a/lib/App/Netdisco/DB/ResultSet/Device.pm b/lib/App/Netdisco/DB/ResultSet/Device.pm index fa5ce923..04c4dfa1 100644 --- a/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -386,7 +386,8 @@ Results are ordered by the Device DNS and IP fields. =item * -Related rows from the C table will be prefetched. +Column C gives a count of the number of ports on the device +that are actually configured to carry the VLAN. =back @@ -404,13 +405,16 @@ sub carrying_vlan { ->search_rs({ 'vlans.vlan' => $cond->{vlan} }, { order_by => [qw/ me.dns me.ip /], - columns => [ - 'me.ip', 'me.dns', - 'me.model', 'me.os', - 'me.vendor', 'vlans.vlan', - 'vlans.description' - ], - join => 'vlans' + select => [{ count => 'ports.vlan' }], + as => ['pcount'], + columns => [ + 'me.ip', 'me.dns', + 'me.model', 'me.os', + 'me.vendor', 'vlans.vlan', + 'vlans.description' + ], + join => {'vlans' => 'ports'}, + distinct => 1, }) ->search({}, $attrs); } diff --git a/share/views/ajax/search/vlan.tt b/share/views/ajax/search/vlan.tt index c37407ae..1b00b0a6 100644 --- a/share/views/ajax/search/vlan.tt +++ b/share/views/ajax/search/vlan.tt @@ -4,6 +4,7 @@ VLAN Device Description + Ports Model OS Vendor @@ -31,6 +32,12 @@ $(document).ready(function() { "render": function(data, type, row, meta) { return '' + he.encode(data || '') + ''; } + }, { + "data": 'pcount', + "searchable": false, + "render": function(data, type, row, meta) { + return '' + he.encode(data.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")) + ''; + } }, { "data": 'model', "render": function(data, type, row, meta) { diff --git a/share/views/ajax/search/vlan_csv.tt b/share/views/ajax/search/vlan_csv.tt index 82b0e33e..da755229 100644 --- a/share/views/ajax/search/vlan_csv.tt +++ b/share/views/ajax/search/vlan_csv.tt @@ -1,10 +1,10 @@ [% USE CSV -%] -[% CSV.dump([ 'VLAN' 'Device' 'Description' 'Model' 'OS' 'Vendor' ]) %] +[% CSV.dump([ 'VLAN' 'Device' 'Description' 'Ports' 'Model' 'OS' 'Vendor' ]) %] [% FOREACH row IN results %] [% mylist = [] %] [% device = row.dns || row.ip %] - [% FOREACH col IN [ row.vlans.vlan device row.vlans.description row.model row.os row.vendor ] %] + [% FOREACH col IN [ row.vlans.vlan device row.vlans.description row.pcount row.model row.os row.vendor ] %] [% mylist.push(col) %] [% END %] [% CSV.dump(mylist) %]