From f1bb8b96534345daffaa0fe462a28e4621889899 Mon Sep 17 00:00:00 2001 From: Noah Zalev Date: Fri, 30 Jul 2021 13:34:00 -0400 Subject: [PATCH] Added Last Seen sort option --- views/default.handlebars | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/views/default.handlebars b/views/default.handlebars index 644b8373..6da1779f 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -318,6 +318,7 @@ +   @@ -3775,6 +3776,17 @@ if (sort == 0) { nodes.sort(meshSort); } else if (sort == 1) { nodes.sort(powerSort); } else if (sort == 2) { if (showRealNames == true) { nodes.sort(deviceHostSort); } else { nodes.sort(deviceSort); } } + else if (sort == 5) { + // if the last seen column is not turned on, turn it on first (we require this to sort the data) + if (!(deviceViewSettings && deviceViewSettings.devsCols && deviceViewSettings.devsCols.indexOf('lastseen') >= 0)) { + // force initialize the view settings + if (deviceViewSettings == null) { deviceViewSettings = {}; } + if (!Array.isArray(deviceViewSettings.devsCols)) { deviceViewSettings.devsCols = ['user','ip','conn', 'lastseen']; } + else { deviceViewSettings.devsCols.push('lastseen'); } + } + nodes.sort(lastConnectSort); + } + // Compute the width of the device view. var totalDeviceViewWidth = Q('column_l').clientWidth - 60; @@ -3845,7 +3857,7 @@ c = 0; if ((view == 1) || (view == 3) || (view == 5)) { r += '
'; } // Open collapse div } - } else if (sort == 2) { + } else if (sort == 2 || sort == 5) { // Device header if (current == null) { current = '1'; } } @@ -5283,6 +5295,7 @@ function powerSort(a, b) { var ap = a.pwr?a.pwr:0; var bp = b.pwr?b.pwr:0; if (ap > bp) return -1; if (ap < bp) return 1; if (ap == bp) { if (showRealNames == true) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } else { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } } return 0; } function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } + function lastConnectSort(a, b) { return a.lastconnect - b.lastconnect; } function onSearchFocus(x) { searchFocus = x; } function clearDeviceSearch() { Q('KvmSearchInput').value = Q('SearchInput').value = ''; Q('DevFilterSelect').value = 0; onOnlineCheckBox(); mainUpdate(1); } function onMapSearchFocus(x) { mapSearchFocus = x; }