use qstr in templates

This commit is contained in:
Oliver Gorwits
2014-01-26 13:35:53 +00:00
parent ddd29a845e
commit 00a23958a7
30 changed files with 87 additions and 46 deletions

View File

@@ -7,6 +7,8 @@ package App::Netdisco::DB::Result::Device;
use strict;
use warnings;
use URI::Escape;
use base 'DBIx::Class::Core';
__PACKAGE__->table("device");
__PACKAGE__->add_columns(
@@ -273,4 +275,20 @@ Number of seconds which have elapsed since the value of C<last_arpnip>.
sub since_last_arpnip { return (shift)->get_column('since_last_arpnip') }
=head1 ADDITIONAL METHODS
=head2 qstr
Returns a query string suitable for including in Netdisco URLs which will
reference this device.
=cut
sub qstr {
my $row = shift;
return sprintf 'q=%s&uuid=%s',
uri_escape($row->dns || $row->ip),
uri_escape($row->ip);
}
1;

View File

@@ -4,6 +4,7 @@ use strict;
use warnings;
use base 'DBIx::Class::Core';
use URI::Escape;
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
@@ -58,4 +59,16 @@ __PACKAGE__->add_columns(
},
);
sub left_qstr {
my $row = shift;
return sprintf 'q=%s&uuid=%s',
uri_escape($row->left_dns || $row->left_ip), uri_escape($row->left_ip);
}
sub right_qstr {
my $row = shift;
return sprintf 'q=%s&uuid=%s',
uri_escape($row->right_dns || $row->right_ip), uri_escape($row->right_ip);
}
1;

View File

@@ -10,6 +10,7 @@ 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 Path::Class 'dir';
use URI::Escape;
use App::Netdisco::Web::AuthN;
use App::Netdisco::Web::Static;
@@ -66,6 +67,11 @@ hook 'before_template' => sub {
$tokens->{$_} = $tokens->{$_}->path_query
for qw/search_node search_device device_ports/;
# precreated query string which uses uuid
$tokens->{qstr} = sprintf 'q=%s&uuid=%s',
uri_escape(param('q') || ''),
uri_escape(param('uuid') || param('q') || '');
# allow very long lists of ports
$Template::Directive::WHILE_MAX = 10_000;

View File

@@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
use URI::Escape;
register_device_tab({ tag => 'netmap', label => 'Neighbors' });
@@ -35,7 +36,8 @@ sub _add_children {
push @legit, $c;
push @{$ptr}, {
name => _get_name($c),
fullname => (var('devices')->{$c} || $c),
qstr => (sprintf 'q=%s&uuid=%s',
uri_escape(var('devices')->{$c} || $c), uri_escape($c)),
ip => $c,
};
}
@@ -93,7 +95,8 @@ get '/ajax/data/device/netmap' => require_login sub {
my %tree = (
ip => $start,
name => _get_name($start),
fullname => (var('devices')->{$start} || $start),
qstr => (sprintf 'q=%s&uuid=%s',
uri_escape(var('devices')->{$start} || $start), uri_escape($start)),
children => [],
);