WebAdmin: fix column visibility after reorder

Fixes #1899

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2025-03-02 18:46:23 +01:00
parent c61571ea07
commit 40c14607f6
5 changed files with 61 additions and 28 deletions

View File

@@ -267,6 +267,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "status", data: "status",
name: "status",
render: function(data, type, row) { render: function(data, type, row) {
if (type === 'display') { if (type === 'display') {
switch (data){ switch (data){
@@ -281,6 +282,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "last_login", data: "last_login",
name: "last_login",
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
if (type === 'display') { if (type === 'display') {
@@ -299,6 +301,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "email", data: "email",
name: "email",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -313,6 +316,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "role", data: "role",
name: "role",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -327,6 +331,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "filters.totp_config", data: "filters.totp_config",
name: "two_factor",
visible: false, visible: false,
defaultContent: false, defaultContent: false,
render: function(data, type, row) { render: function(data, type, row) {
@@ -341,6 +346,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "description", data: "description",
name: "description",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -442,10 +448,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
$('#table_body').localize(); $('#table_body').localize();
} }
function handleColVisibilityCheckbox(el, index) { function handleColVisibilityCheckbox(el, selector) {
let index = dt.column(selector).index();
el.off("change"); el.off("change");
el.prop('checked', dt.column(index).visible()); el.prop('checked', dt.column(index).visible());
el.on("change", function(e){ el.on("change", function(e){
let index = dt.column(selector).index();
dt.column(index).visible($(this).is(':checked')); dt.column(index).visible($(this).is(':checked'));
dt.draw('page'); dt.draw('page');
}); });
@@ -458,12 +466,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
dt.rows().deselect(); dt.rows().deselect();
dt.search(e.target.value).draw(); dt.search(e.target.value).draw();
}); });
handleColVisibilityCheckbox($('#checkColStatus'), 1); handleColVisibilityCheckbox($('#checkColStatus'), "status:name");
handleColVisibilityCheckbox($('#checkColLastLogin'), 2); handleColVisibilityCheckbox($('#checkColLastLogin'), "last_login:name");
handleColVisibilityCheckbox($('#checkColEmail'), 3); handleColVisibilityCheckbox($('#checkColEmail'), "email:name");
handleColVisibilityCheckbox($('#checkColRole'), 4); handleColVisibilityCheckbox($('#checkColRole'), "role:name");
handleColVisibilityCheckbox($('#checkCol2FA'), 5); handleColVisibilityCheckbox($('#checkCol2FA'), "two_factor:name");
handleColVisibilityCheckbox($('#checkColDesc'), 6); handleColVisibilityCheckbox($('#checkColDesc'), "description:name");
const exportButton = $(document.querySelector('[data-table-filter="export"]')); const exportButton = $(document.querySelector('[data-table-filter="export"]'));
exportButton.on('click', function(e){ exportButton.on('click', function(e){

View File

@@ -204,6 +204,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "filesystem.provider", data: "filesystem.provider",
name: "storage",
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
if (type === 'display') { if (type === 'display') {
@@ -229,6 +230,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "used_quota_size", data: "used_quota_size",
name: "quota",
visible: false, visible: false,
searchable: false, searchable: false,
orderable: false, orderable: false,
@@ -249,6 +251,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "users", data: "users",
name: "associations",
defaultContent: "", defaultContent: "",
visible: false, visible: false,
searchable: false, searchable: false,
@@ -270,6 +273,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "description", data: "description",
name: "description",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -362,10 +366,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
$('#table_body').localize(); $('#table_body').localize();
} }
function handleColVisibilityCheckbox(el, index) { function handleColVisibilityCheckbox(el, selector) {
let index = dt.column(selector).index();
el.off("change"); el.off("change");
el.prop('checked', dt.column(index).visible()); el.prop('checked', dt.column(index).visible());
el.on("change", function(e){ el.on("change", function(e){
let index = dt.column(selector).index();
dt.column(index).visible($(this).is(':checked')); dt.column(index).visible($(this).is(':checked'));
dt.draw('page'); dt.draw('page');
}); });
@@ -378,10 +384,10 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
dt.rows().deselect(); dt.rows().deselect();
dt.search(e.target.value).draw(); dt.search(e.target.value).draw();
}); });
handleColVisibilityCheckbox($('#checkColStorage'), 1); handleColVisibilityCheckbox($('#checkColStorage'), "storage:name");
handleColVisibilityCheckbox($('#checkColQuota'), 2); handleColVisibilityCheckbox($('#checkColQuota'), "quota:name");
handleColVisibilityCheckbox($('#checkColAssociations'), 3); handleColVisibilityCheckbox($('#checkColAssociations'), "associations:name");
handleColVisibilityCheckbox($('#checkColDesc'), 4); handleColVisibilityCheckbox($('#checkColDesc'), "description:name");
const exportButton = $(document.querySelector('[data-table-filter="export"]')); const exportButton = $(document.querySelector('[data-table-filter="export"]'));
exportButton.on('click', function(e){ exportButton.on('click', function(e){

View File

@@ -190,6 +190,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "users", data: "users",
name: "members",
defaultContent: "", defaultContent: "",
searchable: false, searchable: false,
orderable: false, orderable: false,
@@ -210,6 +211,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "description", data: "description",
name: "description",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -299,10 +301,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
$('#table_body').localize(); $('#table_body').localize();
} }
function handleColVisibilityCheckbox(el, index) { function handleColVisibilityCheckbox(el, selector) {
let index = dt.column(selector).index();
el.off("change"); el.off("change");
el.prop('checked', dt.column(index).visible()); el.prop('checked', dt.column(index).visible());
el.on("change", function(e){ el.on("change", function(e){
let index = dt.column(selector).index();
dt.column(index).visible($(this).is(':checked')); dt.column(index).visible($(this).is(':checked'));
dt.draw('page'); dt.draw('page');
}); });
@@ -315,8 +319,8 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
dt.rows().deselect(); dt.rows().deselect();
dt.search(e.target.value).draw(); dt.search(e.target.value).draw();
}); });
handleColVisibilityCheckbox($('#checkColMembers'), 1); handleColVisibilityCheckbox($('#checkColMembers'), "members:name");
handleColVisibilityCheckbox($('#checkColDesc'), 2); handleColVisibilityCheckbox($('#checkColDesc'), "description:name");
const exportButton = $(document.querySelector('[data-table-filter="export"]')); const exportButton = $(document.querySelector('[data-table-filter="export"]'));
exportButton.on('click', function(e){ exportButton.on('click', function(e){

View File

@@ -191,6 +191,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "users", data: "users",
name: "members",
defaultContent: "", defaultContent: "",
searchable: false, searchable: false,
orderable: false, orderable: false,
@@ -211,6 +212,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "description", data: "description",
name: "description",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -300,10 +302,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
$('#table_body').localize(); $('#table_body').localize();
} }
function handleColVisibilityCheckbox(el, index) { function handleColVisibilityCheckbox(el, selector) {
let index = dt.column(selector).index();
el.off("change"); el.off("change");
el.prop('checked', dt.column(index).visible()); el.prop('checked', dt.column(index).visible());
el.on("change", function(e){ el.on("change", function(e){
let index = dt.column(selector).index();
dt.column(index).visible($(this).is(':checked')); dt.column(index).visible($(this).is(':checked'));
dt.draw('page'); dt.draw('page');
}); });
@@ -316,8 +320,8 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
dt.rows().deselect(); dt.rows().deselect();
dt.search(e.target.value).draw(); dt.search(e.target.value).draw();
}); });
handleColVisibilityCheckbox($('#checkColMembers'), 1); handleColVisibilityCheckbox($('#checkColMembers'), "members:name");
handleColVisibilityCheckbox($('#checkColDesc'), 2); handleColVisibilityCheckbox($('#checkColDesc'), "description:name");
const exportButton = $(document.querySelector('[data-table-filter="export"]')); const exportButton = $(document.querySelector('[data-table-filter="export"]'));
exportButton.on('click', function(e){ exportButton.on('click', function(e){

View File

@@ -319,6 +319,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "status", data: "status",
name: "status",
render: function(data, type, row) { render: function(data, type, row) {
let result = data; let result = data;
if (row.expiration_date){ if (row.expiration_date){
@@ -341,6 +342,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "last_login", data: "last_login",
name: "last_login",
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
if (type === 'display') { if (type === 'display') {
@@ -359,6 +361,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "email", data: "email",
name: "email",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -373,6 +376,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "filesystem.provider", data: "filesystem.provider",
name: "storage",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -399,6 +403,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "role", data: "role",
name: "role",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -413,6 +418,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "filters.totp_config", data: "filters.totp_config",
name: "two_factor",
visible: false, visible: false,
defaultContent: "", defaultContent: "",
render: function(data, type, row) { render: function(data, type, row) {
@@ -430,6 +436,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "quota_files", data: "quota_files",
name: "disk_quota",
visible: false, visible: false,
searchable: false, searchable: false,
orderable: false, orderable: false,
@@ -464,6 +471,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "total_data_transfer", data: "total_data_transfer",
name: "transfer_quota",
visible: false, visible: false,
searchable: false, searchable: false,
orderable: false, orderable: false,
@@ -509,6 +517,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}, },
{ {
data: "groups", data: "groups",
name: "groups",
visible: false, visible: false,
defaultContent: [], defaultContent: [],
render: function(data, type, row) { render: function(data, type, row) {
@@ -626,10 +635,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
$('#table_body').localize(); $('#table_body').localize();
} }
function handleColVisibilityCheckbox(el, index) { function handleColVisibilityCheckbox(el, selector) {
let index = dt.column(selector).index();
el.off("change"); el.off("change");
el.prop('checked', dt.column(index).visible()); el.prop('checked', dt.column(index).visible());
el.on("change", function(e){ el.on("change", function(e){
let index = dt.column(selector).index();
dt.column(index).visible($(this).is(':checked')); dt.column(index).visible($(this).is(':checked'));
dt.draw('page'); dt.draw('page');
}); });
@@ -642,15 +653,15 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
dt.rows().deselect(); dt.rows().deselect();
dt.search(e.target.value).draw(); dt.search(e.target.value).draw();
}); });
handleColVisibilityCheckbox($('#checkColStatus'), 1); handleColVisibilityCheckbox($('#checkColStatus'), "status:name");
handleColVisibilityCheckbox($('#checkColLastLogin'), 2); handleColVisibilityCheckbox($('#checkColLastLogin'), "last_login:name");
handleColVisibilityCheckbox($('#checkColEmail'), 3); handleColVisibilityCheckbox($('#checkColEmail'), "email:name");
handleColVisibilityCheckbox($('#checkColStorage'), 4); handleColVisibilityCheckbox($('#checkColStorage'), "storage:name");
handleColVisibilityCheckbox($('#checkColRole'), 5); handleColVisibilityCheckbox($('#checkColRole'), "role:name");
handleColVisibilityCheckbox($('#checkCol2FA'), 6); handleColVisibilityCheckbox($('#checkCol2FA'), "two_factor:name");
handleColVisibilityCheckbox($('#checkColDiskQuota'), 7); handleColVisibilityCheckbox($('#checkColDiskQuota'), "disk_quota:name");
handleColVisibilityCheckbox($('#checkColTransferQuota'), 8); handleColVisibilityCheckbox($('#checkColTransferQuota'), "transfer_quota:name");
handleColVisibilityCheckbox($('#checkColGroups'), 9); handleColVisibilityCheckbox($('#checkColGroups'), "groups:name");
const exportButton = $(document.querySelector('[data-table-filter="export"]')); const exportButton = $(document.querySelector('[data-table-filter="export"]'));
exportButton.on('click', function(e){ exportButton.on('click', function(e){