Added Last Seen sort option
Noah Zalev committed
Jul 30, 2021 at 13:34 UTC
f1bb8b96534345daffaa0fe462a28e4621889899
1 file changed
+14
-1
views/default.handlebars
+14
-1
@@ -318,6 +318,7 @@
318
<option>Device</option>
319
<option>Tags</option>
320
<option>Group-Tags</option>
321
+ <option>Last Seen</option>
322
</select>
323
324
</div>
@@ -3775,6 +3776,17 @@
3776
if (sort == 0) { nodes.sort(meshSort); }
3777
else if (sort == 1) { nodes.sort(powerSort); }
3778
else if (sort == 2) { if (showRealNames == true) { nodes.sort(deviceHostSort); } else { nodes.sort(deviceSort); } }
3779
+ else if (sort == 5) {
3780
+ // if the last seen column is not turned on, turn it on first (we require this to sort the data)
3781
+ if (!(deviceViewSettings && deviceViewSettings.devsCols && deviceViewSettings.devsCols.indexOf('lastseen') >= 0)) {
3782
+ // force initialize the view settings
3783
+ if (deviceViewSettings == null) { deviceViewSettings = {}; }
3784
+ if (!Array.isArray(deviceViewSettings.devsCols)) { deviceViewSettings.devsCols = ['user','ip','conn', 'lastseen']; }
3785
+ else { deviceViewSettings.devsCols.push('lastseen'); }
3786
+ }
3787
+ nodes.sort(lastConnectSort);
3788
+ }
3789
+
3790
3791
// Compute the width of the device view.
3792
var totalDeviceViewWidth = Q('column_l').clientWidth - 60;
@@ -3845,7 +3857,7 @@
3857
c = 0;
3858
if ((view == 1) || (view == 3) || (view == 5)) { r += '<div id=DevxCol' + deviceHeaderId + ((collapsed === true)?' style=display:none':'') + '>'; } // Open collapse div
3859
}
3848
- } else if (sort == 2) {
3860
+ } else if (sort == 2 || sort == 5) {
3861
// Device header
3862
if (current == null) { current = '1'; }
3863
}
@@ -5283,6 +5295,7 @@
5295
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; }
5296
function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; }
5297
function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; }
5298
+ function lastConnectSort(a, b) { return a.lastconnect - b.lastconnect; }
5299
function onSearchFocus(x) { searchFocus = x; }
5300
function clearDeviceSearch() { Q('KvmSearchInput').value = Q('SearchInput').value = ''; Q('DevFilterSelect').value = 0; onOnlineCheckBox(); mainUpdate(1); }
5301
function onMapSearchFocus(x) { mapSearchFocus = x; }