From 531782b30c157348b769d78439c0afb65fc5ff95 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 23 Oct 2014 23:04:02 +0100 Subject: [PATCH] working device ports sidebar column and in-cell checkboxes --- Netdisco/share/config.yml | 28 ++++++++++++ .../share/views/ajax/datatabledefaults.tt | 22 ++++++++++ Netdisco/share/views/ajax/device/ports.tt | 43 ++++++------------- Netdisco/share/views/js/common.js | 1 + 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index 7e14a201..b793adfd 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -85,6 +85,34 @@ table_pagesize: 10 table_showrecordsmenu: - [10, 25, 50, 100, '-1'] - [10, 25, 50, 100, 'All'] +table_display: + device: + ports: + c_admin: off + c_port: on + c_descr: off + c_type: off + c_duplex: off + c_lastchange: off + c_name: on + c_speed: off + c_mac: off + c_mtu: off + c_pvid: on + c_vmember: on + c_power: off + c_ssid: off + c_nodes: off + c_neighbors: on + c_stp: off + c_up: off + n_age: off + n_ip: on + n_netbios: on + n_ssid: on + n_vendor: off + n_archived: off + neigh_id: off # ------------- # NETDISCO CORE diff --git a/Netdisco/share/views/ajax/datatabledefaults.tt b/Netdisco/share/views/ajax/datatabledefaults.tt index 55b3ed82..e4eebac5 100644 --- a/Netdisco/share/views/ajax/datatabledefaults.tt +++ b/Netdisco/share/views/ajax/datatabledefaults.tt @@ -8,4 +8,26 @@ "search": '_INPUT_', "searchPlaceholder": 'Filter records...', "lengthMenu": "Show _MENU_ records." + }, + "rowCallback": function (row, data) { + // update in-cell content based on current sidebar settings + [% FOREACH key IN settings.table_display.device.ports.keys %] + if ($('#dp-data-table').DataTable().column('[% key %]:name').length === 0) { + $(row).find('span.[% key %]').toggle( $("input[id='[% key %]']").prop('checked') ); + } + [% END %] + }, + "stateLoadParams": function (settings, data) { + // enforce config defaults for columns + // TODO: allow state loading + [% FOREACH key IN settings.table_display.device.ports.keys %] + if (data.columns[$('#dp-data-table').DataTable().column('[% key %]:name').index()]) { + data.columns[$('#dp-data-table').DataTable().column('[% key %]:name').index()].visible + = [% (settings.table_display.device.ports.$key == 'on') ? 'true' : 'false' %]; + } + else { + $("input[id='[% key %]']").prop('checked', + [% (settings.table_display.device.ports.$key == 'on') ? 'true' : 'false' %]); + } + [% END %] } diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index d2f81df9..9e0ce64f 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -36,14 +36,6 @@ $(document).ready(function() { "colVis": { "exclude": [ 0 ] }, - "stateLoadParams": function (settings, data) { - [% FOREACH key IN params.keys %] - [% NEXT UNLESS key.match('^c_') AND !key.match('^c_neighbors') AND params.$key == 'on' %] - if (data.columns[$('#dp-data-table').DataTable().column( '[% key %]:name' ).index()]) { - data.columns[$('#dp-data-table').DataTable().column( '[% key %]:name' ).index()].visible = true; - } - [% END %] - }, "columns": [ { "title": '', @@ -155,7 +147,6 @@ $(document).ready(function() { { "title": 'Description', "name": 'c_descr', - "visible": false, "type": 'portsort', "className": 'nd_nowrap', "data": "descr", @@ -165,7 +156,6 @@ $(document).ready(function() { }, { "title": 'Type', "name": 'c_type', - "visible": false, "data": "type", "render": function(data, type, row, meta) { return type === 'display' ? he.encode(data || '') : data; @@ -173,7 +163,6 @@ $(document).ready(function() { }, { "title": 'Duplex', "name": 'c_duplex', - "visible": false, "data": "duplex", "render": function(data, type, row, meta) { if (row.up === 'up' && row.duplex) { @@ -187,7 +176,6 @@ $(document).ready(function() { }, { "title": 'Last Change', "name": 'c_lastchange', - "visible": false, "data": "lastchange_stamp", }, { "title": 'Name', @@ -220,7 +208,6 @@ $(document).ready(function() { }, { "title": 'Speed', "name": 'c_speed', - "visible": false, "data": "speed", "render": function(data, type, row, meta) { return type === 'display' ? he.encode(data || '') : data; @@ -228,7 +215,6 @@ $(document).ready(function() { }, { "title": 'Port MAC', "name": 'c_mac', - "visible": false, "data": "mac", "render": function(data, type, row, meta) { return type === 'display' ? he.encode(data || '') : data; @@ -236,7 +222,6 @@ $(document).ready(function() { }, { "title": 'MTU', "name": 'c_mtu', - "visible": false, /* mtu is an integer, no need to encode */ "data": "mtu" }, { @@ -279,7 +264,6 @@ $(document).ready(function() { }, { "title": 'VLAN Membership', "name": 'c_vmember', - "visible": false, "type": 'natural', "data": null, "render": function ( data, type, row, meta ) { @@ -309,7 +293,6 @@ $(document).ready(function() { }, { "title": 'PoE', "name": 'c_power', - "visible": false, "data": "power_admin", "defaultContent": "", "className": 'nd_nowrap', @@ -382,7 +365,7 @@ $(document).ready(function() { } }, { "title": 'Connected Devices and Nodes', - "name": 'c_nodes', + "name": 'c_neighbors', "data": "null", "defaultContent": "", "render": function ( data, type, row, meta ) { @@ -414,7 +397,7 @@ $(document).ready(function() { } cell_str += '
'; if (row.remote_id || row.remote_type) { - cell_str += ' ('; + cell_str += ' ('; if (row.remote_id) { cell_str += ' id: ' + he.encode(row.remote_id); } @@ -440,7 +423,7 @@ $(document).ready(function() { } cell_str += '
'; if (row.remote_id || row.remote_type) { - cell_str += ' ('; + cell_str += ' ('; if (row.remote_id) { cell_str += ' id: ' + he.encode(row.remote_id); } @@ -454,14 +437,14 @@ $(document).ready(function() { cell_str += '  (possible uplink)'; } } - cell_str += ''; + cell_str += ''; var macfmt = '[% params.mac_format %]'; for (index = 0; index < row.nodes.length; ++index) { if ((row.remote_ip || row.is_uplink) && index === 0 ) { cell_str += '
'; } if (row.nodes[index].active === 0) { - cell_str += ''; + cell_str += ''; if (index > 0 ) { cell_str += '
'; } @@ -483,7 +466,7 @@ $(document).ready(function() { // n_vendor if (row.nodes[index].abbrev) { - cell_str += ' (' + cell_str += ' (' + '' + he.encode(row.nodes[index].abbrev || '') + ')'; @@ -501,21 +484,21 @@ $(document).ready(function() { arr = jQuery.map( arr, function( a ) { return '' + he.encode(a) + ''; }); - cell_str += ' (SSID: ' + arr.join(" ") + ')'; + cell_str += ' (SSID: ' + arr.join(" ") + ')'; } // n_age - cell_str += ' ('; + cell_str += ' ('; var now = moment(); var t_last = moment(row.nodes[index].time_last); cell_str += t_last.from(now) + ')'; // n_ip if (row.nodes[index].ip && row.nodes[index].ip.length > 0) { - cell_str += ''; + cell_str += ''; for (idx = 0; idx < row.nodes[index].ip.length; ++idx) { if (row.nodes[index].ip_active[idx] === 0) { - cell_str += ''; + cell_str += ''; cell_str += '
    '; } else { @@ -539,7 +522,7 @@ $(document).ready(function() { // n_netbios if (row.nodes[index].nbname) { - cell_str += '' + cell_str += '' + '
     \\\\