Remember port search columns/settings in a Cookie
Squashed commit of the following: commit5bb8dc3bc1Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Sep 5 23:48:04 2013 +0100 parse cookie and set column defaults commit05e6acfee5Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 07:12:00 2013 +0100 add list of cols to cookie commit7c5c1b7882Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 2 23:23:48 2013 +0100 submit cookie with port columns options commitf350c34074Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 2 22:46:14 2013 +0100 remove unecessary JS using template var commit7ca1623d2fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 2 22:35:36 2013 +0100 factor out tab-specific stuff to common.js
This commit is contained in:
@@ -4,6 +4,7 @@ use Dancer ':syntax';
|
||||
use Dancer::Plugin::Ajax;
|
||||
use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
use URL::Encode 'url_params_mixed';
|
||||
|
||||
hook 'before' => sub {
|
||||
my @default_port_columns_left = (
|
||||
@@ -53,6 +54,36 @@ hook 'before' => sub {
|
||||
return unless (request->path eq uri_for('/device')->path
|
||||
or index(request->path, uri_for('/ajax/content/device')->path) == 0);
|
||||
|
||||
# override ports form defaults with cookie settings
|
||||
|
||||
my $cookie = cookie('nd_ports-form');
|
||||
my $cdata = url_params_mixed($cookie);
|
||||
|
||||
if ($cdata and ref {} eq ref $cdata) {
|
||||
foreach my $item (@{ var('port_columns') }) {
|
||||
my $key = $item->{name};
|
||||
next unless defined $cdata->{$key}
|
||||
and $cdata->{$key} =~ m/^[[:alnum:]_]+$/;
|
||||
$item->{default} = $cdata->{$key};
|
||||
}
|
||||
|
||||
foreach my $item (@{ var('connected_properties') }) {
|
||||
my $key = $item->{name};
|
||||
next unless defined $cdata->{$key}
|
||||
and $cdata->{$key} =~ m/^[[:alnum:]_]+$/;
|
||||
$item->{default} = $cdata->{$key};
|
||||
}
|
||||
|
||||
foreach my $key (qw/age_num age_unit mac_format/) {
|
||||
params->{$key} ||= $cdata->{$key}
|
||||
if defined $cdata->{$key}
|
||||
and $cdata->{$key} =~ m/^[[:alnum:]_]+$/;
|
||||
}
|
||||
}
|
||||
|
||||
# copy ports form defaults into request query params if this is
|
||||
# a redirect from within the application (tab param is not set)
|
||||
|
||||
foreach my $col (@{ var('port_columns') }) {
|
||||
next unless $col->{default} eq 'on';
|
||||
params->{$col->{name}} = 'checked'
|
||||
@@ -66,9 +97,9 @@ hook 'before' => sub {
|
||||
}
|
||||
|
||||
if (not param('tab') or param('tab') ne 'ports') {
|
||||
params->{'age_num'} = 3;
|
||||
params->{'age_unit'} = 'months';
|
||||
params->{'mac_format'} = 'IEEE';
|
||||
params->{'age_num'} ||= 3;
|
||||
params->{'age_unit'} ||= 'months';
|
||||
params->{'mac_format'} ||= 'IEEE';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -76,12 +107,13 @@ hook 'before_template' => sub {
|
||||
my $tokens = shift;
|
||||
|
||||
# new searches will use these defaults in their sidebars
|
||||
$tokens->{device_ports} = uri_for('/device', {
|
||||
tab => 'ports',
|
||||
age_num => 3,
|
||||
age_unit => 'months',
|
||||
mac_format => 'IEEE',
|
||||
});
|
||||
$tokens->{device_ports} = uri_for('/device', { tab => 'ports' });
|
||||
|
||||
# copy ports form defaults into helper values for building template links
|
||||
|
||||
foreach my $key (qw/age_num age_unit mac_format/) {
|
||||
$tokens->{device_ports}->query_param($key, params->{$key});
|
||||
}
|
||||
|
||||
# for Net::MAC method
|
||||
$tokens->{mac_format_call} = 'as_'. params->{'mac_format'}
|
||||
@@ -121,7 +153,10 @@ get '/device' => require_login sub {
|
||||
}
|
||||
|
||||
params->{'tab'} ||= 'details';
|
||||
template 'device', { d => $dev };
|
||||
template 'device', {
|
||||
d => $dev,
|
||||
device => params->{'tab'},
|
||||
};
|
||||
};
|
||||
|
||||
true;
|
||||
|
||||
@@ -105,6 +105,7 @@ get '/search' => require_login sub {
|
||||
my $vendor_list = [ $s->resultset('Device')->get_distinct_col('vendor') ];
|
||||
|
||||
template 'search', {
|
||||
search => params->{'tab'},
|
||||
model_list => $model_list,
|
||||
os_ver_list => $os_ver_list,
|
||||
vendor_list => $vendor_list,
|
||||
|
||||
Reference in New Issue
Block a user