#372 fix inventory doesn't work with only one device

This commit is contained in:
Oliver Gorwits
2018-03-02 15:59:47 +00:00
parent 5cda45453d
commit 6a43842ea9
4 changed files with 24 additions and 18 deletions

View File

@@ -1,3 +1,9 @@
2.039014 -
[BUG FIXES]
* #372 fix inventory doesn't work with only one device
2.039013 - 2018-03-02
[ENHANCEMENTS]

View File

@@ -475,7 +475,7 @@ sub has_layer {
=back
=head2 get_models
=head2 get_platforms
Returns a sorted list of Device models with the following columns only:
@@ -494,15 +494,15 @@ Netdisco database.
=cut
sub get_models {
sub get_platforms {
my $rs = shift;
return $rs->search({}, {
select => [ 'vendor', 'model', { count => 'ip' } ],
as => [qw/vendor model count/],
'columns' => [ 'vendor', 'model' ],
'+select' => [{ count => 'ip' }],
'+as' => ['count'],
group_by => [qw/vendor model/],
order_by => [{-asc => 'vendor'}, {-asc => 'model'}],
})
});
}
=head2 get_releases
@@ -527,8 +527,9 @@ Netdisco database.
sub get_releases {
my $rs = shift;
return $rs->search({}, {
select => [ 'os', 'os_ver', { count => 'ip' } ],
as => [qw/os os_ver count/],
columns => ['os', 'os_ver'],
'+select' => [ { count => 'ip' } ],
'+as' => [qw/count/],
group_by => [qw/os os_ver/],
order_by => [{-asc => 'os'}, {-asc => 'os_ver'}],
})

View File

@@ -13,14 +13,13 @@ register_navbar_item({
});
get '/inventory' => require_login sub {
my $models = schema('netdisco')->resultset('Device')->get_models();
my $platforms = schema('netdisco')->resultset('Device')->get_platforms();
my $releases = schema('netdisco')->resultset('Device')->get_releases();
var(nav => 'inventory');
template 'inventory', {
models => $models,
releases => $releases,
platforms => [$platforms->hri->all],
releases => [$releases->hri->all],
};
};

View File

@@ -1,5 +1,5 @@
<div class="container">
[% IF models.count %]
[% IF platforms.size %]
<div class="row">
<div class="span6">
<h3 class="nd_inventory-table-head">By Platform</h3>
@@ -12,7 +12,7 @@
</tr>
</thead>
<tbody>
[% FOREACH platform IN models.all %]
[% FOREACH platform IN platforms %]
[% NEXT UNLESS platform.vendor OR platform.model %]
<tr>
<th>
@@ -29,7 +29,7 @@
[% platform.model | html_entity %]</a>
[% ELSE %]unknown[% END %]
</th>
<th>[% platform.get_column('count') | html_entity %]</th>
<th>[% platform.count | html_entity %]</th>
</tr>
[% END %]
</tbody>
@@ -46,8 +46,8 @@
</tr>
</thead>
<tbody>
[% FOREACH release IN releases.all %]
[% NEXT UNLESS (release.os OR release.os_ver) %]
[% FOREACH release IN releases %]
[% NEXT UNLESS release.os OR release.os_ver %]
<tr>
<th>
[% IF release.os %]
@@ -63,7 +63,7 @@
[% release.os_ver | html_entity %]</a>
[% ELSE %]unknown[% END %]
</th>
<th>[% release.get_column('count') | html_entity %]</th>
<th>[% release.count | html_entity %]</th>
</tr>
[% END %]
</tbody>