support for plugins for navbar items
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
							
								
								
									
										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(); | ||||
| @@ -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: [] | ||||
|  | ||||
|   | ||||
| @@ -52,9 +52,11 @@ | ||||
|       <a class="brand" href="[% uri_for('/') %]">Netdisco</a> | ||||
|       [% IF session.user %] | ||||
|       <ul class="nav"> | ||||
|         <li[% ' class="active"' IF vars.nav == 'inventory' %]> | ||||
|           <a href="[% uri_for('/inventory') %]">Inventory</a> | ||||
|         [% FOREACH ni IN settings.navbar_items %] | ||||
|         <li[% ' class="active"' IF vars.nav == ni.id %]> | ||||
|           <a href="[% uri_for(ni.path) %]">[% ni.label %]</a> | ||||
|         </li> | ||||
|         [% END %] | ||||
|         [% IF more_dd.size %] | ||||
|         <li class="dropdown"> | ||||
|           <a href="#" class="dropdown-toggle" data-toggle="dropdown"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user