add userSessionsSort for session sorting (#6177)

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Jun 14, 2024 at 09:56 UTC 0a89d07937b5f28dcdee23dec8d7eaa3283e73b9
5 files changed +29 -2
meshcentral-config-schema.json
+5
@@ -1701,6 +1701,11 @@
1701 "default": false,
1702 "description": "When enabled, this will show the notes panel in the device view"
1703 },
1704 + "userSessionsSort": {
1705 + "type": "string",
1706 + "default": "SessionId",
1707 + "description": "Arrange the Connect sessions offered when multiple Terminal Sessions are present by 'SessionId', 'StationName' or 'Username' with 'SessionId' as the default sorting criteria."
1708 + },
1709 "agentInviteCodes": {
1710 "type": "boolean",
1711 "default": false,
sample-config-advanced.json
+1
@@ -193,6 +193,7 @@
193 "minify": true,
194 "_hidePowerTimeline": true,
195 "_showNotesPanel": true,
196 + "_userSessionsSort": "Username",
197 "_newAccounts": true,
198 "_newAccountsUserGroups": [ "ugrp//xxxxxxxxxxxxxxxxx" ],
199 "_userNameIsEmail": true,
views/default-mobile.handlebars
+10
@@ -1654,6 +1654,16 @@
1654 else if (userSessions.length == 1) { connectDesktop(null, 1, userSessions[0].SessionId, message.tag); } // One active session, connect to it
1655 else {
1656 var x = '';
1657 + var sortBy = "{{{userSessionsSort}}}";
1658 + if (sortBy != '') {
1659 + userSessions.sort(function(a, b) {
1660 + if (!a[sortBy]) return -1; // a comes before b
1661 + if (!b[sortBy]) return 1; // b comes before a
1662 + if (a[sortBy] < b[sortBy]) return -1;
1663 + if (a[sortBy] > b[sortBy]) return 1;
1664 + return 0;
1665 + });
1666 + }
1667 for (var i in userSessions) {
1668 x += '<div style="text-align:left;cursor:pointer;background-color:gray;margin:5px;padding:5px;border-radius:5px" onclick=connectDesktop(event,1,' + userSessions[i].SessionId + ',' + message.tag + ')>' + userSessions[i].State + ', ' + userSessions[i].StationName;
1669 if (userSessions[i].Username) { if (userSessions[i].Domain) { x += ' - ' + userSessions[i].Domain + '/' + userSessions[i].Username; } else { x += ' - ' + userSessions[i].Username; } }
views/default.handlebars
+11 -1
@@ -1,4 +1,4 @@
1 -<!DOCTYPE html>
1 +<!DOCTYPE html>
2 <html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
@@ -2689,6 +2689,16 @@
2689 else if (userSessions.length === 1) { connectDesktop(null, 1, userSessions[0].SessionId, message.tag); } // One active session, connect to it
2690 else {
2691 var x = '';
2692 + var sortBy = "{{{userSessionsSort}}}";
2693 + if (sortBy != '') {
2694 + userSessions.sort(function(a, b) {
2695 + if (!a[sortBy]) return -1; // a comes before b
2696 + if (!b[sortBy]) return 1; // b comes before a
2697 + if (a[sortBy] < b[sortBy]) return -1;
2698 + if (a[sortBy] > b[sortBy]) return 1;
2699 + return 0;
2700 + });
2701 + }
2702 for (var i in userSessions) {
2703 x += '<div style="text-align:left;cursor:pointer;background-color:gray;margin:5px;padding:5px;border-radius:5px" onclick=connectDesktop(event,1,' + userSessions[i].SessionId + ',' + message.tag + ')>' + userSessions[i].State + (userSessions[i].StationName ? (', ' + userSessions[i].StationName) : '');
2704 if (userSessions[i].Username) { if (userSessions[i].Domain) { x += ' - ' + userSessions[i].Domain + '/' + userSessions[i].Username; } else { x += ' - ' + userSessions[i].Username; } }
webserver.js
+2 -1
@@ -3152,7 +3152,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
3152 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)),
3153 webRelayDns: ((args.relaydns != null) ? args.relaydns[0] : ''),
3154 hidePowerTimeline: (domain.hidepowertimeline ? 'true' : 'false'),
3155 - showNotesPanel: (domain.shownotespanel ? 'true' : 'false')
3155 + showNotesPanel: (domain.shownotespanel ? 'true' : 'false'),
3156 + userSessionsSort: (domain.usersessionssort ? domain.usersessionssort : 'SessionId')
3157 }, dbGetFunc.req, domain), user);
3158 }
3159 xdbGetFunc.req = req;