diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index f7d9e07f..488347a7 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -4,91 +4,6 @@ use Dancer ':syntax'; use Dancer::Plugin::Ajax; use Dancer::Plugin::DBIC; use Dancer::Plugin::Auth::Extensible; -use URL::Encode 'url_params_mixed'; - -hook 'before' => sub { - my @default_port_columns_left = ( - { name => 'c_port', label => 'Port', default => '' }, - ); - - my @default_port_columns_right = ( - { name => 'c_descr', label => 'Description', default => '' }, - { name => 'c_type', label => 'Type', default => '' }, - { name => 'c_duplex', label => 'Duplex', default => '' }, - { name => 'c_lastchange', label => 'Last Change', default => '' }, - { name => 'c_name', label => 'Name', default => '' }, - { name => 'c_speed', label => 'Speed', default => '' }, - { name => 'c_mac', label => 'Port MAC', default => '' }, - { name => 'c_mtu', label => 'MTU', default => '' }, - { name => 'c_pvid', label => 'Native VLAN', default => '' }, - { name => 'c_vmember', label => 'VLAN Membership', default => '' }, - { name => 'c_power', label => 'PoE', default => '' }, - { name => 'c_ssid', label => 'SSID', default => '' }, - { name => 'c_nodes', label => 'Show Nodes', default => '' }, - { name => 'c_neighbors', label => 'Connected Devices', default => 'on' }, - { name => 'c_stp', label => 'Spanning Tree', default => '' }, - { name => 'c_up', label => 'Status', default => '' }, - { name => 'c_admin', label => 'Port Controls', default => '' }, - ); - - # build list of port detail columns - my @port_columns = (); - - push @port_columns, - grep {$_->{position} eq 'left'} @{ setting('_extra_device_port_cols') }; - push @port_columns, @default_port_columns_left; - push @port_columns, - grep {$_->{position} eq 'mid'} @{ setting('_extra_device_port_cols') }; - push @port_columns, @default_port_columns_right; - push @port_columns, - grep {$_->{position} eq 'right'} @{ setting('_extra_device_port_cols') }; - - var('port_columns' => \@port_columns); - - # view settings for port connected devices - var('connected_properties' => [ - { name => 'n_age', label => 'Age Stamp', default => '' }, - { name => 'n_ip', label => 'IP Address', default => 'on' }, - { name => 'n_netbios', label => 'NetBIOS', default => 'on' }, - { name => 'n_ssid', label => 'SSID', default => 'on' }, - { name => 'n_vendor', label => 'Vendor', default => '' }, - { name => 'n_archived', label => 'Archived Data', default => '' }, - ]); - - return unless (index(request->path, uri_for('/device')->path) == 0 - or index(request->path, uri_for('/ajax/content/device')->path) == 0); - - # copy ports form defaults into request query params if this is - # a redirect from within the application (tab param is not set) - - if (param('reset') or not param('tab') or param('tab') ne 'ports') { - foreach my $col (@{ var('port_columns') }) { - delete params->{$col->{name}}; - params->{$col->{name}} = 'checked' - if $col->{default} eq 'on'; - } - - foreach my $col (@{ var('connected_properties') }) { - delete params->{$col->{name}}; - params->{$col->{name}} = 'checked' - if $col->{default} eq 'on'; - } - - # not stored in the cookie - params->{'age_num'} ||= 3; - params->{'age_unit'} ||= 'months'; - params->{'mac_format'} ||= 'IEEE'; - - if (param('reset')) { - params->{'age_num'} = 3; - params->{'age_unit'} = 'months'; - params->{'mac_format'} = 'IEEE'; - - # nuke the port params cookie - cookie('nd_ports-form' => '', expires => '-1 day'); - } - } -}; hook 'before_template' => sub { my $tokens = shift; @@ -96,29 +11,6 @@ hook 'before_template' => sub { # new searches will use these defaults in their sidebars $tokens->{device_ports} = uri_for('/device/ports'); - # copy ports form defaults into helper values for building template links - - foreach my $key (qw/age_num age_unit mac_format/) { - $tokens->{device_ports}->query_param($key, params->{$key}); - } - - # for Net::MAC method - $tokens->{mac_format_call} = 'as_'. params->{'mac_format'} - if params->{'mac_format'}; - - foreach my $col (@{ var('port_columns') }) { - next unless $col->{default} eq 'on'; - $tokens->{device_ports}->query_param($col->{name}, 'checked'); - } - - foreach my $col (@{ var('connected_properties') }) { - next unless $col->{default} eq 'on'; - $tokens->{device_ports}->query_param($col->{name}, 'checked'); - } - - 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 my $self_uri = uri_for(request->path, scalar params); $self_uri->query_param_delete('q'); diff --git a/Netdisco/share/views/ajax/datatabledefaults.tt b/Netdisco/share/views/ajax/datatabledefaults.tt index ba3cc1dc..a6f8b654 100644 --- a/Netdisco/share/views/ajax/datatabledefaults.tt +++ b/Netdisco/share/views/ajax/datatabledefaults.tt @@ -6,8 +6,8 @@ "dom": '<"top"l<"nd_datatables-pager"p>f>rt<"bottom"><"clear">', "language": { "search": '_INPUT_', - "searchPlaceholder": 'Filter records...', - "lengthMenu": "Show _MENU_ records." + "searchPlaceholder": 'Filter results...', + "lengthMenu": "Show _MENU_ rows." }, "rowCallback": function (row, data) { // update in-cell content based on current sidebar settings @@ -21,12 +21,13 @@ // TODO: would be nice to update CSV link too var datatable = $('#[% tabname %]_pane').find('table').first().DataTable(); + var sidebarform = $('#[% tabname %]_form'); // if no existing state, all columns default to visible. // on table load, state is saved... we can find out whether there was // loaded state, and if not, use this hook to set initial column // visibility. if (datatable.state.loaded() === null) { - $('#[% tabname %]_form').find('input[type="checkbox"]').each( function() { + sidebarform.find('input[type="checkbox"]').each( function() { var id = $(this).attr('id'); var col = datatable.column( id + ':name' ); if (col.length === 1) { @@ -35,9 +36,18 @@ } }); } + else { + // save sidebar settings + data["sidebarform"] = sidebarform.serializeArray(); + } // make sure filter is never saved data.search.search = ""; // make sure paging position is not saved data.start = 0; + }, + "stateLoadParams": function (settings, data) { + // load all sidebar settings + var sidebarform = $('#[% tabname %]_form'); + sidebarform.deserialize( data.sidebarform ); } diff --git a/Netdisco/share/views/js/device.js b/Netdisco/share/views/js/device.js index 028768d6..c12c9dd4 100644 --- a/Netdisco/share/views/js/device.js +++ b/Netdisco/share/views/js/device.js @@ -27,7 +27,7 @@ // on load, establish global delegations for now and future $(document).ready(function() { - var tab = '[% tab.tag %]' + var tab = '[% tabname %]' var target = '#' + tab + '_pane'; var portfilter = $('#ports_form').find("input[name=f]"); @@ -99,6 +99,10 @@ $('#ports_form').on('change', "input[type=checkbox].nd_dynamic-dp", function(event) { var target = $(this).attr('id'); $('span.' + target).toggle(); + + // save new sidebar settings + var datatable = $('#[% tabname %]_pane').find('table').first().DataTable(); + datatable.state.save(); }); // activity for admin tasks in device details