From da268d57e7ea5faa2950a643568a28cfc5283859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vest=C3=B8l?= Date: Fri, 10 Aug 2018 15:51:41 +0200 Subject: [PATCH] Serverside rendering of /slaves for more plugin functionality --- static/nodes.html | 46 +++++++++++++++++++++++++++++++++++++++++++-- static/sidebar.html | 10 ++++++---- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/static/nodes.html b/static/nodes.html index b519c797..031a901c 100644 --- a/static/nodes.html +++ b/static/nodes.html @@ -1,7 +1,7 @@ <%- include("head.html") %> - + @@ -10,7 +10,49 @@

Slaves

- + <% + function findInArray(key, value, array){ + let indexes = []; + for(let i in array){ + if(array[i][key] && array[i][key].includes(value)) indexes.push(i); + } + return indexes; + } + html = "

Current connections:

"; + for(let id in slaves){ + let slave = slaves[id]; + html += ` +
+ +

${slave.instanceName}

+
+

ID: ${id}

+

Last seen: ${moment(Number(slave.time)).format("DD.MM.YY, hh:mm")}

+

Online players: ${slave.playerCount}

+

IP: ${slave.publicIP}:${slave.serverPort}

+

Host: ${slave.mac}

+ ${findInArray("modName", "remoteMap", slave.mods).length ? "Remote map" : ""} + ` + for(let o in masterPlugins){ + let plug = masterPlugins[o]; + if(plug.main + && plug.main.ui + && typeof plug.main.ui.slaveListing == "object" + && Array.isArray(plug.main.ui.slaveListing)){ + let slaveListingEntries = plug.main.ui.slaveListing; + for(let i in slaveListingEntries){ + let button = slaveListingEntries[i]; + if(button.getHtml && typeof button.getHtml == "function"){ + html += button.getHtml({slave}); + } + } + } + } + html += ` +
` + } + %> + <%- html %>
diff --git a/static/sidebar.html b/static/sidebar.html index f51e6443..82be0ab8 100644 --- a/static/sidebar.html +++ b/static/sidebar.html @@ -15,19 +15,21 @@ <%# Very ugly ejs code to hide the Players button if the playerManager plugin isn`t installed %> <% sidebarPluginButtonsHtml = ""; - masterPlugins.forEach(plug => { + for(let o in masterPlugins){ + let plug = masterPlugins[o]; if(plug.main && plug.main.ui && typeof plug.main.ui.sidebar == "object" && Array.isArray(plug.main.ui.sidebar)){ let sidebarEntries = plug.main.ui.sidebar; - sidebarEntries.forEach(button => { + for(let i in sidebarEntries){ + let button = sidebarEntries[i]; if(button.getHtml && typeof button.getHtml == "function"){ sidebarPluginButtonsHtml += button.getHtml(); } - }); + } } - }); + } %> <%- sidebarPluginButtonsHtml %>