support for plugins for navbar items
This commit is contained in:
		| @@ -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(); | ||||
		Reference in New Issue
	
	Block a user