diff --git a/lib/App/Netdisco/Web.pm b/lib/App/Netdisco/Web.pm index fe2d7cc3..241ddfa0 100644 --- a/lib/App/Netdisco/Web.pm +++ b/lib/App/Netdisco/Web.pm @@ -71,6 +71,24 @@ Dancer::Session::Cookie::init(session); # workaround for https://github.com/PerlDancer/Dancer/issues/935 hook after_error_render => sub { setting('layout' => 'main') }; +hook 'before' => sub { + my $key = request->path; + if (param('tab') and ($key !~ m/ajax/)) { + $key .= ('/' . param('tab')); + } + $key =~ s|.*/(\w+)/(\w+)$|${1}_${2}|; + vars->{'sidebar_key'} = $key; + + return unless param('firstsearch') + and exists setting('sidebar_defaults')->{$key}; + + # new searches will use these defaults in their sidebars + my %params = %{ setting('sidebar_defaults')->{$key} }; + foreach my $p (keys %params) { + params->{$p} = $params{$p} if $params{$p}; + } +}; + # this hook should be loaded _after_ all plugins hook 'before_template' => sub { my $tokens = shift; @@ -92,9 +110,34 @@ hook 'before_template' => sub { $tokens->{table_showrecordsmenu} = to_json( setting('table_showrecordsmenu') ); + # linked searches will use these defaults in their sidebars + foreach my $sidebar_key (keys %{ setting('sidebar_defaults') }) { + my ($mode, $report) = ($sidebar_key =~ m/(\w+)_(\w+)/); + if ($mode =~ m/^search$/) { + $tokens->{$sidebar_key} = uri_for("/$mode", {tab => $report}); + } + elsif ($mode =~ m/^report$/) { + $tokens->{$sidebar_key} = uri_for("/$mode/$report"); + } + + if (exists setting('sidebar_defaults')->{$sidebar_key}) { + foreach my $col (keys %{ setting('sidebar_defaults')->{$sidebar_key} }) { + if (var('sidebar_key') eq $sidebar_key) { + $tokens->{$sidebar_key}->query_param($col, params->{$col}) + if params->{$col}; + } + else { + $tokens->{$sidebar_key}->query_param($col, + setting('sidebar_defaults')->{$sidebar_key}->{$col}); + } + } + } + + $tokens->{$sidebar_key} = $tokens->{$sidebar_key}->path_query; + } + # fix Plugin Template Variables to be only path+query - $tokens->{$_} = $tokens->{$_}->path_query - for qw/search_node search_device device_ports/; + $tokens->{device_ports} = $tokens->{device_ports}->path_query; # allow very long lists of ports $Template::Directive::WHILE_MAX = 10_000; diff --git a/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm b/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm index a3aa2dfd..2d1e0584 100644 --- a/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm +++ b/lib/App/Netdisco/Web/Plugin/Report/ModuleInventory.pm @@ -16,28 +16,6 @@ register_report( } ); -hook 'before' => sub { - return - unless ( - request->path eq uri_for('/report/moduleinventory')->path - or index( request->path, - uri_for('/ajax/content/report/moduleinventory')->path ) == 0 - ); - - # view settings - var('module_options' => [ - { name => 'fruonly', - label => 'FRU Only', - default => 'on' - }, - { name => 'matchall', - label => 'Match All Options', - default => 'on' - }, - ] - ); -}; - hook 'before_template' => sub { my $tokens = shift; diff --git a/lib/App/Netdisco/Web/Report.pm b/lib/App/Netdisco/Web/Report.pm index bf48d73b..069068db 100644 --- a/lib/App/Netdisco/Web/Report.pm +++ b/lib/App/Netdisco/Web/Report.pm @@ -17,10 +17,6 @@ get '/report/*' => require_login sub { elsif ( $tag eq 'moduleinventory' ) { $class_list = [ schema('netdisco')->resultset('DeviceModule') ->get_distinct_col('class') ]; - - foreach my $col ( @{ var('module_options') } ) { - params->{$col->{name}} = 'checked' if $col->{default} eq 'on'; - } } elsif ( $tag eq 'portssid' ) { $ssid_list = [ schema('netdisco')->resultset('DevicePortSsid') diff --git a/lib/App/Netdisco/Web/Search.pm b/lib/App/Netdisco/Web/Search.pm index 4ee39116..c1684f64 100644 --- a/lib/App/Netdisco/Web/Search.pm +++ b/lib/App/Netdisco/Web/Search.pm @@ -8,51 +8,9 @@ use Dancer::Plugin::Auth::Extensible; use App::Netdisco::Util::Web 'sql_match'; use NetAddr::MAC (); -hook 'before' => sub { - # view settings for node options - var('node_options' => [ - { name => 'stamps', label => 'Time Stamps', default => 'on' }, - { name => 'deviceports', label => 'Device Ports', default => 'on' }, - ]); - - # view settings for port options - var('port_options' => [ - { name => 'ethernet', label => 'Ethernet Only', default => 'on' }, - ]); - - # view settings for device options - var('device_options' => [ - { name => 'matchall', label => 'Match All Options', default => 'on' }, - ]); - - return unless param('firstsearch') and - (request->path eq uri_for('/search')->path - or index(request->path, uri_for('/ajax/content/search')->path) == 0); - - foreach my $col (@{ var('node_options') }, - @{ var('port_options') }, - @{ var('device_options') }) { - params->{$col->{name}} = 'checked' if $col->{default} eq 'on'; - } -}; - hook 'before_template' => sub { my $tokens = shift; - # new searches will use these defaults in their sidebars - $tokens->{search_node} = uri_for('/search', {tab => 'node'}); - $tokens->{search_device} = uri_for('/search', {tab => 'device'}); - - foreach my $col (@{ var('node_options') }) { - next unless $col->{default} eq 'on'; - $tokens->{search_node}->query_param($col->{name}, 'checked'); - } - - foreach my $col (@{ var('device_options') }) { - next unless $col->{default} eq 'on'; - $tokens->{search_device}->query_param($col->{name}, 'checked'); - } - return unless (request->path eq uri_for('/search')->path or index(request->path, uri_for('/ajax/content/search')->path) == 0); diff --git a/share/config.yml b/share/config.yml index b9c8892b..3b3346cf 100644 --- a/share/config.yml +++ b/share/config.yml @@ -85,6 +85,25 @@ web_plugins: - Device::Neighbors - Device::Addresses extra_web_plugins: [] +sidebar_defaults: + search_node: + stamps: checked + deviceports: checked + show_vendor: null + archived: null + partial: null + age_invert: null + daterange: null + mac_format: IEEE + search_port: + partial: null + uplink: null + ethernet: checked + search_device: + matchall: checked + report_moduleinventory: + fruonly: checked + matchall: checked jobqueue_refresh: 10 safe_password_store: true reports: [] diff --git a/share/views/ajax/device/modules.tt b/share/views/ajax/device/modules.tt index 834864e5..f8ec6dbf 100644 --- a/share/views/ajax/device/modules.tt +++ b/share/views/ajax/device/modules.tt @@ -20,9 +20,9 @@ [%- ELSE -%]   [%- END -%] - [% nodes.$item.module.description -%] + [% nodes.$item.module.description -%] [%- IF nodes.$item.module.name -%] - ([% nodes.$item.module.name %]) + ([% nodes.$item.module.name %]) [%- END -%] [%- IF nodes.$item.module.fw_ver -%] fw: [% nodes.$item.module.fw_ver %] @@ -34,13 +34,13 @@ sw: [% nodes.$item.module.sw_ver %] [%- END -%] [%- IF nodes.$item.module.serial -%] - [serial: [% nodes.$item.module.serial %]] + [serial: [% nodes.$item.module.serial %]] [%- END -%] [%- IF nodes.$item.module.type -%] - / [% nodes.$item.module.type %] + / [% nodes.$item.module.type %] [%- END -%] [%- IF nodes.$item.module.model -%] - / [% nodes.$item.module.model %] + / [% nodes.$item.module.model %] [%- END -%] [%- IF nodes.$item.module.fru -%] [FRU] diff --git a/share/views/ajax/report/moduleinventory.tt b/share/views/ajax/report/moduleinventory.tt index 9c6576b8..a22a4ac0 100644 --- a/share/views/ajax/report/moduleinventory.tt +++ b/share/views/ajax/report/moduleinventory.tt @@ -44,32 +44,32 @@ $(document).ready(function() { }, { "data": 'description', "render": function(data, type, row, meta) { - return '' + he.encode(data || '') + ''; + return '' + he.encode(data || '') + ''; } }, { "data": 'name', "render": function(data, type, row, meta) { - return '' + he.encode(data || '') + ''; + return '' + he.encode(data || '') + ''; } }, { "data": 'class', "render": function(data, type, row, meta) { - return '' + he.encode(capitalizeFirstLetter(data + '')) + ''; + return '' + he.encode(capitalizeFirstLetter(data + '')) + ''; } }, { "data": 'type', "render": function(data, type, row, meta) { - return '' + he.encode(data || '') + ''; + return '' + he.encode(data || '') + ''; } }, { "data": 'model', "render": function(data, type, row, meta) { - return '' + he.encode(data || '') + ''; + return '' + he.encode(data || '') + ''; } }, { "data": 'serial', "render": function(data, type, row, meta) { - return '' + he.encode(data || '') + ''; + return '' + he.encode(data || '') + ''; } }, { "data": 'hw_ver', @@ -95,7 +95,7 @@ $(document).ready(function() { { "data": 'class', "render": function(data, type, row, meta) { - return '' + he.encode(capitalizeFirstLetter(data + '')) + ''; + return '' + he.encode(capitalizeFirstLetter(data + '')) + ''; } }, { "data": 'count', diff --git a/share/views/layouts/main.tt b/share/views/layouts/main.tt index d180128c..66bdb64b 100644 --- a/share/views/layouts/main.tt +++ b/share/views/layouts/main.tt @@ -86,7 +86,7 @@