add support for admin tasks as plugins
This commit is contained in:
@@ -175,6 +175,24 @@ any query parameters which might customize the report search.
|
|||||||
See the L<App::Netdisco::Web::Plugin::Report::DuplexMismatch> module for a
|
See the L<App::Netdisco::Web::Plugin::Report::DuplexMismatch> module for a
|
||||||
simple example of how to implement the handler.
|
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</admin/mynewfeature> 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
|
=head1 Templates
|
||||||
|
|
||||||
All of Netdisco's web page templates are stashed away in its distribution,
|
All of Netdisco's web page templates are stashed away in its distribution,
|
||||||
|
|||||||
17
Netdisco/lib/App/Netdisco/Web/AdminTask.pm
Normal file
17
Netdisco/lib/App/Netdisco/Web/AdminTask.pm
Normal file
@@ -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;
|
||||||
@@ -7,6 +7,7 @@ set(
|
|||||||
'navbar_items' => [],
|
'navbar_items' => [],
|
||||||
'search_tabs' => [],
|
'search_tabs' => [],
|
||||||
'device_tabs' => [],
|
'device_tabs' => [],
|
||||||
|
'admin_tasks' => [],
|
||||||
'reports_menu' => {},
|
'reports_menu' => {},
|
||||||
'reports' => {},
|
'reports' => {},
|
||||||
'report_order' => [qw/Device Port Node VLAN Network Wireless/],
|
'report_order' => [qw/Device Port Node VLAN Network Wireless/],
|
||||||
@@ -49,6 +50,26 @@ register 'register_navbar_item' => sub {
|
|||||||
push @{ setting('navbar_items') }, $config;
|
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 {
|
sub _register_tab {
|
||||||
my ($nav, $config) = @_;
|
my ($nav, $config) = @_;
|
||||||
my $stash = setting("${nav}_tabs");
|
my $stash = setting("${nav}_tabs");
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -84,6 +84,20 @@
|
|||||||
<i id="navsearchgo" class="icon-search navbar_icon"></i>
|
<i id="navsearchgo" class="icon-search navbar_icon"></i>
|
||||||
</span>
|
</span>
|
||||||
</form>
|
</form>
|
||||||
|
[% IF vars.user.admin %]
|
||||||
|
<ul class="nav">
|
||||||
|
[% IF settings.admin_tasks.size %]
|
||||||
|
<li class="dropdown[% ' active' IF vars.nav == 'admin' %]">
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin Tasks <b class="caret"></b></a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
[% FOREACH ai IN settings.admin_tasks %]
|
||||||
|
<li><a href="[% uri_for('/admin/' _ ai.tag) %]">[% ai.label | html_entity %]</a></li>
|
||||||
|
[% END %]
|
||||||
|
</ul>
|
||||||
|
</li> <!-- /dropdown -->
|
||||||
|
[% END %]
|
||||||
|
</ul>
|
||||||
|
[% END %]
|
||||||
<ul class="nav pull-right">
|
<ul class="nav pull-right">
|
||||||
<li class="nd_navbartext">Logged in as </li>
|
<li class="nd_navbartext">Logged in as </li>
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
|
|||||||
Reference in New Issue
Block a user