diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 927186c1..37b272c5 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -8,77 +8,83 @@ use NetAddr::IP::Lite ':lower'; use App::Netdisco::Util::Web (); # for sort_port hook 'before' => sub { - # list of port detail columns - var('port_columns' => [ - { name => 'c_admin', label => 'Admin Controls', default => '' }, - { name => 'c_port', label => 'Port', default => 'on' }, - { name => 'c_descr', label => 'Description', default => '' }, - { name => 'c_type', label => 'Type', default => '' }, - { name => 'c_duplex', label => 'Duplex', default => '' }, - { name => 'c_lastchange', label => 'Last Change', default => '' }, - { name => 'c_name', label => 'Name', default => 'on' }, - { name => 'c_speed', label => 'Speed', default => '' }, - { name => 'c_mac', label => 'Port MAC', default => '' }, - { name => 'c_mtu', label => 'MTU', default => '' }, - { name => 'c_vlan', label => 'Native VLAN', default => 'on' }, - { name => 'c_vmember', label => 'Tagged VLANs', default => 'on' }, - { name => 'c_power', label => 'PoE', default => '' }, - { name => 'c_nodes', label => 'Connected Nodes', default => '' }, - { name => 'c_neighbors', label => 'Connected Devices', default => 'on' }, - { name => 'c_stp', label => 'Spanning Tree', default => '' }, - { name => 'c_up', label => 'Status', default => '' }, - ]); + # list of port detail columns + var('port_columns' => [ + { name => 'c_admin', label => 'Admin Controls', default => '' }, + { name => 'c_port', label => 'Port', default => 'on' }, + { name => 'c_descr', label => 'Description', default => '' }, + { name => 'c_type', label => 'Type', default => '' }, + { name => 'c_duplex', label => 'Duplex', default => '' }, + { name => 'c_lastchange', label => 'Last Change', default => '' }, + { name => 'c_name', label => 'Name', default => 'on' }, + { name => 'c_speed', label => 'Speed', default => '' }, + { name => 'c_mac', label => 'Port MAC', default => '' }, + { name => 'c_mtu', label => 'MTU', default => '' }, + { name => 'c_vlan', label => 'Native VLAN', default => 'on' }, + { name => 'c_vmember', label => 'Tagged VLANs', default => 'on' }, + { name => 'c_power', label => 'PoE', default => '' }, + { name => 'c_nodes', label => 'Connected Nodes', default => '' }, + { name => 'c_neighbors', label => 'Connected Devices', default => 'on' }, + { name => 'c_stp', label => 'Spanning Tree', default => '' }, + { name => 'c_up', label => 'Status', default => '' }, + ]); - # view settings for port connected devices - var('connected_properties' => [ - { name => 'n_age', label => 'Age Stamp', default => '' }, - { name => 'n_ip', label => 'IP Address', default => 'on' }, - { name => 'n_archived', label => 'Archived Data', default => '' }, - ]); + # view settings for port connected devices + var('connected_properties' => [ + { name => 'n_age', label => 'Age Stamp', default => '' }, + { name => 'n_ip', label => 'IP Address', default => 'on' }, + { name => 'n_archived', label => 'Archived Data', default => '' }, + ]); - # new searches will use these defaults in their sidebars - var('device_ports' => uri_for('/device', { - tab => 'ports', - age_num => 3, - age_unit => 'months', - })); + return unless (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'; - var('device_ports')->query_param($col->{name}, 'checked'); - } + 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'; - var('device_ports')->query_param($col->{name}, 'checked'); - } + 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 (request->path eq uri_for('/device')->path - or index(request->path, uri_for('/ajax/content/device')->path) == 0) { + if (not param('tab') or param('tab') ne 'ports') { + params->{'age_num'} = 3; + params->{'age_unit'} = 'months'; + } +}; - 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'; - } +hook 'before_template' => sub { + my $tokens = shift; - 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'; - } + # new searches will use these defaults in their sidebars + $tokens->{device_ports} = uri_for('/device', { + tab => 'ports', + age_num => 3, + age_unit => 'months', + }); - if (not param('tab') or param('tab') ne 'ports') { - params->{'age_num'} = 3; - params->{'age_unit'} = 'months'; - } + foreach my $col (@{ var('port_columns') }) { + next unless $col->{default} eq 'on'; + $tokens->{device_ports}->query_param($col->{name}, 'checked'); + } - # 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); - } + foreach my $col (@{ var('connected_properties') }) { + next unless $col->{default} eq 'on'; + $tokens->{device_ports}->query_param($col->{name}, 'checked'); + } + + return unless (request->path eq uri_for('/device')->path + or index(request->path, uri_for('/ajax/content/device')->path) == 0); + + # 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'); + $tokens->{self_options} = $self_uri->query_form_hash; }; ajax '/ajax/content/device/:thing' => sub { diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index fde603eb..2238c333 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -9,51 +9,58 @@ use Net::MAC (); use List::MoreUtils (); hook 'before' => sub { - # 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' }, - ]); + # view settings for node options + var('node_options' => [ + { name => 'stamps', label => 'Time Stamps', 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'})); + # view settings for device options + var('device_options' => [ + { name => 'matchall', label => 'Match All Options', default => 'on' }, + ]); - foreach my $col (@{ var('node_options') }) { - next unless $col->{default} eq 'on'; - var('search_node')->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); - foreach my $col (@{ var('device_options') }) { - next unless $col->{default} eq 'on'; - var('search_device')->query_param($col->{name}, 'checked'); - } + 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'; + } - if (request->path eq uri_for('/search')->path - or index(request->path, uri_for('/ajax/content/search')->path) == 0) { + 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'; + } +}; - 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'; - } +hook 'before_template' => sub { + my $tokens = shift; - 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'; - } + # 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'}); - # used in the device search sidebar template to set selected items - foreach my $opt (qw/model vendor os_ver/) { - my $p = (ref [] eq ref param($opt) ? param($opt) - : (param($opt) ? [param($opt)] : [])); - var("${opt}_lkp" => { map { $_ => 1 } @$p }); - } - } + 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); + + # used in the device search sidebar template to set selected items + foreach my $opt (qw/model vendor os_ver/) { + my $p = (ref [] eq ref param($opt) ? param($opt) + : (param($opt) ? [param($opt)] : [])); + $tokens->{"${opt}_lkp"} = { map { $_ => 1 } @$p }; + } }; # device with various properties or a default match-all @@ -226,15 +233,9 @@ get '/search' => sub { } # used in the device search sidebar to populate select inputs - var('model_list' => [ - schema('netdisco')->resultset('Device')->get_distinct_col('model') - ]); - var('os_ver_list' => [ - schema('netdisco')->resultset('Device')->get_distinct_col('os_ver') - ]); - var('vendor_list' => [ - schema('netdisco')->resultset('Device')->get_distinct_col('vendor') - ]); + my $model_list = [ schema('netdisco')->resultset('Device')->get_distinct_col('model') ]; + 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' => [ @@ -244,7 +245,11 @@ get '/search' => sub { { id => 'port', label => 'Port' }, ]); - template 'search'; + template 'search', { + model_list => $model_list, + os_ver_list => $os_ver_list, + vendor_list => $vendor_list, + }; }; true; diff --git a/Netdisco/share/views/ajax/device/addresses.tt b/Netdisco/share/views/ajax/device/addresses.tt index a195b03f..984f340e 100644 --- a/Netdisco/share/views/ajax/device/addresses.tt +++ b/Netdisco/share/views/ajax/device/addresses.tt @@ -14,10 +14,10 @@