tabs now must be plugins also

This commit is contained in:
Oliver Gorwits
2013-02-09 17:49:44 +00:00
parent eafa039bbd
commit a684570fbd
6 changed files with 43 additions and 25 deletions

View File

@@ -300,15 +300,6 @@ get '/device' => sub {
return;
}
# list of tabs
var('tabs' => [
{ id => 'details', label => 'Details' },
{ id => 'ports', label => 'Ports' },
{ id => 'modules', label => 'Modules' },
{ id => 'netmap', label => 'Neighbors' },
{ id => 'addresses', label => 'Addresses' },
]);
params->{'tab'} ||= 'details';
template 'device', { d => $device };
};

View File

@@ -3,7 +3,11 @@ package App::Netdisco::Web::Plugin;
use Dancer ':syntax';
use Dancer::Plugin;
set('navbar_items' => []);
set(
'navbar_items' => [],
'search_tabs' => [],
'device_tabs' => [],
);
register 'register_navbar_item' => sub {
my ($self, $config) = plugin_args(@_);
@@ -23,5 +27,33 @@ register 'register_navbar_item' => sub {
push @{ setting('navbar_items') }, $config;
};
sub _register_tab {
my ($nav, $config) = @_;
my $stash = setting("${nav}_tabs");
die "bad config to register_${nav}_tab\n"
unless length $config->{id}
and length $config->{label};
foreach my $item (@{ $stash }) {
if ($item->{id} eq $config->{id}) {
$item = $config;
return;
}
}
push @{ $stash }, $config;
}
register 'register_search_tab' => sub {
my ($self, $config) = plugin_args(@_);
_register_tab('search', $config);
};
register 'register_device_tab' => sub {
my ($self, $config) = plugin_args(@_);
_register_tab('device', $config);
};
register_plugin;
true;

View File

@@ -237,14 +237,6 @@ get '/search' => sub {
my $os_ver_list = [ schema('netdisco')->resultset('Device')->get_distinct_col('os_ver') ];
my $vendor_list = [ schema('netdisco')->resultset('Device')->get_distinct_col('vendor') ];
# list of tabs
var('tabs' => [
{ id => 'device', label => 'Device' },
{ id => 'node', label => 'Node' },
{ id => 'vlan', label => 'VLAN' },
{ id => 'port', label => 'Port' },
]);
template 'search', {
model_list => $model_list,
os_ver_list => $os_ver_list,