get rid of device_ports and self_options template vars

This commit is contained in:
Oliver Gorwits
2014-11-03 19:59:01 +00:00
parent 8277763c80
commit 799358f86c
22 changed files with 31 additions and 57 deletions

View File

@@ -370,11 +370,6 @@ together with the correct default search options set.
A path and query string which links to the Device tab of the Search page, A path and query string which links to the Device tab of the Search page,
together with the correct default search options set. together with the correct default search options set.
=item C<device_ports>
A path and query sting which links to the Ports tab of the Device page,
together with the correct default column view options set.
=item C<uri_base> =item C<uri_base>
Used for linking to static content within App::Netdisco safely if the base of Used for linking to static content within App::Netdisco safely if the base of
@@ -389,13 +384,6 @@ template safely if the base of the app is relocated:
<a href="[% uri_for('/search') %]" ...> <a href="[% uri_for('/search') %]" ...>
=item C<self_options>
Available in the Device tabs, use this if you need to refer back to the
current page with some additional parameters, for example:
<a href="[% uri_for('/device/ports', self_options) %]&foo=bar" ...>
=back =back
=head1 Javascript and Stylesheets =head1 Javascript and Stylesheets

View File

@@ -82,7 +82,7 @@ hook 'before_template' => sub {
# fix Plugin Template Variables to be only path+query # fix Plugin Template Variables to be only path+query
$tokens->{$_} = $tokens->{$_}->path_query $tokens->{$_} = $tokens->{$_}->path_query
for qw/search_node search_device device_ports/; for qw/search_node search_device/;
# shorthand access to section and tabname # shorthand access to section and tabname
my @parts = split m{/}, request->path; my @parts = split m{/}, request->path;

View File

@@ -5,20 +5,6 @@ use Dancer::Plugin::Ajax;
use Dancer::Plugin::DBIC; use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible; use Dancer::Plugin::Auth::Extensible;
hook 'before_template' => sub {
my $tokens = shift;
# new searches will use these defaults in their sidebars
$tokens->{device_ports} = uri_for('/device/ports');
# 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');
$self_uri->query_param_delete('prefer');
$tokens->{self_options} = $self_uri->query_form_hash;
};
my $handler = sub { my $handler = sub {
my $q = param('q'); my $q = param('q');
my ($tab) = splat; my ($tab) = splat;

View File

@@ -10,7 +10,7 @@
</tbody> </tbody>
[% FOREACH row IN results %] [% FOREACH row IN results %]
<tr> <tr>
<td><a href="[% device_ports %]&q=[% row.ip | uri %]&f=[% row.port | uri %]"> <td><a href="[% uri_for('/device/ports') %]&q=[% row.ip | uri %]&f=[% row.port | uri %]">
[% row.dns || row.name || row.ip | html_entity %] ( [% row.port | html_entity %] ) </a></td> [% row.dns || row.name || row.ip | html_entity %] ( [% row.port | html_entity %] ) </a></td>
<td><a href="[% search_node %]&q=[% row.remote_ip | uri %]"> <td><a href="[% search_node %]&q=[% row.remote_ip | uri %]">
[% row.remote_ip | html_entity %]</a> [% row.remote_ip | html_entity %]</a>

View File

@@ -31,7 +31,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -117,7 +117,7 @@ $(document).ready(function() {
[% ELSE %] [% ELSE %]
cell_str += ''; cell_str += '';
[% END %] [% END %]
cell_str += '<a class="nd_this-port-only nd_port-only-first" href="[% uri_for('/device/ports',self_options) %]&q=[% params.q | uri %]&f=' cell_str += '<a class="nd_this-port-only nd_port-only-first" href="[% uri_for('/device/ports') %]&q=[% params.q | uri %]&f='
+ encodeURIComponent(row.port) + '&prefer=port">'; + encodeURIComponent(row.port) + '&prefer=port">';
if (row.is_master) { if (row.is_master) {
cell_str += '<small><i class="icon-group muted"></i></small>&nbsp;'; cell_str += '<small><i class="icon-group muted"></i></small>&nbsp;';
@@ -125,7 +125,7 @@ $(document).ready(function() {
cell_str += he.encode(row.port) + '</a>'; cell_str += he.encode(row.port) + '</a>';
if (row.slave_of) { if (row.slave_of) {
cell_str += '<br/>' cell_str += '<br/>'
+ '<a class="nd_this-port-only" href="[% uri_for('/device/ports', self_options) %]&q=[% params.q | uri %]&f=' + '<a class="nd_this-port-only" href="[% uri_for('/device/ports') %]&q=[% params.q | uri %]&f='
+ encodeURIComponent(row.slave_of) + '&prefer=port">' + encodeURIComponent(row.slave_of) + '&prefer=port">'
+ he.encode(row.slave_of) + '</a>'; + he.encode(row.slave_of) + '</a>';
} }
@@ -384,13 +384,13 @@ $(document).ready(function() {
else if (row.remote_type && row.remote_type.match(/(cisco\s+AIR-[L|C]?AP|-K9W8-|^AP:\s)/)) { else if (row.remote_type && row.remote_type.match(/(cisco\s+AIR-[L|C]?AP|-K9W8-|^AP:\s)/)) {
cell_str += '<i class="icon-signal"></i>&nbsp;'; cell_str += '<i class="icon-signal"></i>&nbsp;';
} }
cell_str += '<a href="[% uri_for('/device/ports', self_options) %]&q=' cell_str += '<a href="[% uri_for('/device/ports') %]&q='
+ encodeURIComponent(row.neighbor_alias_ip) + '">'; + encodeURIComponent(row.neighbor_alias_ip) + '">';
var n_dns = row.neighbor_alias_dns ? row.neighbor_alias_dns.replace(d_suffix, '') : ''; var n_dns = row.neighbor_alias_dns ? row.neighbor_alias_dns.replace(d_suffix, '') : '';
cell_str += he.encode(n_dns || row.neighbor_alias_ip) + '</a>'; cell_str += he.encode(n_dns || row.neighbor_alias_ip) + '</a>';
if (row.remote_port) { if (row.remote_port) {
cell_str += ' - ' cell_str += ' - '
+ '<a href="[% uri_for('/device/ports', self_options) %]&q=' + '<a href="[% uri_for('/device/ports') %]&q='
+ encodeURIComponent(row.neighbor_alias_ip) + encodeURIComponent(row.neighbor_alias_ip)
+ '&f=' + encodeURIComponent(row.remote_port) + '&f=' + encodeURIComponent(row.remote_port)
+ '&prefer=port">' + he.encode(row.remote_port || '') + '</a>'; + '&prefer=port">' + he.encode(row.remote_port || '') + '</a>';

View File

@@ -59,7 +59,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -27,7 +27,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.left_dns || row.left_ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.left_dns || row.left_ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {
@@ -45,7 +45,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.right_dns || row.right_ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.right_dns || row.right_ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -25,7 +25,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_duplex=on">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -30,7 +30,7 @@ $(document).ready(function() {
}, { }, {
"data": 'port', "data": 'port',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.switch) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(row.dns || row.name || row.switch) + '(' + he.encode(data) + ')</a>'; return '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.switch) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(row.dns || row.name || row.switch) + '(' + he.encode(data) + ')</a>';
} }
}, { }, {
"data": 'ip_count', "data": 'ip_count',

View File

@@ -27,7 +27,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&c_nodes=on&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&c_nodes=on&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -48,7 +48,7 @@ $(document).ready(function() {
}, { }, {
"data": 'port', "data": 'port',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.switch) + '&f=' + encodeURIComponent(data) + '&c_nodes=on&n_ssid=on">' + he.encode(row.device.dns || row.device.name || row.switch) + '(' + he.encode(data) + ')</a>'; return '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.switch) + '&f=' + encodeURIComponent(data) + '&c_nodes=on&n_ssid=on">' + he.encode(row.device.dns || row.device.name || row.switch) + '(' + he.encode(data) + ')</a>';
} }
}, { }, {
// Included for filtering // Included for filtering

View File

@@ -25,7 +25,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -26,7 +26,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -26,7 +26,7 @@ $(document).ready(function() {
"type": 'portsort', "type": 'portsort',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return type === 'display' ? return type === 'display' ?
'<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>' : '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>' :
data; data;
} }
}, { }, {

View File

@@ -33,7 +33,7 @@ $(document).ready(function() {
{ {
"data": 'ip', "data": 'ip',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(data) + '&f=' + encodeURIComponent(row.port.port) + '&c_nodes=on&n_ssid=on">' + he.encode(row.device.dns || row.device.name || row.ip) + '(' + he.encode(row.port.port) + ')</a>'; return '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(data) + '&f=' + encodeURIComponent(row.port.port) + '&c_nodes=on&n_ssid=on">' + he.encode(row.device.dns || row.device.name || row.ip) + '(' + he.encode(row.port.port) + ')</a>';
} }
}, { }, {
"data": 'broadcast', "data": 'broadcast',

View File

@@ -19,7 +19,7 @@ $(document).ready(function() {
{ {
"data": 'ip', "data": 'ip',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(data) + '">' + he.encode(row.dns || row.ip) + '</a>'; return '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(data) + '">' + he.encode(row.dns || row.ip) + '</a>';
} }
}, { }, {
"data": 'port_count', "data": 'port_count',

View File

@@ -105,7 +105,7 @@
<td>Switch Port</td> <td>Switch Port</td>
<td class="nd_center-cell"> <td class="nd_center-cell">
<a class="nd_linkcell" <a class="nd_linkcell"
href="[% device_ports %]&q=[% node.switch | uri %]&f=[% node.port | uri %]&c_nodes=on&c_neighbors=on"> href="[% uri_for('/device/ports') %]&q=[% node.switch | uri %]&f=[% node.port | uri %]&c_nodes=on&c_neighbors=on">
[% node.switch | html_entity %] - [% node.port | html_entity %] [% node.switch | html_entity %] - [% node.port | html_entity %]
[% '&nbsp;<i class="icon-book text-warning"></i>' IF NOT node.active %]</a> [% '&nbsp;<i class="icon-book text-warning"></i>' IF NOT node.active %]</a>
[% IF node.device.dns AND node.device_port AND node.device_port.name %] [% IF node.device.dns AND node.device_port AND node.device_port.name %]

View File

@@ -45,7 +45,7 @@
</td> </td>
<td>Switch Port</td> <td>Switch Port</td>
<td class="nd_center-cell"> <td class="nd_center-cell">
<a href="[% device_ports %]&q=[% node.switch | uri %]&f=[% node.port | uri %]&c_nodes=on&c_neighbors=on"> <a href="[% uri_for('/device/ports') %]&q=[% node.switch | uri %]&f=[% node.port | uri %]&c_nodes=on&c_neighbors=on">
[% node.switch | html_entity %] - [% node.port | html_entity %]</a> [% node.switch | html_entity %] - [% node.port | html_entity %]</a>
[% '&nbsp;<i class="icon-book text-warning"></i>&nbsp;' IF NOT node.active %] [% '&nbsp;<i class="icon-book text-warning"></i>&nbsp;' IF NOT node.active %]
[% IF node.device.dns AND node.device_port AND node.device_port.name %] [% IF node.device.dns AND node.device_port AND node.device_port.name %]
@@ -69,7 +69,7 @@
</td> </td>
<td>Switch Port</td> <td>Switch Port</td>
<td class="nd_center-cell"> <td class="nd_center-cell">
<a href="[% device_ports %]&q=[% port.ip | uri %]&f=[% port.port | uri %]&c_mac=on&c_nodes=on&c_neighbors=on"> <a href="[% uri_for('/device/ports') %]&q=[% port.ip | uri %]&f=[% port.port | uri %]&c_mac=on&c_nodes=on&c_neighbors=on">
[% port.ip | html_entity %] - [% port.descr | html_entity %]</a> [% port.ip | html_entity %] - [% port.descr | html_entity %]</a>
[% IF port.device.dns AND port.name %] [% IF port.device.dns AND port.name %]
([% port.device.dns | html_entity %] - [% port.name | html_entity %]) ([% port.device.dns | html_entity %] - [% port.name | html_entity %])

View File

@@ -26,7 +26,7 @@ $(document).ready(function() {
if (row.device.dns || row.device.name) { if (row.device.dns || row.device.name) {
ddns = ' (' + he.encode(row.device.dns || row.device.name) + ')'; ddns = ' (' + he.encode(row.device.dns || row.device.name) + ')';
} }
return '<a href="[% device_ports %]&q=' + encodeURIComponent(data) return '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(data)
+ '&f=' + encodeURIComponent(row.port) + '">' + he.encode(data) + '&f=' + encodeURIComponent(row.port) + '">' + he.encode(data)
+ ' [' + he.encode(row.port) + ']</a>' + ddns; + ' [' + he.encode(row.port) + ']</a>' + ddns;
} }

View File

@@ -19,32 +19,32 @@ $(document).ready(function() {
"columns": [{ "columns": [{
"data": 'vlans.vlan', "data": 'vlans.vlan',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a class="nd_linkcell nd_stealth-link" href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + data + '</a>'; return '<a class="nd_linkcell nd_stealth-link" href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '">' + data + '</a>';
} }
}, { }, {
"data": 'ip', "data": 'ip',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(row.dns || row.ip) + '</a>'; return '<a href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(row.dns || row.ip) + '</a>';
} }
}, { }, {
"data": 'vlans.description', "data": 'vlans.description',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a class="nd_linkcell nd_stealth-link" href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>'; return '<a class="nd_linkcell nd_stealth-link" href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
"data": 'model', "data": 'model',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a class="nd_linkcell nd_stealth-link" href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>'; return '<a class="nd_linkcell nd_stealth-link" href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
"data": 'os', "data": 'os',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a class="nd_linkcell nd_stealth-link" href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>'; return '<a class="nd_linkcell nd_stealth-link" href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
"data": 'vendor', "data": 'vendor',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a class="nd_linkcell nd_stealth-link" href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>'; return '<a class="nd_linkcell nd_stealth-link" href="[% uri_for('/device/ports') %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>';
} }
} }
], ],

View File

@@ -31,9 +31,9 @@
href="#[% report.tag %]_pane">[% report.label %]</a></li> href="#[% report.tag %]_pane">[% report.label %]</a></li>
[% IF report.tag == 'portlog' %] [% IF report.tag == 'portlog' %]
<span id="nd_device-name"> <span id="nd_device-name">
<a href="[% device_ports %]&q=[% params.q | uri %]&c_admin=on">[% params.q %]</a> <a href="[% uri_for('/device/ports') %]&q=[% params.q | uri %]&c_admin=on">[% params.q %]</a>
- -
<a href="[% device_ports %]&q=[% params.q | uri %]&f=[% params.f | uri %]&c_admin=on">[% params.f %]</a> <a href="[% uri_for('/device/ports') %]&q=[% params.q | uri %]&f=[% params.f | uri %]&c_admin=on">[% params.f %]</a>
</span> </span>
[% ELSIF report.provides_csv %] [% ELSIF report.provides_csv %]
<span id="nd_device-name"> <span id="nd_device-name">