diff --git a/src/controllers/custom/editSuitInvigorationUpgradeController.ts b/src/controllers/custom/editSuitInvigorationUpgradeController.ts new file mode 100644 index 00000000..bc624911 --- /dev/null +++ b/src/controllers/custom/editSuitInvigorationUpgradeController.ts @@ -0,0 +1,34 @@ +import { getAccountIdForRequest } from "@/src/services/loginService"; +import { getInventory } from "@/src/services/inventoryService"; +import { RequestHandler } from "express"; + +const DEFAULT_UPGRADE_EXPIRY_MS = 7 * 24 * 60 * 60 * 1000; // 7 days + +export const editSuitInvigorationUpgradeController: RequestHandler = async (req, res) => { + const accountId = await getAccountIdForRequest(req); + const { oid, data } = req.body as { + oid: string; + data?: { + DefensiveUpgrade: string; + OffensiveUpgrade: string; + UpgradesExpiry?: number; + }; + }; + const inventory = await getInventory(accountId); + const suit = inventory.Suits.id(oid)!; + if (data) { + suit.DefensiveUpgrade = data.DefensiveUpgrade; + suit.OffensiveUpgrade = data.OffensiveUpgrade; + if (data.UpgradesExpiry) { + suit.UpgradesExpiry = new Date(data.UpgradesExpiry); + } else { + suit.UpgradesExpiry = new Date(Date.now() + DEFAULT_UPGRADE_EXPIRY_MS); + } + } else { + suit.DefensiveUpgrade = undefined; + suit.OffensiveUpgrade = undefined; + suit.UpgradesExpiry = undefined; + } + await inventory.save(); + res.end(); +}; diff --git a/src/routes/custom.ts b/src/routes/custom.ts index bc0427f4..3a88fefe 100644 --- a/src/routes/custom.ts +++ b/src/routes/custom.ts @@ -14,6 +14,7 @@ import { addMissingMaxRankModsController } from "@/src/controllers/custom/addMis import { webuiFileChangeDetectedController } from "@/src/controllers/custom/webuiFileChangeDetectedController"; import { completeAllMissionsController } from "@/src/controllers/custom/completeAllMissionsController"; import { addMissingHelminthBlueprintsController } from "@/src/controllers/custom/addMissingHelminthBlueprintsController"; +import { editSuitInvigorationUpgradeController } from "@/src/controllers/custom/editSuitInvigorationUpgradeController"; import { createAccountController } from "@/src/controllers/custom/createAccountController"; import { createMessageController } from "@/src/controllers/custom/createMessageController"; @@ -45,6 +46,7 @@ customRouter.get("/addMissingMaxRankMods", addMissingMaxRankModsController); customRouter.get("/webuiFileChangeDetected", webuiFileChangeDetectedController); customRouter.get("/completeAllMissions", completeAllMissionsController); customRouter.get("/addMissingHelminthBlueprints", addMissingHelminthBlueprintsController); +customRouter.post("/editSuitInvigorationUpgrade", editSuitInvigorationUpgradeController); customRouter.post("/createAccount", createAccountController); customRouter.post("/createMessage", createMessageController); diff --git a/static/webui/index.html b/static/webui/index.html index c6f6baa3..34ef3870 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -977,6 +977,59 @@
+ diff --git a/static/webui/script.js b/static/webui/script.js index 8b041836..3eccd2bf 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -667,6 +667,21 @@ function updateInventory() { const td = document.createElement("td"); td.classList = "text-end text-nowrap"; + if (category == "Suits") { + const a = document.createElement("a"); + a.href = "#"; + a.onclick = () => showSuitInvigorationForm(item); + a.innerHTML = ``; + a.style.textDecoration = "none"; + a.title = ""; + td.appendChild(a); + } + let maxXP = Math.pow(uniqueLevelCaps[item.ItemType] ?? 30, 2) * 1000; if ( category != "Suits" && @@ -2862,3 +2877,118 @@ function handleModularPartsChange(event) { }); } } + +function showSuitInvigorationForm(suitData) { + document.getElementById("invigoration-oid").value = suitData.ItemId.$oid; + + // Auto-fill form with existing data + document.getElementById("invigoration-offensive").value = suitData?.OffensiveUpgrade || ""; + document.getElementById("invigoration-defensive").value = suitData?.DefensiveUpgrade || ""; + + // Handle expiry date + if (suitData?.UpgradesExpiry) { + let expiryDate; + if (suitData.UpgradesExpiry.$date) { + // MongoDB format: { "$date": { "$numberLong": "1752933467151" } } + expiryDate = new Date(parseInt(suitData.UpgradesExpiry.$date.$numberLong)); + } else if (typeof suitData.UpgradesExpiry === "number") { + // Timestamp format + expiryDate = new Date(suitData.UpgradesExpiry); + } else if (suitData.UpgradesExpiry instanceof Date) { + // Date object + expiryDate = suitData.UpgradesExpiry; + } + + if (expiryDate && !isNaN(expiryDate.getTime())) { + // Format for datetime-local input (YYYY-MM-DDTHH:mm) + const year = expiryDate.getFullYear(); + const month = String(expiryDate.getMonth() + 1).padStart(2, "0"); + const day = String(expiryDate.getDate()).padStart(2, "0"); + const hours = String(expiryDate.getHours()).padStart(2, "0"); + const minutes = String(expiryDate.getMinutes()).padStart(2, "0"); + + document.getElementById("invigoration-expiry").value = `${year}-${month}-${day}T${hours}:${minutes}`; + } else { + document.getElementById("invigoration-expiry").value = ""; + } + } else { + document.getElementById("invigoration-expiry").value = ""; + } + + const form = document.getElementById("editSuitInvigorationForm"); + form.style.display = "block"; + form.style.position = "fixed"; + form.style.top = "50%"; + form.style.left = "50%"; + form.style.transform = "translate(-50%, -50%)"; + form.style.zIndex = "1050"; + form.style.width = "400px"; + + // Add backdrop + const backdrop = document.createElement("div"); + backdrop.id = "invigoration-backdrop"; + backdrop.style.position = "fixed"; + backdrop.style.top = "0"; + backdrop.style.left = "0"; + backdrop.style.width = "100%"; + backdrop.style.height = "100%"; + backdrop.style.backgroundColor = "rgba(0, 0, 0, 0.5)"; + backdrop.style.zIndex = "1040"; + backdrop.onclick = hideSuitInvigorationForm; + document.body.appendChild(backdrop); +} + +function hideSuitInvigorationForm() { + document.getElementById("editSuitInvigorationForm").style.display = "none"; + const backdrop = document.getElementById("invigoration-backdrop"); + if (backdrop) { + backdrop.remove(); + } +} + +function submitSuitInvigorationUpgrade(event) { + event.preventDefault(); + + const oid = document.getElementById("invigoration-oid").value; + const offensiveUpgrade = document.getElementById("invigoration-offensive").value; + const defensiveUpgrade = document.getElementById("invigoration-defensive").value; + const expiry = document.getElementById("invigoration-expiry").value; + + if (!offensiveUpgrade && !defensiveUpgrade) { + alert("Please select at least one upgrade type."); + return; + } + + const data = { + OffensiveUpgrade: offensiveUpgrade, + DefensiveUpgrade: defensiveUpgrade + }; + + if (expiry) { + data.UpgradesExpiry = new Date(expiry).getTime(); + } + + editSuitInvigorationUpgrade(oid, data); + hideSuitInvigorationForm(); +} + +function clearSuitInvigorationUpgrades() { + const oid = document.getElementById("invigoration-oid").value; + editSuitInvigorationUpgrade(oid, null); + hideSuitInvigorationForm(); +} + +async function editSuitInvigorationUpgrade(oid, data) { + /* data?: { + DefensiveUpgrade: string; + OffensiveUpgrade: string; + UpgradesExpiry?: number; + }*/ + $.post({ + url: "/custom/editSuitInvigorationUpgrade?" + window.authz, + contentType: "application/json", + data: JSON.stringify({ oid, data }) + }).done(function () { + updateInventory(); + }); +}