First working device paging support on desktop site.
Ylian Saint-Hilaire committed
Aug 31, 2022 at 17:11 UTC
25020ffd18820f9a6c3f55c0a0afd58af55dab8e
4 files changed
+88
-8
meshuser.js
+15
-8
@@ -109,7 +109,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
109
obj.deviceSkip = 0; // How many devices to skip
110
obj.deviceLimit = 0; // How many devices to view
111
obj.visibleDevices = null; // An object of visible nodeid's if the user is in paging mode
112
- if (domain.maxdeviceview != null) { obj.deviceLimit = domain.maxdeviceview; obj.visibleDevices = {}; }
112
+ if (domain.maxdeviceview != null) { obj.deviceLimit = domain.maxdeviceview; }
113
114
// Check if we are a cross-domain administrator
115
if (parent.parent.config.settings.managecrossdomain && (parent.parent.config.settings.managecrossdomain.indexOf(user._id) >= 0)) { obj.crossDomain = true; }
@@ -678,10 +678,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
678
case 'nodes':
679
{
680
// If in paging mode, look to set the skip and limit values
681
- if (obj.visibleDevices != null) {
681
+ if (domain.maxdeviceview != null) {
682
if ((typeof command.skip == 'number') && (command.skip >= 0)) { obj.deviceSkip = command.skip; }
683
if ((typeof command.limit == 'number') && (command.limit > 0)) { obj.deviceLimit = command.limit; }
684
- if ((domain.maxdeviceview != null) && (obj.deviceLimit > domain.maxdeviceview)) { obj.deviceLimit = domain.maxdeviceview; }
684
+ if (obj.deviceLimit > domain.maxdeviceview) { obj.deviceLimit = domain.maxdeviceview; }
685
}
686
687
var links = [], extraids = null, err = null;
@@ -731,13 +731,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
731
parent.common.unEscapeAllLinksFieldName(docs);
732
733
var r = {}, nodeCount = docs.length;
734
- if (obj.visibleDevices != null) { obj.visibleDevices = {}; }
734
+ if (domain.maxdeviceview != null) { obj.visibleDevices = {}; }
735
for (i in docs) {
736
// Check device links, if a link points to an unknown user, remove it.
737
parent.cleanDevice(docs[i]); // TODO: This will make the total device count incorrect and will affect device paging.
738
739
// If we are paging, add the device to the page here
740
- if (obj.visibleDevices != null) { obj.visibleDevices[docs[i]._id] = 1; }
740
+ if (domain.maxdeviceview != null) { obj.visibleDevices[docs[i]._id] = 1; }
741
742
// Remove any connectivity and power state information, that should not be in the database anyway.
743
// TODO: Find why these are sometimes saved in the db.
@@ -810,28 +810,35 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
810
r[meshid].push(docs[i]);
811
}
812
const response = { action: 'nodes', responseid: command.responseid, nodes: r, tag: command.tag };
813
- if (obj.visibleDevices != null) {
813
+ if (domain.maxdeviceview != null) {
814
// If in paging mode, report back the skip and limit values
815
response.skip = obj.deviceSkip;
816
response.limit = obj.deviceLimit;
817
818
// Add total device count
819
+ // Only set response.totalcount if we need to be in paging mode
820
if (nodeCount < response.limit) {
820
- response.totalcount = obj.deviceSkip + nodeCount;
821
+ if (obj.deviceSkip > 0) { response.totalcount = obj.deviceSkip + nodeCount; } else { obj.visibleDevices = null; }
822
try { ws.send(JSON.stringify(response)); } catch (ex) { }
823
} else {
824
// Ask the database for the total device count
825
if (db.CountAllTypeNoTypeFieldMeshFiltered) {
826
db.CountAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', command.id, function (err, count) {
826
- if ((err == null) && (typeof response.totalcount == 'number')) { response.totalcount = count; }
827
+ if ((err != null) || (typeof count != 'number') || ((obj.deviceSkip == 0) && (count < obj.deviceLimit))) {
828
+ obj.visibleDevices = null;
829
+ } else {
830
+ response.totalcount = count;
831
+ }
832
try { ws.send(JSON.stringify(response)); } catch (ex) { }
833
});
834
} else {
835
// The database does not support device counting
836
+ obj.visibleDevices = null; // We are not in paging mode
837
try { ws.send(JSON.stringify(response)); } catch (ex) { }
838
}
839
}
840
} else {
841
+ obj.visibleDevices = null; // We are not in paging mode
842
try { ws.send(JSON.stringify(response)); } catch (ex) { }
843
}
844
});
public/images/views.png
Binary files a/public/images/views.png and b/public/images/views.png differ
public/styles/style.css
+32
@@ -2943,6 +2943,38 @@ a {
2943
width: 28px;
2944
}
2945
2946
+.viewSelector8 {
2947
+ margin-left: 2px;
2948
+ margin-top: 2px;
2949
+ background: url(../images/views.png) -420px 0px;
2950
+ height: 28px;
2951
+ width: 28px;
2952
+}
2953
+
2954
+.viewSelector9 {
2955
+ margin-left: 2px;
2956
+ margin-top: 2px;
2957
+ background: url(../images/views.png) -448px 0px;
2958
+ height: 28px;
2959
+ width: 28px;
2960
+}
2961
+
2962
+.viewSelector10 {
2963
+ margin-left: 2px;
2964
+ margin-top: 2px;
2965
+ background: url(../images/views.png) -476px 0px;
2966
+ height: 28px;
2967
+ width: 28px;
2968
+}
2969
+
2970
+.viewSelector11 {
2971
+ margin-left: 2px;
2972
+ margin-top: 2px;
2973
+ background: url(../images/views.png) -504px 0px;
2974
+ height: 28px;
2975
+ width: 28px;
2976
+}
2977
+
2978
.fulldesk .viewSelector5 {
2979
background: url(../images/views.png) -252px 0px;
2980
}
views/default.handlebars
+41
@@ -294,6 +294,11 @@
294
<div id=p1 style="display:none">
295
<div id="p1title">
296
<div style="display:none" id="devListToolbarViewIcons">
297
+ <div id=devViewPageState style="float:left;line-height:32px;height:32px;font-size:16px;display:none"></div>
298
+ <div tabindex=0 id=devViewPageButton1 class=viewSelector onclick=onDeviceViewPageChange(1) onkeypress="if (event.key == 'Enter') { onDeviceViewPageChange(1); }" title="Go to first page" style="display:none"><div class="viewSelector9"></div></div>
299
+ <div tabindex=0 id=devViewPageButton2 class=viewSelector onclick=onDeviceViewPageChange(2) onkeypress="if (event.key == 'Enter') { onDeviceViewPageChange(2); }" title="Go to previous page" style="display:none"><div class="viewSelector10"></div></div>
300
+ <div tabindex=0 id=devViewPageButton3 class=viewSelector onclick=onDeviceViewPageChange(3) onkeypress="if (event.key == 'Enter') { onDeviceViewPageChange(3); }" title="Go to next page" style="display:none"><div class="viewSelector11"></div></div>
301
+ <div tabindex=0 id=devViewPageButton4 class=viewSelector onclick=onDeviceViewPageChange(4) onkeypress="if (event.key == 'Enter') { onDeviceViewPageChange(4); }" title="Go to last page" style="display:none;margin-right:12px"><div class="viewSelector8"></div></div>
302
<div tabindex=0 id=devViewButton1 class=viewSelector onclick=onDeviceViewChange(1) onkeypress="if (event.key == 'Enter') { onDeviceViewChange(1); }" title="Columns"><div class="viewSelector2"></div></div>
303
<div tabindex=0 id=devViewButton2 class=viewSelector onclick=onDeviceViewChange(2) onkeypress="if (event.key == 'Enter') { onDeviceViewChange(2); }" title="List"><div class="viewSelector1"></div></div>
304
<div tabindex=0 id=devViewButton3 class=viewSelector onclick=onDeviceViewChange(3) onkeypress="if (event.key == 'Enter') { onDeviceViewChange(3); }" title="Desktops"><div class="viewSelector3"></div></div>
@@ -1509,6 +1514,7 @@
1514
var deskKeyboardStrings = [];
1515
var deskLastClipboardSent = null;
1516
var requestedLastConnects = false;
1517
+ var devicePagingState = null;
1518
1519
// Console Message Display Timers
1520
var p11DeskConsoleMsgTimer = null;
@@ -2475,6 +2481,10 @@
2481
// Change the reference to the current node
2482
if (currentNode != null) { currentNode = getNodeFromId(currentNode._id); if (currentNode != null) { gotoDevice(currentNode._id, xxcurrentView, true); } else { go(1); } }
2483
2484
+ // Update device paging
2485
+ devicePagingState = (message.totalcount == null) ? null : { total: message.totalcount, skip: message.skip, limit: message.limit };
2486
+ updateDevicePageState();
2487
+
2488
mainUpdate(1 | 2 | 4 | 64);
2489
break;
2490
}
@@ -3839,6 +3849,37 @@
3849
onDeviceSearchChanged(e);
3850
}
3851
3852
+ function updateDevicePageState() {
3853
+ if ((devicePagingState == null) || (devicePagingState.total <= devicePagingState.limit)) {
3854
+ QV('devViewPageState', false);
3855
+ QV('devViewPageButton1', false);
3856
+ QV('devViewPageButton2', false);
3857
+ QV('devViewPageButton3', false);
3858
+ QV('devViewPageButton4', false);
3859
+ } else {
3860
+ var currentPage = Math.floor((devicePagingState.skip + devicePagingState.limit) / devicePagingState.limit);
3861
+ var maxPage = Math.ceil(devicePagingState.total / devicePagingState.limit);
3862
+ QV('devViewPageState', true);
3863
+ QV('devViewPageButton1', true);
3864
+ QV('devViewPageButton2', true);
3865
+ QV('devViewPageButton3', true);
3866
+ QV('devViewPageButton4', true);
3867
+ QH('devViewPageState', currentPage + '/' + maxPage);
3868
+ }
3869
+ }
3870
+
3871
+ function onDeviceViewPageChange(i) {
3872
+ if (devicePagingState == null) return;
3873
+ var currentPage = (Math.floor((devicePagingState.skip + devicePagingState.limit) / devicePagingState.limit));
3874
+ var maxPage = Math.ceil(devicePagingState.total / devicePagingState.limit);
3875
+ switch (i) {
3876
+ case 1: { if (currentPage > 1) meshserver.send({ action: 'nodes', skip: 0 }); break; } // Goto first page
3877
+ case 2: { if (currentPage > 1) meshserver.send({ action: 'nodes', skip: (currentPage - 2) * devicePagingState.limit }); break; } // Goto previous page
3878
+ case 3: { if (currentPage < maxPage) meshserver.send({ action: 'nodes', skip: currentPage * devicePagingState.limit }); break; } // Goto next page
3879
+ case 4: { if (currentPage < maxPage) meshserver.send({ action: 'nodes', skip: (maxPage - 1) * devicePagingState.limit }); break; } // Goto last page
3880
+ }
3881
+ }
3882
+
3883
function onDeviceViewChange(i) {
3884
if (i != null) { Q('viewselect').value = i; }
3885
for (var j = 1; j < 6; j++) { Q('devViewButton' + j).classList.remove('viewSelectorSel'); }