complete defaults into templates, attempt to set cookie in handler
This commit is contained in:
3
Build.PL
3
Build.PL
@@ -74,7 +74,8 @@ Module::Build->new(
|
||||
'Term::UI' => '0',
|
||||
'Try::Tiny' => '0',
|
||||
'URI' => '0',
|
||||
'URL::Encode' => '0.01',
|
||||
'URL::Encode' => '0.03',
|
||||
'URL::Encode::XS' => 0,
|
||||
'YAML' => '0.84',
|
||||
'YAML::XS' => '0.41',
|
||||
},
|
||||
|
||||
@@ -81,11 +81,14 @@ hook 'before' => sub {
|
||||
$key =~ s|.*/(\w+)/(\w+)$|${1}_${2}|;
|
||||
vars->{'sidebar_key'} = $key;
|
||||
|
||||
# search or report from navbar can ignore params
|
||||
return if param('firstsearch');
|
||||
|
||||
my $defaults = dclone (setting('sidebar_defaults')->{$key} or return);
|
||||
push @{ vars->{'guards'} },
|
||||
guard { setting('sidebar_defaults')->{$key} = $defaults };
|
||||
|
||||
# new searches will use these defaults in their sidebars
|
||||
# otherwise update defaults to contain the passed url params
|
||||
setting('sidebar_defaults')->{$key}->{$_}->{'default'} = params->{$_}
|
||||
for keys %{ $defaults };
|
||||
};
|
||||
@@ -126,6 +129,7 @@ hook 'before_template' => sub {
|
||||
$tokens->{$sidebar_key}->query_param($col,
|
||||
setting('sidebar_defaults')->{$sidebar_key}->{$col}->{'default'});
|
||||
|
||||
# used by the sidebar templates when first rendering
|
||||
$tokens->{"${sidebar_key}_defaults"}->{$col}
|
||||
= setting('sidebar_defaults')->{$sidebar_key}->{$col}->{'default'};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use Dancer::Plugin::Ajax;
|
||||
use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use URI ();
|
||||
use Storable 'dclone';
|
||||
use Scope::Guard 'guard';
|
||||
use URL::Encode 'url_params_mixed';
|
||||
@@ -50,20 +51,22 @@ hook 'before' => sub {
|
||||
push @{ vars->{'guards'} },
|
||||
guard { setting('sidebar_defaults')->{'device_ports'} = $defaults };
|
||||
|
||||
foreach my $key (keys %{ setting('sidebar_defaults')->{'device_ports'} }) {
|
||||
next unless defined $cdata->{$key}
|
||||
and $cdata->{$key} =~ m/^[[:alnum:]_]+$/;
|
||||
foreach my $key (keys %{ $defaults }) {
|
||||
setting('sidebar_defaults')->{'device_ports'}->{$key}->{'default'}
|
||||
= $cdata->{$key};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return unless (request->path eq uri_for('/device')->path
|
||||
or index(request->path, uri_for('/ajax/content/device')->path) == 0);
|
||||
hook 'before_template' => sub {
|
||||
return unless var('sidebar_key') and (var('sidebar_key') eq 'device_ports');
|
||||
|
||||
# TODO set cookie
|
||||
# if (param('reset') or not param('tab') or param('tab') ne 'ports') {
|
||||
my $uri = URI->new();
|
||||
foreach my $key (keys %{ setting('sidebar_defaults')->{'device_ports'} }) {
|
||||
$uri->query_param($key => params->{$key}) if params->{$key};
|
||||
}
|
||||
cookie('nd_ports-form' => $uri->query(), expires => '365 days');
|
||||
};
|
||||
|
||||
get '/device' => require_login sub {
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
[%- ELSE -%]
|
||||
<span><i class="icon-leaf"></i>
|
||||
[%- END -%]
|
||||
<a href="[% report_moduleinventory %]&description=[% nodes.$item.module.description | uri %]">[% nodes.$item.module.description -%]</a>
|
||||
<a href="[% uri_for('/report/moduleinventory') %]?description=[% nodes.$item.module.description | uri %]">[% nodes.$item.module.description -%]</a>
|
||||
[%- IF nodes.$item.module.name -%]
|
||||
<a href="[% report_moduleinventory %]&name=[% nodes.$item.module.name | uri %]">([% nodes.$item.module.name %])</a>
|
||||
<a href="[% uri_for('/report/moduleinventory') %]?name=[% nodes.$item.module.name | uri %]">([% nodes.$item.module.name %])</a>
|
||||
[%- 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 -%]
|
||||
<a href="[% report_moduleinventory %]&serial=[% nodes.$item.module.serial | uri %]">[serial: [% nodes.$item.module.serial %]]</a>
|
||||
<a href="[% uri_for('/report/moduleinventory') %]?serial=[% nodes.$item.module.serial | uri %]">[serial: [% nodes.$item.module.serial %]]</a>
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.type -%]
|
||||
/ <a href="[% report_moduleinventory %]&type=[% nodes.$item.module.type | uri %]">[% nodes.$item.module.type %]</a>
|
||||
/ <a href="[% uri_for('/report/moduleinventory') %]?type=[% nodes.$item.module.type | uri %]">[% nodes.$item.module.type %]</a>
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.model -%]
|
||||
/ <a href="[% report_moduleinventory %]&model=[% nodes.$item.module.model | uri %]">[% nodes.$item.module.model %]</a>
|
||||
/ <a href="[% uri_for('/report/moduleinventory') %]?model=[% nodes.$item.module.model | uri %]">[% nodes.$item.module.model %]</a>
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.fru -%]
|
||||
<b>[FRU]</b>
|
||||
|
||||
@@ -92,16 +92,6 @@
|
||||
update_csv_download_link('device', '[% tab.tag %]', '[% tab.provides_csv %]');
|
||||
|
||||
[% IF tab.tag == 'ports' %]
|
||||
// to be fair I can't remember why we do this in JS and not from the app
|
||||
// perhaps because selecting form fields to go in the cookie is easier?
|
||||
// var cookie = $('#ports_form').find('input,select')
|
||||
// .not('#nd_port-query,input[name="q"],input[name="tab"]')
|
||||
// .serializeArray();
|
||||
// $('#ports_form').find('input[type="checkbox"]').map(function() {
|
||||
// cookie.push({'name': 'columns', 'value': $(this).attr('name')});
|
||||
// });
|
||||
// $.cookie('nd_ports-form', $.param(cookie) ,{ expires: 365 });
|
||||
|
||||
// form reset icon on ports tab
|
||||
$('#nd_sidebar-reset-link').attr('href', uri_base + '/device?tab=[% tab.tag %]&reset=on&' +
|
||||
$('#ports_form')
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<ul class="dropdown-menu">
|
||||
[% FOREACH item IN settings._reports_menu.$category %]
|
||||
[% NEXT IF settings._reports.$item.hidden %]
|
||||
<li><a href="[% uri_for('/report/' _ item) %]">[% settings._reports.$item.label | html_entity %]</a></li>
|
||||
<li><a href="[% uri_for('/report/' _ item) %]?firstsearch=on">[% settings._reports.$item.label | html_entity %]</a></li>
|
||||
[% END %]
|
||||
</ul>
|
||||
</li>
|
||||
@@ -138,6 +138,7 @@
|
||||
<form class="navbar-search pull-left" method="get" action="[% uri_for('/search') %]">
|
||||
<input placeholder="Find Anything" class="search-query span3"
|
||||
id="nq" name="q" value="[% display_name %]" type="text" autocomplete="off"/>
|
||||
<input name="firstsearch" type="hidden" value="on">
|
||||
<div class="btn-group nd_navbar-search-group">
|
||||
<button class="btn btn-inverse nd_navbar-search-icon">
|
||||
<span style="font-size: 18px;">
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="fruonly"
|
||||
name="fruonly"[% ' checked="checked"' IF params.fruonly %]/>
|
||||
name="fruonly"[% ' checked="checked"' IF report_moduleinventory_defaults.fruonly %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="fruonly">
|
||||
<span class="nd_searchcheckbox uneditable-input">FRU Only</span>
|
||||
@@ -67,7 +67,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="matchall"
|
||||
name="matchall"[% ' checked="checked"' IF params.matchall %]/>
|
||||
name="matchall"[% ' checked="checked"' IF report_moduleinventory_defaults.matchall %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="matchall">
|
||||
<span class="nd_searchcheckbox uneditable-input">Match All Options</span>
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="matchall"
|
||||
name="matchall"[% ' checked="checked"' IF params.matchall %]/>
|
||||
name="matchall"[% ' checked="checked"' IF search_device_defaults.matchall %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="matchall">
|
||||
<span class="nd_searchcheckbox uneditable-input">Match All Options</span>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="stamps"
|
||||
name="stamps"[% ' checked="checked"' IF params.stamps %]/>
|
||||
name="stamps"[% ' checked="checked"' IF search_node_defaults.stamps %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="stamps">
|
||||
<span class="nd_searchcheckbox uneditable-input">Time Stamps</span>
|
||||
@@ -13,7 +13,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="deviceports"
|
||||
name="deviceports"[% ' checked="checked"' IF params.deviceports %]/>
|
||||
name="deviceports"[% ' checked="checked"' IF search_node_defaults.deviceports %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="deviceports">
|
||||
<span class="nd_searchcheckbox uneditable-input">Device Ports</span>
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="show_vendor"
|
||||
name="show_vendor"[% ' checked="checked"' IF params.show_vendor %]/>
|
||||
name="show_vendor"[% ' checked="checked"' IF search_node_defaults.show_vendor %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="show_vendor">
|
||||
<span class="nd_searchcheckbox uneditable-input">Vendor</span>
|
||||
@@ -31,7 +31,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="archived"
|
||||
name="archived"[% ' checked="checked"' IF params.archived %]/>
|
||||
name="archived"[% ' checked="checked"' IF search_node_defaults.archived %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="archived">
|
||||
<span class="nd_searchcheckbox uneditable-input">
|
||||
@@ -41,7 +41,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on nd_sidebar-legend">
|
||||
<input type="checkbox" id="node_partial"
|
||||
name="partial"[% ' checked="checked"' IF params.partial %]/>
|
||||
name="partial"[% ' checked="checked"' IF search_node_defaults.partial %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="node_partial">
|
||||
<span class="nd_searchcheckbox uneditable-input">Partial Match</span>
|
||||
@@ -52,20 +52,20 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="age_invert"
|
||||
name="age_invert"[% ' checked="checked"' IF params.age_invert %]/>
|
||||
name="age_invert"[% ' checked="checked"' IF search_node_defaults.age_invert %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="age_invert">
|
||||
<span class="nd_searchcheckbox uneditable-input">Not within...</span>
|
||||
</label>
|
||||
</div>
|
||||
<input class="nd_side-input" id="daterange"
|
||||
type="text" name="daterange" value="[% params.daterange | html_entity %]"/>
|
||||
type="text" name="daterange" value="[% search_node_defaults.daterange | html_entity %]"/>
|
||||
</div>
|
||||
<div class="clearfix">
|
||||
<em class="muted">MAC address format:</em><br/>
|
||||
<select id="nd_node-mac-format" name="mac_format">
|
||||
[% FOREACH format IN [ 'IEEE', 'Cisco', 'Microsoft', 'Sun' ] %]
|
||||
<option[% ' selected="selected"' IF params.mac_format == format %]>[% format %]</option>
|
||||
<option[% ' selected="selected"' IF search_node_defaults.mac_format == format %]>[% format %]</option>
|
||||
[% END %]
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="port_partial"
|
||||
name="partial"[% ' checked="checked"' IF params.partial %]/>
|
||||
name="partial"[% ' checked="checked"' IF search_port_defaults.partial %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="port_partial">
|
||||
<span class="nd_searchcheckbox uneditable-input">Partial Match</span>
|
||||
@@ -13,7 +13,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="port_uplink"
|
||||
name="uplink"[% ' checked="checked"' IF params.uplink %]/>
|
||||
name="uplink"[% ' checked="checked"' IF search_port_defaults.uplink %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="port_uplink">
|
||||
<span class="nd_searchcheckbox uneditable-input">Uplinks</span>
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class="clearfix input-prepend">
|
||||
<label class="add-on">
|
||||
<input type="checkbox" id="port_ethernet"
|
||||
name="ethernet"[% ' checked="checked"' IF params.ethernet %]/>
|
||||
name="ethernet"[% ' checked="checked"' IF search_port_defaults.ethernet %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="port_ethernet">
|
||||
<span class="nd_searchcheckbox uneditable-input">Ethernet Only</span>
|
||||
|
||||
Reference in New Issue
Block a user