Plugins can have CSS and Javascript loaded within <head>
This commit is contained in:
@@ -10,6 +10,7 @@ use HTML::Entities (); # to ensure dependency is met
|
||||
use URI::QueryParam (); # part of URI, to add helper methods
|
||||
|
||||
use App::Netdisco::Web::AuthN;
|
||||
use App::Netdisco::Web::Static;
|
||||
use App::Netdisco::Web::Search;
|
||||
use App::Netdisco::Web::Device;
|
||||
use App::Netdisco::Web::Report;
|
||||
|
||||
@@ -18,6 +18,8 @@ hook 'before' => sub {
|
||||
if (session('user') && session->id) {
|
||||
var(user => schema('netdisco')->resultset('User')
|
||||
->find(session('user')));
|
||||
var('user')->port_control(0)
|
||||
if setting('no_port_control');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ use Dancer ':syntax';
|
||||
use Dancer::Plugin;
|
||||
|
||||
set(
|
||||
'_additional_css' => [],
|
||||
'_additional_javascript' => [],
|
||||
'_extra_device_port_cols' => [],
|
||||
'_navbar_items' => [],
|
||||
'_search_tabs' => [],
|
||||
@@ -30,6 +32,32 @@ register 'register_template_path' => sub {
|
||||
$path;
|
||||
};
|
||||
|
||||
sub _register_include {
|
||||
my ($type, $plugin) = @_;
|
||||
|
||||
if (!length $type) {
|
||||
error "bad type to _register_include";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!length $plugin) {
|
||||
error "bad plugin name to register_$type";
|
||||
return;
|
||||
}
|
||||
|
||||
push @{ setting("_additional_$type") }, $plugin;
|
||||
}
|
||||
|
||||
register 'register_css' => sub {
|
||||
my ($self, $plugin) = plugin_args(@_);
|
||||
_register_include('css', $plugin);
|
||||
};
|
||||
|
||||
register 'register_javascript' => sub {
|
||||
my ($self, $plugin) = plugin_args(@_);
|
||||
_register_include('javascript', $plugin);
|
||||
};
|
||||
|
||||
register 'register_device_port_column' => sub {
|
||||
my ($self, $config) = plugin_args(@_);
|
||||
$config->{default} ||= '';
|
||||
|
||||
@@ -77,7 +77,7 @@ ajax '/ajax/content/device/ports' => sub {
|
||||
template 'ajax/device/ports.tt', {
|
||||
results => $results,
|
||||
nodes => $nodes_name,
|
||||
device => $device->ip,
|
||||
device => $device,
|
||||
}, { layout => undef };
|
||||
};
|
||||
|
||||
|
||||
30
Netdisco/lib/App/Netdisco/Web/Static.pm
Normal file
30
Netdisco/lib/App/Netdisco/Web/Static.pm
Normal file
@@ -0,0 +1,30 @@
|
||||
package App::Netdisco::Web::Static;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use Path::Class;
|
||||
|
||||
get '/plugin/*/*.js' => sub {
|
||||
my ($plugin) = splat;
|
||||
|
||||
my $content = template
|
||||
"plugin/$plugin/$plugin.js", {},
|
||||
{ layout => undef };
|
||||
|
||||
send_file \$content,
|
||||
content_type => 'application/javascript',
|
||||
filename => "$plugin.js";
|
||||
};
|
||||
|
||||
get '/plugin/*/*.css' => sub {
|
||||
my ($plugin) = splat;
|
||||
|
||||
my $content = template
|
||||
"plugin/$plugin/$plugin.css", {},
|
||||
{ layout => undef };
|
||||
|
||||
send_file \$content,
|
||||
content_type => 'text/css',
|
||||
filename => "$plugin.css";
|
||||
};
|
||||
|
||||
true;
|
||||
@@ -5,11 +5,17 @@ use Dancer::Plugin::DBIC;
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
|
||||
use File::ShareDir 'dist_dir';
|
||||
use Path::Class;
|
||||
|
||||
register_device_port_column({
|
||||
name => 'c_observiumsparklines',
|
||||
name => 'observiumsparklines',
|
||||
position => 'mid',
|
||||
label => 'Traffic',
|
||||
default => 'on',
|
||||
});
|
||||
|
||||
register_css('observiumsparklines');
|
||||
register_javascript('observiumsparklines');
|
||||
|
||||
true;
|
||||
|
||||
Reference in New Issue
Block a user