From 0a89d07937b5f28dcdee23dec8d7eaa3283e73b9 Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Fri, 14 Jun 2024 09:56:02 +0100 Subject: [PATCH] add userSessionsSort for session sorting (#6177) Signed-off-by: si458 --- meshcentral-config-schema.json | 5 +++++ sample-config-advanced.json | 1 + views/default-mobile.handlebars | 10 ++++++++++ views/default.handlebars | 12 +++++++++++- webserver.js | 3 ++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index ddc68d6c..89b36177 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -1701,6 +1701,11 @@ "default": false, "description": "When enabled, this will show the notes panel in the device view" }, + "userSessionsSort": { + "type": "string", + "default": "SessionId", + "description": "Arrange the Connect sessions offered when multiple Terminal Sessions are present by 'SessionId', 'StationName' or 'Username' with 'SessionId' as the default sorting criteria." + }, "agentInviteCodes": { "type": "boolean", "default": false, diff --git a/sample-config-advanced.json b/sample-config-advanced.json index a3c83b3d..19ea1415 100644 --- a/sample-config-advanced.json +++ b/sample-config-advanced.json @@ -193,6 +193,7 @@ "minify": true, "_hidePowerTimeline": true, "_showNotesPanel": true, + "_userSessionsSort": "Username", "_newAccounts": true, "_newAccountsUserGroups": [ "ugrp//xxxxxxxxxxxxxxxxx" ], "_userNameIsEmail": true, diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index 76ead4f3..20817030 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -1654,6 +1654,16 @@ else if (userSessions.length == 1) { connectDesktop(null, 1, userSessions[0].SessionId, message.tag); } // One active session, connect to it else { var x = ''; + var sortBy = "{{{userSessionsSort}}}"; + if (sortBy != '') { + userSessions.sort(function(a, b) { + if (!a[sortBy]) return -1; // a comes before b + if (!b[sortBy]) return 1; // b comes before a + if (a[sortBy] < b[sortBy]) return -1; + if (a[sortBy] > b[sortBy]) return 1; + return 0; + }); + } for (var i in userSessions) { x += '
' + userSessions[i].State + ', ' + userSessions[i].StationName; if (userSessions[i].Username) { if (userSessions[i].Domain) { x += ' - ' + userSessions[i].Domain + '/' + userSessions[i].Username; } else { x += ' - ' + userSessions[i].Username; } } diff --git a/views/default.handlebars b/views/default.handlebars index f529cc42..c42c760d 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1,4 +1,4 @@ - + @@ -2689,6 +2689,16 @@ else if (userSessions.length === 1) { connectDesktop(null, 1, userSessions[0].SessionId, message.tag); } // One active session, connect to it else { var x = ''; + var sortBy = "{{{userSessionsSort}}}"; + if (sortBy != '') { + userSessions.sort(function(a, b) { + if (!a[sortBy]) return -1; // a comes before b + if (!b[sortBy]) return 1; // b comes before a + if (a[sortBy] < b[sortBy]) return -1; + if (a[sortBy] > b[sortBy]) return 1; + return 0; + }); + } for (var i in userSessions) { x += '
' + userSessions[i].State + (userSessions[i].StationName ? (', ' + userSessions[i].StationName) : ''); if (userSessions[i].Username) { if (userSessions[i].Domain) { x += ' - ' + userSessions[i].Domain + '/' + userSessions[i].Username; } else { x += ' - ' + userSessions[i].Username; } } diff --git a/webserver.js b/webserver.js index 309c6bae..61e13c1f 100644 --- a/webserver.js +++ b/webserver.js @@ -3152,7 +3152,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF webRelayPort: ((args.relaydns != null) ? ((typeof args.aliasport == 'number') ? args.aliasport : args.port) : ((parent.webrelayserver != null) ? ((typeof args.relayaliasport == 'number') ? args.relayaliasport : parent.webrelayserver.port) : 0)), webRelayDns: ((args.relaydns != null) ? args.relaydns[0] : ''), hidePowerTimeline: (domain.hidepowertimeline ? 'true' : 'false'), - showNotesPanel: (domain.shownotespanel ? 'true' : 'false') + showNotesPanel: (domain.shownotespanel ? 'true' : 'false'), + userSessionsSort: (domain.usersessionssort ? domain.usersessionssort : 'SessionId') }, dbGetFunc.req, domain), user); } xdbGetFunc.req = req;