Factor out inventory queries to the Device ResultSet (closes #20)
This commit is contained in:
1
Changes
1
Changes
@@ -16,6 +16,7 @@
|
|||||||
This came as a side-effect of removing JS-only links (closes #21)
|
This came as a side-effect of removing JS-only links (closes #21)
|
||||||
* Replace jquery-collapser with Bootstrap's collapser
|
* Replace jquery-collapser with Bootstrap's collapser
|
||||||
* Upgraded to Twitter Bootstrap 2.1.0 - customized for 13px font 18px line
|
* Upgraded to Twitter Bootstrap 2.1.0 - customized for 13px font 18px line
|
||||||
|
* Factor out inventory queries to the Device ResultSet (closes #20)
|
||||||
|
|
||||||
[BUG FIXES]
|
[BUG FIXES]
|
||||||
|
|
||||||
|
|||||||
@@ -328,6 +328,66 @@ sub carrying_vlan_name {
|
|||||||
->search($cond, $attrs);
|
->search($cond, $attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 get_models
|
||||||
|
|
||||||
|
Returns a sorted list of Device models with the following columns only:
|
||||||
|
|
||||||
|
=over 4
|
||||||
|
|
||||||
|
=item vendor
|
||||||
|
|
||||||
|
=item model
|
||||||
|
|
||||||
|
=item count
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
Where C<count> is the number of instances of that Vendor's Model in the
|
||||||
|
Netdisco database.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub get_models {
|
||||||
|
my $rs = shift;
|
||||||
|
return $rs->search({}, {
|
||||||
|
select => [ 'vendor', 'model', { count => 'ip' } ],
|
||||||
|
as => [qw/vendor model count/],
|
||||||
|
group_by => [qw/vendor model/],
|
||||||
|
order_by => [{-asc => 'vendor'}, {-desc => 'count'}, {-asc => 'model'}],
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
=head2 get_releases
|
||||||
|
|
||||||
|
Returns a sorted list of Device OS releases with the following columns only:
|
||||||
|
|
||||||
|
=over 4
|
||||||
|
|
||||||
|
=item os
|
||||||
|
|
||||||
|
=item os_ver
|
||||||
|
|
||||||
|
=item count
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
Where C<count> is the number of devices running that OS release in the
|
||||||
|
Netdisco database.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub get_releases {
|
||||||
|
my $rs = shift;
|
||||||
|
return $rs->search({}, {
|
||||||
|
select => [ 'os', 'os_ver', { count => 'ip' } ],
|
||||||
|
as => [qw/os os_ver count/],
|
||||||
|
group_by => [qw/os os_ver/],
|
||||||
|
order_by => [{-asc => 'os'}, {-desc => 'count'}, {-asc => 'os_ver'}],
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
=head2 get_distinct( $column )
|
=head2 get_distinct( $column )
|
||||||
|
|
||||||
Returns an asciibetical sorted list of the distinct values in the given column
|
Returns an asciibetical sorted list of the distinct values in the given column
|
||||||
|
|||||||
@@ -4,20 +4,14 @@ use Dancer ':syntax';
|
|||||||
use Dancer::Plugin::DBIC;
|
use Dancer::Plugin::DBIC;
|
||||||
|
|
||||||
get '/inventory' => sub {
|
get '/inventory' => sub {
|
||||||
|
my $models = schema('netdisco')->resultset('Device')->get_models();
|
||||||
|
my $releases = schema('netdisco')->resultset('Device')->get_releases();
|
||||||
|
|
||||||
var(nav => 'inventory');
|
var(nav => 'inventory');
|
||||||
|
|
||||||
template 'inventory', {
|
template 'inventory', {
|
||||||
models => scalar schema('netdisco')->resultset('Device')->search({},{
|
models => $models,
|
||||||
select => [ 'vendor', 'model', { count => 'ip' } ],
|
releases => $releases,
|
||||||
as => [qw/vendor model count/],
|
|
||||||
group_by => [qw/vendor model/],
|
|
||||||
order_by => [{-asc => 'vendor'}, {-desc => 'count'}, {-asc => 'model'}],
|
|
||||||
}),
|
|
||||||
releases => scalar schema('netdisco')->resultset('Device')->search({},{
|
|
||||||
select => [ 'os', 'os_ver', { count => 'ip' } ],
|
|
||||||
as => [qw/os os_ver count/],
|
|
||||||
group_by => [qw/os os_ver/],
|
|
||||||
order_by => [{-asc => 'os'}, {-desc => 'count'}, {-asc => 'os_ver'}],
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user