diff --git a/CHANGELOG.md b/CHANGELOG.md index bccfa8b2..c366087c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ Version 2.0.0 - Factorio game and rcon port now defaults to a random port above 49151. - Removed unimplemented mods update command. - Fixed rcon password being generated with Math.random(). +- Added plugins directory to the views path. This makes it possible for + plugins to render their own ejs views or pages in their own folders by + using paths of the format "pluginName/path/to/page-or-view". ### Breaking Changes @@ -21,6 +24,8 @@ Version 2.0.0 clusterioModel. - Instance names can no longer be invalid Windows file names. - Removed config management from the command line and the server manager. +- Moved ejs templates into views folder and changed their extension to + .ejs. Breaks playerManager. Version 1.2.1 diff --git a/master.js b/master.js index 6f407ed7..e0a1986c 100644 --- a/master.js +++ b/master.js @@ -42,7 +42,6 @@ const authenticate = require("lib/authenticate"); const express = require("express"); const compression = require('compression'); const cookieParser = require('cookie-parser'); -const ejs = require("ejs"); // Required for express post requests const bodyParser = require("body-parser"); const fileUpload = require('express-fileupload'); @@ -59,9 +58,8 @@ app.use(fileUpload()); app.use(compression()); // dynamic HTML generations with EJS -app.set('views', path.join(__dirname, 'static')); -app.set('view engine', 'html'); -app.engine('html', ejs.renderFile); +app.set('view engine', 'ejs'); +app.set('views', ['views', 'sharedPlugins']); // give ejs access to some interesting information app.use(function(req, res, next){ diff --git a/sharedPlugins/serverManager/masterPlugin.js b/sharedPlugins/serverManager/masterPlugin.js index e972283d..981dbf00 100644 --- a/sharedPlugins/serverManager/masterPlugin.js +++ b/sharedPlugins/serverManager/masterPlugin.js @@ -69,8 +69,8 @@ class masterPlugin { let pages = [ { addr: "/serverManager", - path: path.join(__dirname,"static/index.html"), - render: ejs + path: "serverManager/views/index", + render: true }, ] pages.forEach(page => { @@ -81,14 +81,10 @@ class masterPlugin { } else { var permissions = {}; } - page.render.renderFile(page.path, { + res.render(page.path, { permissions, serverManager: this, req: req, - }, async (err, prom) => { - if(err) console.log(err); - let str = await prom; - res.send(str); }); } else { res.send(await fs.readFile(page.path)); diff --git a/sharedPlugins/serverManager/static/index.html b/sharedPlugins/serverManager/views/index.ejs similarity index 90% rename from sharedPlugins/serverManager/static/index.html rename to sharedPlugins/serverManager/views/index.ejs index 0dd92458..54fc72fc 100644 --- a/sharedPlugins/serverManager/static/index.html +++ b/sharedPlugins/serverManager/views/index.ejs @@ -1,12 +1,12 @@ - <%- include("./../../../static/head.html") %> + <%- include("head") %> - <%- include("./../../../static/sidebar.html") %> + <%- include("sidebar") %>
<% @@ -33,6 +33,6 @@
diff --git a/static/browserconfig.xml b/static/browserconfig.xml index c5541482..ae389fe5 100644 --- a/static/browserconfig.xml +++ b/static/browserconfig.xml @@ -1,2 +1,11 @@ -#ffffff \ No newline at end of file + + + + + + + #ffffff + + + \ No newline at end of file diff --git a/static/nodes.html b/static/nodes.html deleted file mode 100644 index f45ec765..00000000 --- a/static/nodes.html +++ /dev/null @@ -1,62 +0,0 @@ - - - <%- include("head.html") %> - - - - - <%- include("nav.html") %> -
- -
- <% - let html = "" - for(let [id, slave] of locals.slaves){ - html += ` -
- -
    -
  • 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}
  • -
- ` - for(let o in locals.masterPlugins){ - let plug = locals.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 += "
" - html += button.getHtml({slave}); - html += "
" - } - } - } - } - html += ` -
- ` - } - %> - <%- html %> -
-
- - \ No newline at end of file diff --git a/static/sidebar.html b/static/sidebar.html deleted file mode 100644 index ab694086..00000000 --- a/static/sidebar.html +++ /dev/null @@ -1 +0,0 @@ -<%- include("nav.html") %> \ No newline at end of file diff --git a/static/head.html b/views/head.ejs similarity index 100% rename from static/head.html rename to views/head.ejs diff --git a/static/index.html b/views/index.ejs similarity index 96% rename from static/index.html rename to views/index.ejs index b755490e..336848b8 100644 --- a/static/index.html +++ b/views/index.ejs @@ -1,11 +1,11 @@ - <%- include("head.html") %> + <%- include("head") %> -<%- include("nav.html") %> +<%- include("nav") %>
- <%# Very ugly ejs code to hide the Players button if the playerManager plugin isn`t installed %> - <% - let sidebarPluginButtonsHtml = ""; - for(let o in locals.masterPlugins){ +
<% +for(let o in locals.masterPlugins) { let plug = locals.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; - for(let i in sidebarEntries){ - let button = sidebarEntries[i]; - if(button.getHtml && typeof button.getHtml == "function"){ - sidebarPluginButtonsHtml += button.getHtml(); + if ( + plug.main + && plug.main.ui + && typeof plug.main.ui.sidebar == "object" + && Array.isArray(plug.main.ui.sidebar) + ) { + let sidebarEntries = plug.main.ui.sidebar; + for (let i in sidebarEntries) { + let button = sidebarEntries[i]; + if (button.getHtml && typeof button.getHtml == "function") { %> + <%- button.getHtml() %><% + } + } } - } - } - } - %> - <%- sidebarPluginButtonsHtml %> +} %> - \ No newline at end of file + diff --git a/static/nodeDetails.html b/views/nodeDetails.ejs similarity index 92% rename from static/nodeDetails.html rename to views/nodeDetails.ejs index 4851b9e3..6d6e2c00 100644 --- a/static/nodeDetails.html +++ b/views/nodeDetails.ejs @@ -1,13 +1,13 @@ - <%- include("head.html") %> + <%- include("head") %> - <%- include("nav.html") %> + <%- include("nav") %>
@@ -29,4 +29,4 @@
- \ No newline at end of file + diff --git a/views/nodes.ejs b/views/nodes.ejs new file mode 100644 index 00000000..1e860c23 --- /dev/null +++ b/views/nodes.ejs @@ -0,0 +1,54 @@ + + + <%- include("head") %> + + + + + <%- include("nav") %> +
+ +
<% +for (let [id, slave] of locals.slaves) { %> +
+ +
    +
  • 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 %>
  • +
<% + for (let o in locals.masterPlugins) { + let plug = locals.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") { %> + <% + } + } + } + } %> +
<% +} %> +
+
+ + diff --git a/static/settings.html b/views/settings.ejs similarity index 81% rename from static/settings.html rename to views/settings.ejs index 8ae0f096..18295ad5 100644 --- a/static/settings.html +++ b/views/settings.ejs @@ -1,11 +1,11 @@ - <%- include("head.html") %> + <%- include("head") %> - <%- include("nav.html") %> + <%- include("nav") %>
- \ No newline at end of file + diff --git a/views/sidebar.ejs b/views/sidebar.ejs new file mode 100644 index 00000000..8809c389 --- /dev/null +++ b/views/sidebar.ejs @@ -0,0 +1 @@ +<%- include("nav") %>