start to save sidebar in datatables state
This commit is contained in:
@@ -4,91 +4,6 @@ use Dancer ':syntax';
|
|||||||
use Dancer::Plugin::Ajax;
|
use Dancer::Plugin::Ajax;
|
||||||
use Dancer::Plugin::DBIC;
|
use Dancer::Plugin::DBIC;
|
||||||
use Dancer::Plugin::Auth::Extensible;
|
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 {
|
hook 'before_template' => sub {
|
||||||
my $tokens = shift;
|
my $tokens = shift;
|
||||||
@@ -96,29 +11,6 @@ hook 'before_template' => sub {
|
|||||||
# new searches will use these defaults in their sidebars
|
# new searches will use these defaults in their sidebars
|
||||||
$tokens->{device_ports} = uri_for('/device/ports');
|
$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
|
# for templates to link to same page with modified query but same options
|
||||||
my $self_uri = uri_for(request->path, scalar params);
|
my $self_uri = uri_for(request->path, scalar params);
|
||||||
$self_uri->query_param_delete('q');
|
$self_uri->query_param_delete('q');
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
"dom": '<"top"l<"nd_datatables-pager"p>f>rt<"bottom"><"clear">',
|
"dom": '<"top"l<"nd_datatables-pager"p>f>rt<"bottom"><"clear">',
|
||||||
"language": {
|
"language": {
|
||||||
"search": '_INPUT_',
|
"search": '_INPUT_',
|
||||||
"searchPlaceholder": 'Filter records...',
|
"searchPlaceholder": 'Filter results...',
|
||||||
"lengthMenu": "Show _MENU_ records."
|
"lengthMenu": "Show _MENU_ rows."
|
||||||
},
|
},
|
||||||
"rowCallback": function (row, data) {
|
"rowCallback": function (row, data) {
|
||||||
// update in-cell content based on current sidebar settings
|
// update in-cell content based on current sidebar settings
|
||||||
@@ -21,12 +21,13 @@
|
|||||||
// TODO: would be nice to update CSV link too
|
// TODO: would be nice to update CSV link too
|
||||||
|
|
||||||
var datatable = $('#[% tabname %]_pane').find('table').first().DataTable();
|
var datatable = $('#[% tabname %]_pane').find('table').first().DataTable();
|
||||||
|
var sidebarform = $('#[% tabname %]_form');
|
||||||
// if no existing state, all columns default to visible.
|
// if no existing state, all columns default to visible.
|
||||||
// on table load, state is saved... we can find out whether there was
|
// 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
|
// loaded state, and if not, use this hook to set initial column
|
||||||
// visibility.
|
// visibility.
|
||||||
if (datatable.state.loaded() === null) {
|
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 id = $(this).attr('id');
|
||||||
var col = datatable.column( id + ':name' );
|
var col = datatable.column( id + ':name' );
|
||||||
if (col.length === 1) {
|
if (col.length === 1) {
|
||||||
@@ -35,9 +36,18 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// save sidebar settings
|
||||||
|
data["sidebarform"] = sidebarform.serializeArray();
|
||||||
|
}
|
||||||
|
|
||||||
// make sure filter is never saved
|
// make sure filter is never saved
|
||||||
data.search.search = "";
|
data.search.search = "";
|
||||||
// make sure paging position is not saved
|
// make sure paging position is not saved
|
||||||
data.start = 0;
|
data.start = 0;
|
||||||
|
},
|
||||||
|
"stateLoadParams": function (settings, data) {
|
||||||
|
// load all sidebar settings
|
||||||
|
var sidebarform = $('#[% tabname %]_form');
|
||||||
|
sidebarform.deserialize( data.sidebarform );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
// on load, establish global delegations for now and future
|
// on load, establish global delegations for now and future
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var tab = '[% tab.tag %]'
|
var tab = '[% tabname %]'
|
||||||
var target = '#' + tab + '_pane';
|
var target = '#' + tab + '_pane';
|
||||||
var portfilter = $('#ports_form').find("input[name=f]");
|
var portfilter = $('#ports_form').find("input[name=f]");
|
||||||
|
|
||||||
@@ -99,6 +99,10 @@
|
|||||||
$('#ports_form').on('change', "input[type=checkbox].nd_dynamic-dp", function(event) {
|
$('#ports_form').on('change', "input[type=checkbox].nd_dynamic-dp", function(event) {
|
||||||
var target = $(this).attr('id');
|
var target = $(this).attr('id');
|
||||||
$('span.' + target).toggle();
|
$('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
|
// activity for admin tasks in device details
|
||||||
|
|||||||
Reference in New Issue
Block a user