diff --git a/Netdisco/Changes b/Netdisco/Changes index da549638..41b30736 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,5 +1,9 @@ 2.004004 - + [NEW FEATURES] + + * Support for Web Plugins (see App::Netdisco::Web::Plugin) + [ENHANCEMENTS] * Do not include inventory items which don't have full OS details diff --git a/Netdisco/Makefile.PL b/Netdisco/Makefile.PL index 61417897..b87519ed 100644 --- a/Netdisco/Makefile.PL +++ b/Netdisco/Makefile.PL @@ -9,7 +9,7 @@ requires 'DBD::SQLite' => 0; requires 'DBIx::Class' => 0; requires 'DBIx::Class::Helper::Row::SubClass' => 0; requires 'Daemon::Control' => 0; -requires 'Dancer' => 0; +requires 'Dancer' => 1.3098; requires 'Dancer::Plugin::DBIC' => 0; requires 'File::ShareDir' => 0; requires 'HTML::Entities' => 0; diff --git a/Netdisco/lib/App/Netdisco/Web.pm b/Netdisco/lib/App/Netdisco/Web.pm index cf2b9276..c3527b47 100644 --- a/Netdisco/lib/App/Netdisco/Web.pm +++ b/Netdisco/lib/App/Netdisco/Web.pm @@ -13,7 +13,26 @@ use App::Netdisco::Web::AuthN; use App::Netdisco::Web::Search; use App::Netdisco::Web::Device; use App::Netdisco::Web::PortControl; -use App::Netdisco::Web::Inventory; + +sub _load_web_plugins { + my $plugin_list = shift; + + foreach my $plugin (@$plugin_list) { + $plugin = 'App::Netdisco::Web::Plugin::'. $plugin + unless $plugin =~ m/^\+/; + $plugin =~ s/^\+//; + + eval "require $plugin"; + } +} + +if (setting('web_plugins') and ref [] eq ref setting('web_plugins')) { + _load_web_plugins( setting('web_plugins') ); +} + +if (setting('extra_web_plugins') and ref [] eq ref setting('extra_web_plugins')) { + _load_web_plugins( setting('extra_web_plugins') ); +} hook 'before_template' => sub { my $tokens = shift; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin.pm b/Netdisco/lib/App/Netdisco/Web/Plugin.pm new file mode 100644 index 00000000..9fa41cda --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin.pm @@ -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; diff --git a/Netdisco/lib/App/Netdisco/Web/Inventory.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Inventory.pm similarity index 66% rename from Netdisco/lib/App/Netdisco/Web/Inventory.pm rename to Netdisco/lib/App/Netdisco/Web/Plugin/Inventory.pm index 0cd33dc3..2532cf14 100644 --- a/Netdisco/lib/App/Netdisco/Web/Inventory.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Inventory.pm @@ -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(); diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index 3a8efa31..3e7626fb 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -29,6 +29,19 @@ engines: # netdisco stuff (can be overidden in the environment .yml) +web_plugins: + - Inventory +# - Report::WirelessDevices +# - Search::Device +# - Search::Node +# - Search::VLAN +# - Search::Port +# - Device::Details +# - Device::Ports +# - Device::Modules +# - Device::Neighbors +# - Device::Addresses + discover_no: [] discover_only: [] diff --git a/Netdisco/share/views/layouts/main.tt b/Netdisco/share/views/layouts/main.tt index 8d33e4d6..d0d88f19 100644 --- a/Netdisco/share/views/layouts/main.tt +++ b/Netdisco/share/views/layouts/main.tt @@ -52,9 +52,11 @@ Netdisco [% IF session.user %]