blib/lib/App/Netdisco/Web/Plugin/Device/Details.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 62 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Web::Plugin::Device::Details;
2  
3 use Dancer ':syntax';
4 use Dancer::Plugin::Ajax;
5 use Dancer::Plugin::DBIC;
6 use Dancer::Plugin::Auth::Extensible;
7  
8 use App::Netdisco::Web::Plugin;
9  
10 use List::MoreUtils 'singleton';
11  
12 register_device_tab({ tag => 'details', label => 'Details' });
13  
14 # device details table
15 ajax '/ajax/content/device/details' => require_login sub {
16 my $q = param('q');
17 my $device = schema(vars->{'tenant'})->resultset('Device')
18 ->search_for_device($q) or send_error('Bad device', 400);
19  
20 my @results
21 = schema(vars->{'tenant'})->resultset('Device')
22 ->search({ 'me.ip' => $device->ip })
23 ->with_times
24 ->with_custom_fields
25 ->with_layer_features
26 ->hri->all;
27  
28 my @power
29 = schema(vars->{'tenant'})->resultset('DevicePower')
30 ->search( { 'me.ip' => $device->ip } )->with_poestats->hri->all;
31  
32 my @interfaces = $device->device_ips->hri->all;
33  
34 my @serials = $device->modules->search({
35 class => 'chassis',
36 -and => [
37 { serial => { '!=' => '' } },
38 { serial => { '!=' => undef } },
39 ],
40 })->order_by('pos')->get_column('serial')->all;
41  
42 # filter the tags by hide_tags setting
43 my @hide = @{ setting('hide_tags')->{'device'} };
44  
45 content_type('text/html');
46 template 'ajax/device/details.tt', {
47 d => $results[0], p => \@power,
48 interfaces => \@interfaces,
49 has_snapshot =>
50 $device->oids->search({-bool => \q{ jsonb_typeof(value) = 'array' }})->count,
51 filtered_tags => [ singleton (@{ $device->tags || [] }, @hide, @hide) ],
52 serials => [sort keys %{ { map {($_ => $_)} (@serials, ($device->serial ? $device->serial : ())) } }],
53 }, { layout => undef };
54 };
55  
56 1;