#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 2.039013 - 2018-03-02
[ENHANCEMENTS] [ENHANCEMENTS]

View File

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

View File

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

View File

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