removing JS-only links (closes #21)

This commit is contained in:
Oliver Gorwits
2012-04-09 22:55:10 +01:00
parent bec395c2d0
commit 5192b52d55
14 changed files with 132 additions and 75 deletions

View File

@@ -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';
};

View File

@@ -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);
}
};

View File

@@ -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' },