diff --git a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod index 23908a02..67a18357 100644 --- a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod +++ b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod @@ -175,6 +175,24 @@ any query parameters which might customize the report search. See the L module for a simple example of how to implement the handler. +=head1 Admin Tasks + +These components appear in the black navigation bar under an Admin menu, but only +if the logged in user has Administrator rights in Netdisco. + +To register an item for display in the Admin menu, use the following code: + + register_admin_task({ + tag => 'newfeature', + label => 'My New Feature', + }); + +This causes an item to appear in the Admin menu with a visible text of "My New +Feature" which when clicked sends the user to the C page. +Note that this won't work for any target link - the path must be an +App::Netdisco Dancer route handler. Please bug the App::Netdisco devs if you +want arbitrary links supported. + =head1 Templates All of Netdisco's web page templates are stashed away in its distribution, diff --git a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm new file mode 100644 index 00000000..5316e8eb --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm @@ -0,0 +1,17 @@ +package App::Netdisco::Web::AdminTask; + +use Dancer ':syntax'; + +get '/admin/*' => sub { + my ($tag) = splat; + + # trick the ajax into working as if this were a tabbed page + params->{tab} = $tag; + + var(nav => 'admin'); + template 'admintask', { + task => setting('admin_tasks')->{ $tag }, + }; +}; + +true; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin.pm b/Netdisco/lib/App/Netdisco/Web/Plugin.pm index 49c7e6a6..11a6a179 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin.pm @@ -7,6 +7,7 @@ set( 'navbar_items' => [], 'search_tabs' => [], 'device_tabs' => [], + 'admin_tasks' => [], 'reports_menu' => {}, 'reports' => {}, 'report_order' => [qw/Device Port Node VLAN Network Wireless/], @@ -49,6 +50,26 @@ register 'register_navbar_item' => sub { push @{ setting('navbar_items') }, $config; }; +register 'register_admin_task' => sub { + my ($self, $config) = plugin_args(@_); + + if (!length $config->{tag} + or !length $config->{label}) { + + error "bad config to register_admin_task"; + return; + } + + foreach my $item (@{ setting('admin_tasks') }) { + if ($item->{tag} eq $config->{tag}) { + $item = $config; + return; + } + } + + push @{ setting('admin_tasks') }, $config; +}; + sub _register_tab { my ($nav, $config) = @_; my $stash = setting("${nav}_tabs"); diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm new file mode 100644 index 00000000..15f208c9 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm @@ -0,0 +1,24 @@ +package App::Netdisco::Web::Plugin::AdminTask::PseudoDevice; + +use Dancer ':syntax'; +use Dancer::Plugin::Ajax; +use Dancer::Plugin::DBIC; + +use App::Netdisco::Web::Plugin; + +register_admin_task({ + tag => 'pseudodevice', + label => 'Manage Pseudo Devices', +}); + +#ajax '/ajax/content/report/duplexmismatch' => sub { +# my $set = schema('netdisco')->resultset('Virtual::DuplexMismatch'); +# return unless $set->count; +# +# content_type('text/html'); +# template 'ajax/report/duplexmismatch.tt', { +# results => $set, +# }, { layout => undef }; +#}; + +true; diff --git a/Netdisco/share/views/layouts/main.tt b/Netdisco/share/views/layouts/main.tt index f752a221..676a0ce2 100644 --- a/Netdisco/share/views/layouts/main.tt +++ b/Netdisco/share/views/layouts/main.tt @@ -84,6 +84,20 @@ + [% IF vars.user.admin %] + + [% END %]