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

@@ -1,10 +1,15 @@
0.x
[NEW FEATURES]
* Icon to copy Navbar search text to Device Search Options field (closes #11)
[ENHANCEMENTS]
* Native copy of the Netdisco sort_port routine (#17)
* Refactor begin hooks (closes #16)
* Icon to copy Navbar search text to Device Search Options field (closes #11)
* Re-engineer link generation to ensure sane defaults and remembered options.
This came as a side-effect of removing JS-only links (closes #21)
[BUG FIXES]

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

View File

@@ -87,11 +87,6 @@ body {
height: 100%;
}
/* link port name to restricted search */
.this_port_only {
cursor: pointer;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* many styles for the collapsing lists */

View File

@@ -14,10 +14,10 @@
<td>[% row.alias %]</a>
<td>[% row.dns.remove(settings.domain_suffix) %]</a>
<td class="center_cell"><a class="nd_linkcell"
href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.port %]">[% row.port %]</a></td>
href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.port %]">[% row.port %]</a></td>
<td>[% row.device_port.name %]</td>
<td><a class="nd_linkcell"
href="[% uri_for('/search') %]?tab=device&ip=[% row.subnet %]">[% row.subnet %]</a></td>
href="[% vars.search_device %]&ip=[% row.subnet %]">[% row.subnet %]</a></td>
</tr>
[% END %]
</tbody>

View File

@@ -8,7 +8,7 @@
<td>Location</td>
<td>
<a rel="tooltip" data-placement="top" data-offset="5" title="Find Similar Devices"
href="[% uri_for('/search') %]?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&location=[% d.location | uri %]">[% d.location %]</a>
href="[% vars.search_device %]&location=[% d.location | uri %]">[% d.location %]</a>
</td>
</tr>
<tr>
@@ -19,10 +19,10 @@
<td>Vendor / Model</td>
<td>
<a rel="tooltip" data-placement="top" data-offset="5" title="Find Similar Devices"
href="[% uri_for('/search') %]?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&vendor=[% d.vendor | uri %]">[% d.vendor %]</a>
href="[% vars.search_device %]&vendor=[% d.vendor | uri %]">[% d.vendor %]</a>
/
<a rel="tooltip" data-placement="top" data-offset="5" title="Find Similar Devices"
href="[% uri_for('/search') %]?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&model=[% d.model | uri %]">[% d.model %]</a>
href="[% vars.search_device %]&model=[% d.model | uri %]">[% d.model %]</a>
</td>
</tr>
<tr>
@@ -30,7 +30,7 @@
<td>[% d.os %] /
<a rel="tooltip" data-placement="top" data-offset="5"
title="Find Similar Devices"
href="[% uri_for('/search') %]?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&os_ver=[% d.os_ver | uri %]">[% d.os_ver %]</a>
href="[% vars.search_device %]&os_ver=[% d.os_ver | uri %]">[% d.os_ver %]</a>
</td>
</tr>
<tr>

View File

@@ -23,7 +23,10 @@
[% END %]
</td>
[% IF params.c_port %]
<td><a class="nd_linkcell this_port_only">[% row.port | html_entity %]</a></td>
<td><a class="nd_linkcell" href="[% uri_for('/device',
vars.self_options) %]&q=[% params.q | uri %]&f=[% row.port | uri %]">
[% row.port | html_entity %]
</a></td>
[% END %]
[% IF params.c_descr %]
<td class="center_cell">[% row.descr | html_entity %]</td>
@@ -82,12 +85,13 @@
<td>
[% IF row.remote_ip %]
[% IF row.neighbor %]
<a href="[% uri_for('/device') %]?tab=ports&q=[% row.neighbor.ip | uri %]&f=[% row.remote_port | uri %]">
<a href="[% uri_for('/device',
vars.self_options) %]&q=[% row.neighbor.ip | uri %]&f=[% row.remote_port | uri %]">
[% row.neighbor.dns.remove(settings.domain_suffix) || row.neighbor.ip %]
([% row.remote_port | html_entity %])</a>
[% ELSE %]
<span class="label label-important">N</span>
<a href="[% uri_for('/search') %]?tab=node&q=[% row.remote_ip | uri %]">
<a href="[% vars.search_node %]&q=[% row.remote_ip | uri %]">
[% row.remote_ip %] (port: [% row.remote_port %]
id: [% (row.remote_type _ ' / ') IF row.remote_type %][% row.remote_id %])</a>
[% END %]
@@ -95,16 +99,16 @@
[% FOREACH node IN row.$nodes %]
[% '<br/>' IF row.remote_ip OR NOT loop.first %]
[% '<span class="label label-warning">A</span> &nbsp;' IF NOT node.active %]
<a href="[% uri_for('/search') %]?tab=node&q=[% node.mac | uri %]">[% node.mac %]</a>
<a href="[% vars.search_node %]&q=[% node.mac | uri %]">[% node.mac %]</a>
[% ' (' _ node.time_last_age _ ')' IF params.n_age %]
[% IF params.n_ip %]
[% FOREACH ip IN node.ips %]
<br/>&nbsp; [% '<span class="label label-warning">A</span> &nbsp;' IF NOT ip.active %]
[% SET dns = ip.dns %]
[% IF dns %]
<a href="[% uri_for('/search') %]?tab=node&q=[% ip.ip | uri %]">[% dns %] ([% ip.ip %])</a>
<a href="[% vars.search_node %]&q=[% ip.ip | uri %]">[% dns %] ([% ip.ip %])</a>
[% ELSE %]
<a href="[% uri_for('/search') %]?tab=node&q=[% ip.ip | uri %]">[% ip.ip %]</a>
<a href="[% vars.search_node %]&q=[% ip.ip | uri %]">[% ip.ip %]</a>
[% END %]
[% END %]
[% END %]

View File

@@ -17,12 +17,12 @@
[% WHILE (row = macs.next) %]
<tr>
<td><a class="nd_linkcell"
href="[% uri_for('/search') %]?[% vars.query_defaults.node %]&q=[% row.mac | uri %]">[% row.mac %]</a></td>
href="[% vars.search_node %]&q=[% row.mac | uri %]">[% row.mac %]</a></td>
[% IF params.vendor %]
<td>[% row.oui.company %]</td>
[% END %]
<td>IP &rarr; MAC</td>
<td><a href="[% uri_for('/search') %]?[% vars.query_defaults.node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
<td><a href="[% vars.search_node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
[% ' (' _ row.dns.remove(settings.domain_suffix) _ ')' IF row.dns %]
[% ' <span class="label label-warning">A</span>' IF NOT row.active %]
</td>
@@ -38,7 +38,7 @@
<td>&nbsp;</td>
[% END %]
<td>Switch Port</td>
<td><a href="[% uri_for('/device') %]?tab=ports&q=[% node.switch | url %]&f=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
<td><a href="[% vars.device_ports %]&q=[% node.switch | url %]&f=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
[% ' <span class="label label-warning">A</span>' IF NOT node.active %]
</td>
@@ -55,7 +55,7 @@
<td>&nbsp;</td>
[% END %]
<td>MAC &rarr; IP</td>
<td><a href="[% uri_for('/search') %]?[% vars.query_defaults.node %]&q=[% nodeip.ip | uri %]">[% nodeip.ip %]</a>
<td><a href="[% vars.search_node %]&q=[% nodeip.ip | uri %]">[% nodeip.ip %]</a>
[% ' (' _ nodeip.dns.remove(settings.domain_suffix) _ ')' IF nodeip.dns %]
[% ' <span class="label label-warning">A</span>' IF NOT nodeip.active %]
</td>

View File

@@ -20,7 +20,7 @@
<td>
[% IF first_row %]
<a class="nd_linkcell"
href="[% uri_for('/search') %]?[% vars.query_defaults.node %]&q=[% row.mac | uri %]">[% row.mac %]</a>
href="[% vars.search_node %]&q=[% row.mac | uri %]">[% row.mac %]</a>
[% ELSE %]
&nbsp;
[% END %]
@@ -35,7 +35,7 @@
</td>
[% END %]
<td>MAC &rarr; IP</td>
<td><a href="[% uri_for('/search') %]?[% vars.query_defaults.node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
<td><a href="[% vars.search_node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
[% ' (' _ row.dns.remove(settings.domain_suffix) _ ')' IF row.dns %]
[% ' <span class="label label-warning">A</span>' IF NOT row.active %]
</td>
@@ -51,7 +51,7 @@
<td>
[% IF first_row %]
<a class="nd_linkcell"
href="[% uri_for('/search') %]?[% vars.query_defaults.node %]&q=[% node.mac | uri %]">[% node.mac %]</a>
href="[% vars.search_node %]&q=[% node.mac | uri %]">[% node.mac %]</a>
[% ELSE %]
&nbsp;
[% END %]
@@ -66,7 +66,7 @@
</td>
[% END %]
<td>Switch Port</td>
<td><a href="[% uri_for('/device') %]?tab=ports&q=[% node.switch | url %]&f=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
<td><a href="[% vars.device_ports %]&q=[% node.switch | url %]&f=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
[% ' <span class="label label-warning">A</span>' IF NOT node.active %]
</td>
@@ -82,7 +82,7 @@
<td>
[% IF first_row %]
<a class="nd_linkcell"
href="[% uri_for('/search') %]?[% vars.query_defaults.node %]&q=[% port.mac | uri %]">[% port.mac %]</a>
href="[% vars.search_node %]&q=[% port.mac | uri %]">[% port.mac %]</a>
[% ELSE %]
&nbsp;
[% END %]
@@ -97,7 +97,7 @@
</td>
[% END %]
<td>Switch Port</td>
<td><a href="[% uri_for('/device') %]?tab=ports&q=[% port.ip | url %]&f=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
<td><a href="[% vars.device_ports %]&q=[% port.ip | url %]&f=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
[% ' (' _ port.device.dns.remove(settings.domain_suffix) _ ')' IF port.device.dns %]
</td>
[% IF params.stamps %]

View File

@@ -11,7 +11,7 @@
[% WHILE (row = results.next) %]
<tr>
<td>[% row.name %]</td>
<td><a href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.port %]">[% row.ip %] [ [% row.port %] ]</a>
<td><a href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.port %]">[% row.ip %] [ [% row.port %] ]</a>
[% ' (' _ row.device.dns.remove(settings.domain_suffix) _ ')' IF row.device.dns %]
</td>
<td>[% row.descr %]</td>

View File

@@ -13,17 +13,17 @@
[% WHILE (row = results.next) %]
<tr>
<td><a class="nd_linkcell nd_stealthlink"
href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.vlan %]</a></td>
href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.vlan %]</a></td>
<td><a class="nd_linkcell"
href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.dns %]</a></td>
href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.dns %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.description %]</a></td>
href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.description %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.model %]</a></td>
href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.model %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.os %]</a></td>
href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.os %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% uri_for('/device') %]?tab=ports&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vendor %]</a></td>
href="[% vars.device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vendor %]</a></td>
</tr>
[% END %]
</tbody>

View File

@@ -16,12 +16,12 @@
<tr>
<th>
<a class="nd_stealthlink"
href="[% uri_for('/search') %]?tab=device&matchall=on&vendor=[% platform.vendor %]">
href="[% vars.search_device %]&vendor=[% platform.vendor %]">
[% platform.vendor %]</a>
</th>
<th>
<a class="nd_linkcell"
href="[% uri_for('/search') %]?tab=device&matchall=on&model=[% platform.model %]">
href="[% vars.search_device %]&model=[% platform.model %]">
[% platform.model %]</a>
</th>
<th>[% platform.get_column('count') %]</th>
@@ -46,7 +46,7 @@
<th>[% release.os %]</th>
<th>
<a class="nd_linkcell"
href="[% uri_for('/search') %]?tab=device&matchall=on&os_ver=[% release.os_ver %]">
href="[% vars.search_device %]&os_ver=[% release.os_ver %]">
[% release.os_ver %]</a>
</th>
<th>[% release.get_column('count') %]</th>

View File

@@ -70,10 +70,14 @@
$('#ports_form').trigger('submit');
});
// make all port names clickable to restrict results to that port only
// clickable device port names can simply resubmit AJAX rather than
// fetch the whole page again.
$('body').delegate('.this_port_only', 'click', function() {
event.preventDefault(); // link is real so prevent page submit
var port = $(this).text();
sweep.val(port);
$('.field_clear_icon').show();
$('#ports_form').trigger('submit');
});