support for plugins for navbar items
This commit is contained in:
27
Netdisco/lib/App/Netdisco/Web/Plugin.pm
Normal file
27
Netdisco/lib/App/Netdisco/Web/Plugin.pm
Normal file
@@ -0,0 +1,27 @@
|
||||
package App::Netdisco::Web::Plugin;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin;
|
||||
|
||||
set('navbar_items' => []);
|
||||
|
||||
register 'register_navbar_item' => sub {
|
||||
my ($self, $config) = plugin_args(@_);
|
||||
|
||||
die "bad config to register_navbar_item\n"
|
||||
unless length $config->{id}
|
||||
and length $config->{path}
|
||||
and length $config->{label};
|
||||
|
||||
foreach my $item (@{ setting('navbar_items') }) {
|
||||
if ($item->{id} eq $config->{id}) {
|
||||
$item = $config;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
push @{ setting('navbar_items') }, $config;
|
||||
};
|
||||
|
||||
register_plugin;
|
||||
true;
|
||||
@@ -1,8 +1,16 @@
|
||||
package App::Netdisco::Web::Inventory;
|
||||
package App::Netdisco::Web::Plugin::Inventory;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin::DBIC;
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
|
||||
register_navbar_item({
|
||||
id => 'inventory',
|
||||
path => '/inventory',
|
||||
label => 'Inventory',
|
||||
});
|
||||
|
||||
get '/inventory' => sub {
|
||||
my $models = schema('netdisco')->resultset('Device')->get_models();
|
||||
my $releases = schema('netdisco')->resultset('Device')->get_releases();
|
||||
Reference in New Issue
Block a user