1package App::Netdisco::Web::Plugin::Report::HalfDuplex;
2
3use Dancer ':syntax';
4use Dancer::Plugin::DBIC;
5use Dancer::Plugin::Auth::Extensible;
6
7use App::Netdisco::Web::Plugin;
8
9register_report(
10    {   category     => 'Port',
11        tag          => 'halfduplex',
12        label        => 'Ports in Half Duplex Mode',
13        provides_csv => 1,
14        api_endpoint => 1,
15    }
16);
17
18get '/ajax/content/report/halfduplex' => require_login sub {
19    my @results
20        = schema('netdisco')->resultset('DevicePort')
21        ->columns( [qw/ ip port name duplex /] )->search(
22        { up => 'up', duplex => { '-ilike' => 'half' } },
23        {   '+columns' => [qw/ device.dns device.name /],
24            join       => [qw/ device /],
25            collapse   => 1,
26        }
27        )->order_by( [qw/ device.dns port /] )->hri->all;
28
29    return unless scalar @results;
30
31    if ( request->is_ajax ) {
32        my $json = to_json( \@results );
33        template 'ajax/report/halfduplex.tt', { results => $json };
34    }
35    else {
36        header( 'Content-Type' => 'text/comma-separated-values' );
37        template 'ajax/report/halfduplex_csv.tt',
38            { results => \@results };
39    }
40};
41
421;
43