diff --git a/Changes b/Changes index 042350df..92c3c49f 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,15 @@ 0.x + [NEW FEATURES] + + * Icon to copy Navbar search text to Device Search Options field (closes #11) + [ENHANCEMENTS] * Native copy of the Netdisco sort_port routine (#17) * Refactor begin hooks (closes #16) - * Icon to copy Navbar search text to Device Search Options field (closes #11) + * Re-engineer link generation to ensure sane defaults and remembered options. + This came as a side-effect of removing JS-only links (closes #21) [BUG FIXES] diff --git a/Netdisco/lib/Netdisco/Web.pm b/Netdisco/lib/Netdisco/Web.pm index 6fe60d7c..a856250a 100644 --- a/Netdisco/lib/Netdisco/Web.pm +++ b/Netdisco/lib/Netdisco/Web.pm @@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC; use Socket6 (); # to ensure dependency is met use HTML::Entities (); # to ensure dependency is met +use URI::QueryParam (); # part of URI, to add helper methods use Netdisco::Web::AuthN; use Netdisco::Web::Search; @@ -26,17 +27,6 @@ hook 'before_template' => sub { $Template::Directive::WHILE_MAX = 10_000; }; -# set up query strings which describe default search options. -# these are used in both Device and Search templates -hook 'before_template' => sub { - var('query_defaults' => { map { ($_ => "tab=$_") } qw/node device/ }); - - var('query_defaults')->{node} .= "\&$_=". (param($_) || '') - for qw/stamps vendor archived partial/; - var('query_defaults')->{device} .= "\&$_=". (param($_) || '') - for qw/matchall/; -}; - get '/' => sub { template 'index'; }; diff --git a/Netdisco/lib/Netdisco/Web/Device.pm b/Netdisco/lib/Netdisco/Web/Device.pm index ca83b16d..5e37451b 100644 --- a/Netdisco/lib/Netdisco/Web/Device.pm +++ b/Netdisco/lib/Netdisco/Web/Device.pm @@ -33,18 +33,48 @@ hook 'before' => sub { { name => 'n_archived', label => 'Archived Data', default => '' }, ]); - if (request->path eq uri_for('/device')->path) { - # new searches will have these defaults in the ports sidebar + # new searches will use these defaults in their sidebars + var('device_ports' => uri_for('/device', { + tab => 'ports', + age_num => 3, + age_unit => 'months', + })); + + foreach my $col (@{ var('port_columns') }) { + next unless $col->{default} eq 'on'; + var('device_ports')->query_param($col->{name}, 'checked'); + } + + foreach my $col (@{ var('connected_properties') }) { + next unless $col->{default} eq 'on'; + var('device_ports')->query_param($col->{name}, 'checked'); + } + + if (request->path eq uri_for('/device')->path + or index(request->path, uri_for('/ajax/content/device')->path) == 0) { + + foreach my $col (@{ var('port_columns') }) { + next unless $col->{default} eq 'on'; + params->{$col->{name}} = 'checked' + if not param('tab') or param('tab') ne 'ports'; + } + + foreach my $col (@{ var('connected_properties') }) { + next unless $col->{default} eq 'on'; + params->{$col->{name}} = 'checked' + if not param('tab') or param('tab') ne 'ports'; + } + if (not param('tab') or param('tab') ne 'ports') { - foreach my $col (@{ var('port_columns') }) { - params->{$col->{name}} = 'checked' if $col->{default} eq 'on'; - } - foreach my $col (@{ var('connected_properties') }) { - params->{$col->{name}} = 'checked' if $col->{default} eq 'on'; - } params->{'age_num'} = 3; params->{'age_unit'} = 'months'; } + + # for templates to link to same page with modified query but same options + my $self_uri = uri_for(request->path, scalar params); + $self_uri->query_param_delete('q'); + $self_uri->query_param_delete('f'); + var('self_options' => $self_uri->query_form_hash); } }; diff --git a/Netdisco/lib/Netdisco/Web/Search.pm b/Netdisco/lib/Netdisco/Web/Search.pm index 01159ccf..68d36b51 100644 --- a/Netdisco/lib/Netdisco/Web/Search.pm +++ b/Netdisco/lib/Netdisco/Web/Search.pm @@ -10,25 +10,43 @@ use List::MoreUtils (); use Net::DNS (); hook 'before' => sub { - if (request->path eq uri_for('/search')->path) { - # new searches have these defaults in their sidebars - if (not param('tab') or param('tab') ne 'node') { - params->{'stamps'} = 'checked'; - } - if (not param('tab') or param('tab') ne 'device') { - params->{'matchall'} = 'checked'; + # view settings for node options + var('node_options' => [ + { name => 'stamps', label => 'Time Stamps', default => 'on' }, + ]); + # view settings for device options + var('device_options' => [ + { name => 'matchall', label => 'Match All Options', default => 'on' }, + ]); + + # new searches will use these defaults in their sidebars + var('search_node' => uri_for('/search', {tab => 'node'})); + var('search_device' => uri_for('/search', {tab => 'device'})); + + foreach my $col (@{ var('node_options') }) { + next unless $col->{default} eq 'on'; + var('search_node')->query_param($col->{name}, 'checked'); + } + + foreach my $col (@{ var('device_options') }) { + next unless $col->{default} eq 'on'; + var('search_device')->query_param($col->{name}, 'checked'); + } + + if (request->path eq uri_for('/search')->path + or index(request->path, uri_for('/ajax/content/search')->path) == 0) { + + foreach my $col (@{ var('node_options') }) { + next unless $col->{default} eq 'on'; + params->{$col->{name}} = 'checked' + if not param('tab') or param('tab') ne 'node'; } - # used in the device search sidebar to populate select inputs - var('model_list' => [ - schema('netdisco')->resultset('Device')->get_distinct('model') - ]); - var('os_ver_list' => [ - schema('netdisco')->resultset('Device')->get_distinct('os_ver') - ]); - var('vendor_list' => [ - schema('netdisco')->resultset('Device')->get_distinct('vendor') - ]); + foreach my $col (@{ var('device_options') }) { + next unless $col->{default} eq 'on'; + params->{$col->{name}} = 'checked' + if not param('tab') or param('tab') ne 'device'; + } # used in the device search sidebar template to set selected items foreach my $opt (qw/model vendor os_ver/) { @@ -215,6 +233,17 @@ get '/search' => sub { } } + # used in the device search sidebar to populate select inputs + var('model_list' => [ + schema('netdisco')->resultset('Device')->get_distinct('model') + ]); + var('os_ver_list' => [ + schema('netdisco')->resultset('Device')->get_distinct('os_ver') + ]); + var('vendor_list' => [ + schema('netdisco')->resultset('Device')->get_distinct('vendor') + ]); + # list of tabs var('tabs' => [ { id => 'device', label => 'Device' }, diff --git a/Netdisco/public/css/netdisco.css b/Netdisco/public/css/netdisco.css index 518a7ef9..11f98ecd 100644 --- a/Netdisco/public/css/netdisco.css +++ b/Netdisco/public/css/netdisco.css @@ -87,11 +87,6 @@ body { height: 100%; } -/* link port name to restricted search */ -.this_port_only { - cursor: pointer; -} - /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* many styles for the collapsing lists */ diff --git a/Netdisco/views/ajax/device/addresses.tt b/Netdisco/views/ajax/device/addresses.tt index dfadf46e..a195b03f 100644 --- a/Netdisco/views/ajax/device/addresses.tt +++ b/Netdisco/views/ajax/device/addresses.tt @@ -14,10 +14,10 @@