diff --git a/public/js/fetchPlans.js b/public/js/fetchPlans.js new file mode 100644 index 0000000..90baa31 --- /dev/null +++ b/public/js/fetchPlans.js @@ -0,0 +1,40 @@ +document.addEventListener('DOMContentLoaded', function() { + const eggSelect = document.getElementById('egg'); + const nodeSelect = document.getElementById('node'); + const planDetailsDiv = document.getElementById('plan-details'); + + eggSelect.addEventListener('change', updatePlans); + nodeSelect.addEventListener('change', updatePlans); + + function updatePlans() { + const selectedEgg = eggSelect.value; + const selectedNode = nodeSelect.value; + + if (selectedEgg && selectedNode) { + fetch(`/api/plans?egg=${selectedEgg}&node=${selectedNode}`) + .then(response => response.json()) + .then(plans => { + // Clear existing plan details + planDetailsDiv.innerHTML = ''; + // Populate new plan details + plans.forEach(plan => { + const planDiv = document.createElement('div'); + planDiv.classList.add('p-4', 'bg-slate-600', 'rounded-md', 'text-center'); + planDiv.innerHTML = ` +

${plan.name}

+ `; + planDetailsDiv.appendChild(planDiv); + }); + }) + .catch(error => console.error('Error fetching plans:', error)); + } + } +}); \ No newline at end of file diff --git a/routes/servers.js b/routes/servers.js index b4d46cd..acbce23 100644 --- a/routes/servers.js +++ b/routes/servers.js @@ -6,7 +6,8 @@ const Egg = require("../models/Egg"); const Plan = require("../models/Plan"); const SettingsModel = require("../models/Settings"); const { sha256 } = require('js-sha256'); - +const Nest = require('../models/Nest'); +const Node = require('../models/Node'); router.get("/", checkSetup, checkAuth, async function (req, res) { const servers = await Server.findAll({where: {ownerId: req.user.id}}) @@ -18,11 +19,35 @@ router.get("/", checkSetup, checkAuth, async function (req, res) { plan: plan.name, egg: (await Egg.findOne({where: {id: server.eggId}})).name, price: plan.price, - hourPrice: (plan.price / 720).toFixed(2) + hourPrice: (plan.price / 720).toFixed(2), + node: (await Node.findOne({where: {id: server.nodeId}})).name, } return serverObject; })) - res.render("dash/servers.html", {hostname: (await SettingsModel.findOne({where: {name: "hostname"}})).value, servers: serversArray, username: req.user.username, gravatarhash: sha256(req.user.email), credits: req.user.credits, pterourl: (await SettingsModel.findOne({where: {name: "pterourl"}})).value, isAdmin: req.user.admin, page: "Your servers"}) + + // GET DATA + const plans = await Plan.findAll(); + let usedEggs = []; + let usedNests = []; + plans.forEach((plan) => plan.eggs.split(",").forEach((egg) => usedEggs.push(parseInt(egg)))); + const eggs = await Egg.findAll({ where: { id: usedEggs} }); + eggs.forEach((egg) => usedNests.push(egg.nestId)); + const nests = await Nest.findAll({ where: { id: usedNests } }); + const nodes = await Node.findAll(); + + res.render("dash/servers.html", + {hostname: (await SettingsModel.findOne({where: {name: "hostname"}})).value, + servers: serversArray, + username: req.user.username, + gravatarhash: sha256(req.user.email), + credits: req.user.credits, + pterourl: (await SettingsModel.findOne({where: {name: "pterourl"}})).value, + isAdmin: req.user.admin, + page: "Your servers", + nests: nests, + eggs: eggs, + nodes: nodes, + }) }) diff --git a/views/modals/createserver.html b/views/modals/createserver.html new file mode 100644 index 0000000..c4fc045 --- /dev/null +++ b/views/modals/createserver.html @@ -0,0 +1,42 @@ +{% extends "modals/modal.html" %} + + +{% block content %} +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ + + + +{% endblock %} \ No newline at end of file diff --git a/views/modals/modal.html b/views/modals/modal.html index aa5cc9f..9eb8b54 100644 --- a/views/modals/modal.html +++ b/views/modals/modal.html @@ -2,7 +2,7 @@