From ca6a08ef4628d19649d902b50b4c1b63310ee02a Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 25 Oct 2014 14:51:15 +0100 Subject: [PATCH] Change from ?tab=tabname param to .../tabname path The reason for this is that DataTables keys local data on the page path, so each tab should have its own path. We're already doing this for reports and admin tasks, so it also makes sense to have consistency with search and device tabs. Squashed commit of the following: commit 4ad33a23a81122496adfe561ad14f039e6255eff Author: Oliver Gorwits Date: Sat Oct 25 14:46:17 2014 +0100 fix search preference selection commit 363e094935d386961e8773f787af41c46b83129a Author: Oliver Gorwits Date: Sat Oct 25 14:36:45 2014 +0100 fix css selector to match begins with /search commit 43c972ee0d9401f74dcc3bd30052dba130b0d068 Author: Oliver Gorwits Date: Sat Oct 25 14:18:24 2014 +0100 fix history push commit 84f83eb46874b0222c0484014389713e4f027c8a Author: Oliver Gorwits Date: Sat Oct 25 14:06:44 2014 +0100 update sidebar form for tab-path, remove hidden tab name field commit 344d4679a83f714c998cd475c041f8effab0c696 Author: Oliver Gorwits Date: Sat Oct 25 14:05:49 2014 +0100 update template links for tab path commit 9cf370d7eb4413aac6fc19c2c13a9bf670600965 Author: Oliver Gorwits Date: Sat Oct 25 14:04:57 2014 +0100 move tab-specific JS from common into specific includes files commit c2d8592a18e389535368d1e74fed29fe5a0eabd8 Author: Oliver Gorwits Date: Sat Oct 25 14:02:46 2014 +0100 fix mode commit 52487cea47eaaea7f5c74536ad6d4bb2a8d6ba4c Author: Oliver Gorwits Date: Sat Oct 25 14:01:15 2014 +0100 move from tab param to tabname template var commit b5a2424631a0050d5de3bc658746a40cd822e869 Merge: 531782b d8102bf Author: Oliver Gorwits Date: Sat Oct 25 10:50:00 2014 +0100 Merge branch 'master' into em-device-ports-json --- Netdisco/lib/App/Netdisco/Util/Graph.pm | 2 +- Netdisco/lib/App/Netdisco/Web/AdminTask.pm | 5 +- Netdisco/lib/App/Netdisco/Web/Device.pm | 15 ++-- Netdisco/lib/App/Netdisco/Web/Report.pm | 5 +- Netdisco/lib/App/Netdisco/Web/Search.pm | 30 ++++--- .../public/javascripts/dataTables.colVis.js | 0 Netdisco/share/public/javascripts/netdisco.js | 8 +- .../share/views/ajax/admintask/orphaned.tt | 2 +- Netdisco/share/views/ajax/device/netmap.tt | 4 +- Netdisco/share/views/ajax/device/ports.tt | 4 +- .../views/ajax/report/apradiochannelpower.tt | 2 +- .../views/ajax/report/devicepoestatus.tt | 2 +- .../views/ajax/report/moduleinventory.tt | 2 +- .../share/views/ajax/report/vlaninventory.tt | 4 +- Netdisco/share/views/device.tt | 11 +-- Netdisco/share/views/js/admintask.js | 7 ++ Netdisco/share/views/js/common.js | 80 ++----------------- Netdisco/share/views/js/device.js | 35 ++++++++ Netdisco/share/views/js/report.js | 8 ++ Netdisco/share/views/js/search.js | 11 +++ Netdisco/share/views/layouts/main.tt | 8 +- Netdisco/share/views/search.tt | 10 +-- 22 files changed, 128 insertions(+), 127 deletions(-) mode change 100755 => 100644 Netdisco/share/public/javascripts/dataTables.colVis.js diff --git a/Netdisco/lib/App/Netdisco/Util/Graph.pm b/Netdisco/lib/App/Netdisco/Util/Graph.pm index ba5c2747..630ec1b6 100644 --- a/Netdisco/lib/App/Netdisco/Util/Graph.pm +++ b/Netdisco/lib/App/Netdisco/Util/Graph.pm @@ -326,7 +326,7 @@ sub graph_addnode { $node{URL} = "/device?&q=$ip"; } else { - $node{URL} = "/search?tab=node&q=$ip"; + $node{URL} = "/search/node?q=$ip"; # Overrides any colors given to nodes above. Bug 1094208 $node{fillcolor} = $CONFIG{'node_problem'} || 'red'; } diff --git a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm index e0986398..3cee326b 100644 --- a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm +++ b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm @@ -64,11 +64,10 @@ ajax '/ajax/control/admin/delete' => require_role admin => sub { get '/admin/*' => require_role admin => sub { my ($tag) = splat; - # trick the ajax into working as if this were a tabbed page - params->{tab} = $tag; - var(nav => 'admin'); template 'admintask', { + # trick the ajax into working as if this were a tabbed page + tabname => $tag, task => setting('_admin_tasks')->{ $tag }, }; }; diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index a2de2486..e4fccf93 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -55,7 +55,7 @@ hook 'before' => sub { { name => 'n_archived', label => 'Archived Data', default => '' }, ]); - return unless (request->path eq uri_for('/device')->path + return unless (index(request->path, uri_for('/device')->path) == 0 or index(request->path, uri_for('/ajax/content/device')->path) == 0); # override ports form defaults with cookie settings @@ -121,7 +121,7 @@ hook 'before_template' => sub { my $tokens = shift; # new searches will use these defaults in their sidebars - $tokens->{device_ports} = uri_for('/device', { tab => 'ports' }); + $tokens->{device_ports} = uri_for('/device/ports'); # copy ports form defaults into helper values for building template links @@ -143,7 +143,7 @@ hook 'before_template' => sub { $tokens->{device_ports}->query_param($col->{name}, 'checked'); } - return unless (request->path eq uri_for('/device')->path + return unless (index(request->path, uri_for('/device')->path) == 0 or index(request->path, uri_for('/ajax/content/device')->path) == 0); # for templates to link to same page with modified query but same options @@ -154,8 +154,9 @@ hook 'before_template' => sub { $tokens->{self_options} = $self_uri->query_form_hash; }; -get '/device' => require_login sub { +my $handler = sub { my $q = param('q'); + my ($tab) = splat; my $schema = schema('netdisco')->resultset('Device'); # we are passed either dns or ip @@ -175,11 +176,13 @@ get '/device' => require_login sub { my $first = $dev->first; my $others = ($schema->search({dns => $first->dns})->count() - 1); - params->{'tab'} ||= 'details'; template 'device', { display_name => ($others ? $first->ip : $first->dns), - device => params->{'tab'}, + tabname => ($tab || 'details'), }; }; +get '/device' => require_login $handler; +get '/device/*' => require_login $handler; + true; diff --git a/Netdisco/lib/App/Netdisco/Web/Report.pm b/Netdisco/lib/App/Netdisco/Web/Report.pm index 740cd950..208c732d 100644 --- a/Netdisco/lib/App/Netdisco/Web/Report.pm +++ b/Netdisco/lib/App/Netdisco/Web/Report.pm @@ -48,12 +48,11 @@ get '/report/*' => require_login sub { ]; } - # trick the ajax into working as if this were a tabbed page - params->{tab} = $tag; - var( nav => 'reports' ); template 'report', { + # trick the ajax into working as if this were a tabbed page + tabname => $tag, report => setting('_reports')->{$tag}, domain_list => $domain_list, class_list => $class_list, diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index 54fa0b6d..9d8d6998 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -38,8 +38,8 @@ hook 'before_template' => sub { my $tokens = shift; # new searches will use these defaults in their sidebars - $tokens->{search_node} = uri_for('/search', {tab => 'node'}); - $tokens->{search_device} = uri_for('/search', {tab => 'device'}); + $tokens->{search_node} = uri_for('/search/node'); + $tokens->{search_device} = uri_for('/search/device'); foreach my $col (@{ var('node_options') }) { next unless $col->{default} eq 'on'; @@ -62,18 +62,24 @@ hook 'before_template' => sub { } }; -get '/search' => require_login sub { +my $handler = sub { my $q = param('q'); + my ($tab) = splat; my $s = schema('netdisco'); - if (not param('tab')) { + my $prefer = param('prefer'); + $prefer = '' + unless defined $prefer and $prefer =~ m/^(?:device|node|vlan|port)$/; + $tab ||= param('prefer'); + + if (not $tab) { if (not $q) { return redirect uri_for('/')->path; } # pick most likely tab for initial results if ($q =~ m/^\d+$/) { - params->{'tab'} = 'vlan'; + $tab = 'vlan'; } else { my $nd = $s->resultset('Device')->search_fuzzy($q); @@ -82,15 +88,14 @@ get '/search' => require_login sub { if ($nd and $nd->count) { if ($nd->count == 1) { # redirect to device details for the one device - return redirect uri_for('/device', { - tab => 'details', + return redirect uri_for('/device/details', { q => $nd->first->ip, f => '', })->path_query; } # multiple devices - params->{'tab'} = 'device'; + $tab = 'device'; } elsif ($s->resultset('DevicePort') ->search({ @@ -101,12 +106,12 @@ get '/search' => require_login sub { ], })->count) { - params->{'tab'} = 'port'; + $tab = 'port'; } } # if all else fails - params->{'tab'} ||= 'node'; + $tab ||= 'node'; } # used in the device search sidebar to populate select inputs @@ -115,11 +120,14 @@ get '/search' => require_login sub { my $vendor_list = [ $s->resultset('Device')->get_distinct_col('vendor') ]; template 'search', { - search => params->{'tab'}, + tabname => $tab, model_list => $model_list, os_ver_list => $os_ver_list, vendor_list => $vendor_list, }; }; +get '/search' => require_login $handler; +get '/search/*' => require_login $handler; + true; diff --git a/Netdisco/share/public/javascripts/dataTables.colVis.js b/Netdisco/share/public/javascripts/dataTables.colVis.js old mode 100755 new mode 100644 diff --git a/Netdisco/share/public/javascripts/netdisco.js b/Netdisco/share/public/javascripts/netdisco.js index 1750106d..103f6fb0 100644 --- a/Netdisco/share/public/javascripts/netdisco.js +++ b/Netdisco/share/public/javascripts/netdisco.js @@ -94,7 +94,7 @@ function update_content(from, to) { is_from_history_plugin = 1; window.History.pushState( {name: to, fields: $(to_form).serializeArray()}, - pgtitle, uri_base + '/' + path + '?' + $(to_form).serialize() + pgtitle, uri_base + '/' + path + '/' + to + '?' + $(to_form).serialize() ); is_from_history_plugin = 0; } @@ -145,7 +145,7 @@ function device_form_state(e) { $(id).show(); // if form still has any field val, set strikethough - if (e.parents('form[action="/search"]').length > 0 && with_val != 0) { + if (e.parents('form[action^="/search"]').length > 0 && with_val != 0) { $('#nq').css('text-decoration', 'line-through'); } @@ -184,8 +184,8 @@ $(document).ready(function() { if ($('#nq').val()) { $(this).parents('form').append( $(document.createElement('input')).attr('type', 'hidden') - .attr('name', 'tab') - .attr('value', $(this).data('tab')) + .attr('name', 'prefer') + .attr('value', $(this).data('prefer')) ).submit(); } }); diff --git a/Netdisco/share/views/ajax/admintask/orphaned.tt b/Netdisco/share/views/ajax/admintask/orphaned.tt index d0a9bda2..64ce2968 100644 --- a/Netdisco/share/views/ajax/admintask/orphaned.tt +++ b/Netdisco/share/views/ajax/admintask/orphaned.tt @@ -75,7 +75,7 @@ [% FOREACH row IN network %] - + [% row.dns || row.name || row.ip | html_entity %] [% IF row.location %] diff --git a/Netdisco/share/views/ajax/device/netmap.tt b/Netdisco/share/views/ajax/device/netmap.tt index f75e91b2..f0f960e4 100644 --- a/Netdisco/share/views/ajax/device/netmap.tt +++ b/Netdisco/share/views/ajax/device/netmap.tt @@ -56,8 +56,8 @@ function to_class(name) { return 'nd_' + name.replace(/\./g, "_") } // handler for clicking on a circle - redirect to that device's netmap function circleClick(d) { - window.location = '[% uri_for('/device') %]?tab=netmap' - + '&q=' + d.fullname + window.location = '[% uri_for('/device/netmap') %]' + + '?q=' + d.fullname + '&depth=[% params.depth | uri %]' + '&vlan=[% params.vlan | uri %]'; } diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index 9e0ce64f..12a35090 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -254,7 +254,7 @@ $(document).ready(function() { [% ELSE %] "render": function ( data, type, row, meta ) { if (row.native_vlan && type === 'display') { - return '' + data + ''; + return '' + data + ''; } else { return data; @@ -272,7 +272,7 @@ $(document).ready(function() { var arr = row.vlan_membership; arr = arr.sort(function(a, b){return a-b}); arr = jQuery.map( arr, function( a ) { - return '' + a + ''; + return '' + a + ''; }); if (row.vlan_membership.length > 10) { return '
(' diff --git a/Netdisco/share/views/ajax/report/apradiochannelpower.tt b/Netdisco/share/views/ajax/report/apradiochannelpower.tt index 3a283562..a0b7936d 100644 --- a/Netdisco/share/views/ajax/report/apradiochannelpower.tt +++ b/Netdisco/share/views/ajax/report/apradiochannelpower.tt @@ -25,7 +25,7 @@ function groupString(d) { "use strict"; var s = ''; s = s + 'Device: '; - s = s + ''; + s = s + ''; s = s + he.encode(d.dns || d.device_name || d.ip); if (d.dns || d.device_name) { s = s + ' (' + he.encode(d.ip) + ') '; diff --git a/Netdisco/share/views/ajax/report/devicepoestatus.tt b/Netdisco/share/views/ajax/report/devicepoestatus.tt index 76e0ec33..c6eee84b 100644 --- a/Netdisco/share/views/ajax/report/devicepoestatus.tt +++ b/Netdisco/share/views/ajax/report/devicepoestatus.tt @@ -51,7 +51,7 @@ function groupString(d) { "use strict"; var s = ''; s = s + 'Device: '; - s = s + ''; + s = s + ''; s = s + he.encode(d.dns || d.name || d.ip); if (d.dns || d.name) { s = s + ' (' + he.encode(d.ip) + ') '; diff --git a/Netdisco/share/views/ajax/report/moduleinventory.tt b/Netdisco/share/views/ajax/report/moduleinventory.tt index 19c0ab6c..d9eff292 100644 --- a/Netdisco/share/views/ajax/report/moduleinventory.tt +++ b/Netdisco/share/views/ajax/report/moduleinventory.tt @@ -39,7 +39,7 @@ $(document).ready(function() { { "data": 'ip', "render": function(data, type, row, meta) { - return '' + he.encode(row.device.dns || row.device.name || row.ip) + ''; + return '' + he.encode(row.device.dns || row.device.name || row.ip) + ''; } }, { "data": 'description', diff --git a/Netdisco/share/views/ajax/report/vlaninventory.tt b/Netdisco/share/views/ajax/report/vlaninventory.tt index 5b27c15d..d732866d 100644 --- a/Netdisco/share/views/ajax/report/vlaninventory.tt +++ b/Netdisco/share/views/ajax/report/vlaninventory.tt @@ -18,12 +18,12 @@ $(document).ready(function() { { "data": 'vlan', "render": function(data, type, row, meta) { - return '' + data + ''; + return '' + data + ''; } }, { "data": 'description', "render": function(data, type, row, meta) { - return '' + he.encode(data || '') + ''; + return '' + he.encode(data || '') + ''; } }, { "data": 'dcount', diff --git a/Netdisco/share/views/device.tt b/Netdisco/share/views/device.tt index 63b978ee..7f56b79c 100644 --- a/Netdisco/share/views/device.tt +++ b/Netdisco/share/views/device.tt @@ -13,10 +13,9 @@
[% FOREACH tab IN settings._device_tabs %] -