« blib/lib/App/Netdisco/Web/Plugin/Device/Details.pm
↑ Summary
blib/lib/App/Netdisco/Web/Plugin/Device/Vlans.pm »
| 1 | package App::Netdisco::Web::Plugin::Device::Modules; | ||
| 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::Util::Web (); # for sort_module | ||
| 9 | use App::Netdisco::Web::Plugin; | ||
| 10 | |||
| 11 | register_device_tab({ tag => 'modules', label => 'Modules' }); | ||
| 12 | |||
| 13 | ajax '/ajax/content/device/modules' => require_login sub { | ||
| 14 | my $q = param('q'); | ||
| 15 | |||
| 16 | my $device = schema(vars->{'tenant'})->resultset('Device') | ||
| 17 | ->search_for_device($q) or send_error('Bad device', 400); | ||
| 18 | my @set = $device->modules->search({}, {order_by => { -asc => [qw/parent class pos index/] }}); | ||
| 19 | |||
| 20 | # sort modules (empty set would be a 'no records' msg) | ||
| 21 | my $results = &App::Netdisco::Util::Web::sort_modules( \@set ); | ||
| 22 | return unless scalar %$results; | ||
| 23 | |||
| 24 | content_type('text/html'); | ||
| 25 | template 'ajax/device/modules.tt', { | ||
| 26 | nodes => $results, | ||
| 27 | }, { layout => 'noop' }; | ||
| 28 | }; | ||
| 29 | |||
| 30 | true; |