implement prefetch for ports list, drop template param for modifying search clause

This commit is contained in:
Oliver Gorwits
2012-02-13 17:04:33 +00:00
parent c0ab61fe0f
commit d4388bb519
2 changed files with 15 additions and 5 deletions

View File

@@ -98,6 +98,20 @@ ajax '/ajax/content/device/ports' => sub {
}
return unless $set->count;
# retrieve related data for additonal table columns, if asked for
$set = $set->search_rs({}, {prefetch => {nodes => 'ips'}})
if param('c_connected');
$set = $set->search_rs({}, {prefetch => {port_vlans_tagged => 'vlan'}})
if param('c_vmember');
# if active or not, control the join to Node table
if (param('n_archived')) {
$set = $set->search_rs({-or => [{'nodes.active' => 1}, {'nodes.active' => 0}]});
}
else {
$set = $set->search_rs({'nodes.active' => 1});
}
# 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) }
@@ -105,14 +119,10 @@ ajax '/ajax/content/device/ports' => sub {
or $_->is_free(param('age_num'), param('age_unit')) } $set->all ];
return unless scalar @$results;
my @active = (param('n_archived')
? (-or => [{'me.active' => 1}, {'me.active' => 0}])
: ('me.active' => 1));
content_type('text/html');
template 'ajax/device/ports.tt', {
results => $results,
archive_filter => {@active},
}, { layout => undef };
};

View File

@@ -94,7 +94,7 @@
<br/>&nbsp; ([% row.remote_type %]) / ([% row.remote_id %])</a>
[% END %]
[% END %]
[% FOREACH node IN row.nodes(archive_filter) %]
[% FOREACH node IN row.nodes %]
[% '<br/>' IF row.remote_ip OR NOT loop.first %]
[% '<span class="label warning">a</span> &nbsp;' IF NOT node.active %]
<a href="[% uri_for('/search') %]?tab=node&q=[% node.mac | uri %]">[% node.mac %]</a>