mirror of
				https://github.com/Ylianst/MeshCentral.git
				synced 2025-10-29 23:35:02 -04:00 
			
		
		
		
	First working device paging support on desktop site.
This commit is contained in:
		
							parent
							
								
									26f134c95d
								
							
						
					
					
						commit
						25020ffd18
					
				
							
								
								
									
										23
									
								
								meshuser.js
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								meshuser.js
									
									
									
									
									
								
							| @ -109,7 +109,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | ||||
|     obj.deviceSkip = 0; // How many devices to skip
 | ||||
|     obj.deviceLimit = 0; // How many devices to view
 | ||||
|     obj.visibleDevices = null; // An object of visible nodeid's if the user is in paging mode
 | ||||
|     if (domain.maxdeviceview != null) { obj.deviceLimit = domain.maxdeviceview; obj.visibleDevices = {}; } | ||||
|     if (domain.maxdeviceview != null) { obj.deviceLimit = domain.maxdeviceview; } | ||||
| 
 | ||||
|     // Check if we are a cross-domain administrator
 | ||||
|     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 | ||||
|             case 'nodes': | ||||
|                 { | ||||
|                     // If in paging mode, look to set the skip and limit values
 | ||||
|                     if (obj.visibleDevices != null) { | ||||
|                     if (domain.maxdeviceview != null) { | ||||
|                         if ((typeof command.skip == 'number') && (command.skip >= 0)) { obj.deviceSkip = command.skip; } | ||||
|                         if ((typeof command.limit == 'number') && (command.limit > 0)) { obj.deviceLimit = command.limit; } | ||||
|                         if ((domain.maxdeviceview != null) && (obj.deviceLimit > domain.maxdeviceview)) { obj.deviceLimit = domain.maxdeviceview; } | ||||
|                         if (obj.deviceLimit > domain.maxdeviceview) { obj.deviceLimit = domain.maxdeviceview; } | ||||
|                     } | ||||
| 
 | ||||
|                     var links = [], extraids = null, err = null; | ||||
| @ -731,13 +731,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | ||||
|                         parent.common.unEscapeAllLinksFieldName(docs); | ||||
| 
 | ||||
|                         var r = {}, nodeCount = docs.length; | ||||
|                         if (obj.visibleDevices != null) { obj.visibleDevices = {}; } | ||||
|                         if (domain.maxdeviceview != null) { obj.visibleDevices = {}; } | ||||
|                         for (i in docs) { | ||||
|                             // Check device links, if a link points to an unknown user, remove it.
 | ||||
|                             parent.cleanDevice(docs[i]); // TODO: This will make the total device count incorrect and will affect device paging.
 | ||||
| 
 | ||||
|                             // If we are paging, add the device to the page here
 | ||||
|                             if (obj.visibleDevices != null) { obj.visibleDevices[docs[i]._id] = 1; } | ||||
|                             if (domain.maxdeviceview != null) { obj.visibleDevices[docs[i]._id] = 1; } | ||||
| 
 | ||||
|                             // Remove any connectivity and power state information, that should not be in the database anyway.
 | ||||
|                             // 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 | ||||
|                             r[meshid].push(docs[i]); | ||||
|                         } | ||||
|                         const response = { action: 'nodes', responseid: command.responseid, nodes: r, tag: command.tag }; | ||||
|                         if (obj.visibleDevices != null) { | ||||
|                         if (domain.maxdeviceview != null) { | ||||
|                             // If in paging mode, report back the skip and limit values
 | ||||
|                             response.skip = obj.deviceSkip; | ||||
|                             response.limit = obj.deviceLimit; | ||||
| 
 | ||||
|                             // Add total device count
 | ||||
|                             // Only set response.totalcount if we need to be in paging mode
 | ||||
|                             if (nodeCount < response.limit) { | ||||
|                                 response.totalcount = obj.deviceSkip + nodeCount; | ||||
|                                 if (obj.deviceSkip > 0) { response.totalcount = obj.deviceSkip + nodeCount; } else { obj.visibleDevices = null; } | ||||
|                                 try { ws.send(JSON.stringify(response)); } catch (ex) { } | ||||
|                             } else { | ||||
|                                 // Ask the database for the total device count
 | ||||
|                                 if (db.CountAllTypeNoTypeFieldMeshFiltered) { | ||||
|                                     db.CountAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', command.id, function (err, count) { | ||||
|                                         if ((err == null) && (typeof response.totalcount == 'number')) { response.totalcount = count; } | ||||
|                                         if ((err != null) || (typeof count != 'number') || ((obj.deviceSkip == 0) && (count < obj.deviceLimit))) { | ||||
|                                             obj.visibleDevices = null; | ||||
|                                         } else { | ||||
|                                             response.totalcount = count; | ||||
|                                         } | ||||
|                                         try { ws.send(JSON.stringify(response)); } catch (ex) { } | ||||
|                                     }); | ||||
|                                 } else { | ||||
|                                     // The database does not support device counting
 | ||||
|                                     obj.visibleDevices = null; // We are not in paging mode
 | ||||
|                                     try { ws.send(JSON.stringify(response)); } catch (ex) { } | ||||
|                                 } | ||||
|                             } | ||||
|                         } else { | ||||
|                             obj.visibleDevices = null; // We are not in paging mode
 | ||||
|                             try { ws.send(JSON.stringify(response)); } catch (ex) { } | ||||
|                         } | ||||
|                     }); | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.6 KiB | 
| @ -2943,6 +2943,38 @@ a { | ||||
|     width: 28px; | ||||
| } | ||||
| 
 | ||||
| .viewSelector8 { | ||||
|     margin-left: 2px; | ||||
|     margin-top: 2px; | ||||
|     background: url(../images/views.png) -420px 0px; | ||||
|     height: 28px; | ||||
|     width: 28px; | ||||
| } | ||||
| 
 | ||||
| .viewSelector9 { | ||||
|     margin-left: 2px; | ||||
|     margin-top: 2px; | ||||
|     background: url(../images/views.png) -448px 0px; | ||||
|     height: 28px; | ||||
|     width: 28px; | ||||
| } | ||||
| 
 | ||||
| .viewSelector10 { | ||||
|     margin-left: 2px; | ||||
|     margin-top: 2px; | ||||
|     background: url(../images/views.png) -476px 0px; | ||||
|     height: 28px; | ||||
|     width: 28px; | ||||
| } | ||||
| 
 | ||||
| .viewSelector11 { | ||||
|     margin-left: 2px; | ||||
|     margin-top: 2px; | ||||
|     background: url(../images/views.png) -504px 0px; | ||||
|     height: 28px; | ||||
|     width: 28px; | ||||
| } | ||||
| 
 | ||||
|     .fulldesk .viewSelector5 { | ||||
|         background: url(../images/views.png) -252px 0px; | ||||
|     } | ||||
|  | ||||
| @ -294,6 +294,11 @@ | ||||
|             <div id=p1 style="display:none"> | ||||
|                 <div id="p1title"> | ||||
|                     <div style="display:none" id="devListToolbarViewIcons"> | ||||
|                         <div id=devViewPageState style="float:left;line-height:32px;height:32px;font-size:16px;display:none"></div> | ||||
|                         <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> | ||||
|                         <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> | ||||
|                         <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> | ||||
|                         <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> | ||||
|                         <div tabindex=0 id=devViewButton1 class=viewSelector onclick=onDeviceViewChange(1) onkeypress="if (event.key == 'Enter') { onDeviceViewChange(1); }" title="Columns"><div class="viewSelector2"></div></div> | ||||
|                         <div tabindex=0 id=devViewButton2 class=viewSelector onclick=onDeviceViewChange(2) onkeypress="if (event.key == 'Enter') { onDeviceViewChange(2); }" title="List"><div class="viewSelector1"></div></div> | ||||
|                         <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 @@ | ||||
|         var deskKeyboardStrings = []; | ||||
|         var deskLastClipboardSent = null; | ||||
|         var requestedLastConnects = false; | ||||
|         var devicePagingState = null; | ||||
| 
 | ||||
|         // Console Message Display Timers | ||||
|         var p11DeskConsoleMsgTimer = null; | ||||
| @ -2475,6 +2481,10 @@ | ||||
|                     // Change the reference to the current node | ||||
|                     if (currentNode != null) { currentNode = getNodeFromId(currentNode._id); if (currentNode != null) { gotoDevice(currentNode._id, xxcurrentView, true); } else { go(1); } } | ||||
| 
 | ||||
|                     // Update device paging | ||||
|                     devicePagingState = (message.totalcount == null) ? null : { total: message.totalcount, skip: message.skip, limit: message.limit }; | ||||
|                     updateDevicePageState(); | ||||
| 
 | ||||
|                     mainUpdate(1 | 2 | 4 | 64); | ||||
|                     break; | ||||
|                 } | ||||
| @ -3839,6 +3849,37 @@ | ||||
|             onDeviceSearchChanged(e); | ||||
|         } | ||||
| 
 | ||||
|         function updateDevicePageState() { | ||||
|             if ((devicePagingState == null) || (devicePagingState.total <= devicePagingState.limit)) { | ||||
|                 QV('devViewPageState', false); | ||||
|                 QV('devViewPageButton1', false); | ||||
|                 QV('devViewPageButton2', false); | ||||
|                 QV('devViewPageButton3', false); | ||||
|                 QV('devViewPageButton4', false); | ||||
|             } else { | ||||
|                 var currentPage = Math.floor((devicePagingState.skip + devicePagingState.limit) / devicePagingState.limit); | ||||
|                 var maxPage = Math.ceil(devicePagingState.total / devicePagingState.limit); | ||||
|                 QV('devViewPageState', true); | ||||
|                 QV('devViewPageButton1', true); | ||||
|                 QV('devViewPageButton2', true); | ||||
|                 QV('devViewPageButton3', true); | ||||
|                 QV('devViewPageButton4', true); | ||||
|                 QH('devViewPageState', currentPage + '/' + maxPage); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         function onDeviceViewPageChange(i) { | ||||
|             if (devicePagingState == null) return; | ||||
|             var currentPage = (Math.floor((devicePagingState.skip + devicePagingState.limit) / devicePagingState.limit)); | ||||
|             var maxPage = Math.ceil(devicePagingState.total / devicePagingState.limit); | ||||
|             switch (i) { | ||||
|                 case 1: { if (currentPage > 1) meshserver.send({ action: 'nodes', skip: 0 }); break; } // Goto first page | ||||
|                 case 2: { if (currentPage > 1) meshserver.send({ action: 'nodes', skip: (currentPage - 2) * devicePagingState.limit }); break; } // Goto previous page | ||||
|                 case 3: { if (currentPage < maxPage) meshserver.send({ action: 'nodes', skip: currentPage * devicePagingState.limit }); break; } // Goto next page | ||||
|                 case 4: { if (currentPage < maxPage) meshserver.send({ action: 'nodes', skip: (maxPage - 1) * devicePagingState.limit }); break; } // Goto last page | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         function onDeviceViewChange(i) { | ||||
|             if (i != null) { Q('viewselect').value = i; } | ||||
|             for (var j = 1; j < 6; j++) { Q('devViewButton' + j).classList.remove('viewSelectorSel'); } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user