feat(webui): add "max rank all warframes" & "max rank all weapons" #783

Merged
nrbdev merged 3 commits from rank-30-everything into main 2025-01-15 07:29:02 -08:00
2 changed files with 93 additions and 11 deletions

View File

@ -96,9 +96,9 @@
</div> </div>
<div class="row g-3"> <div class="row g-3">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="card mb-3"> <div class="card mb-3" style="height: 480px;">
<h5 class="card-header">Warframes</h5> <h5 class="card-header">Warframes</h5>
<div class="card-body"> <div class="card-body overflow-auto">
<form class="input-group mb-3" onsubmit="doAcquireWarframe();return false;"> <form class="input-group mb-3" onsubmit="doAcquireWarframe();return false;">
<input class="form-control" id="warframe-to-acquire" list="datalist-warframes" /> <input class="form-control" id="warframe-to-acquire" list="datalist-warframes" />
<button class="btn btn-primary" type="submit">Add</button> <button class="btn btn-primary" type="submit">Add</button>
@ -108,18 +108,11 @@
</table> </table>
</div> </div>
</div> </div>
<div class="card mb-3">
<h5 class="card-header">Bulk Actions</h5>
<div class="card-body">
<button class="btn btn-primary" onclick="addMissingWarframes();">Add Missing Warframes</button>
<button class="btn btn-primary" onclick="addMissingWeapons();">Add Missing Weapons</button>
</div>
</div>
</div> </div>
<div class="col-lg-6"> <div class="col-lg-6">
<div class="card mb-3"> <div class="card mb-3" style="height: 480px;">
<h5 class="card-header">Weapons</h5> <h5 class="card-header">Weapons</h5>
<div class="card-body"> <div class="card-body overflow-auto">
<form class="input-group mb-3" onsubmit="doAcquireWeapon();return false;"> <form class="input-group mb-3" onsubmit="doAcquireWeapon();return false;">
<input class="form-control" id="weapon-to-acquire" list="datalist-weapons" /> <input class="form-control" id="weapon-to-acquire" list="datalist-weapons" />
<button class="btn btn-primary" type="submit">Add</button> <button class="btn btn-primary" type="submit">Add</button>
@ -131,6 +124,15 @@
</div> </div>
</div> </div>
</div> </div>
<div class="card mb-3">
<h5 class="card-header">Bulk Actions</h5>
<div class="card-body d-flex flex-wrap gap-2">
<button class="btn btn-primary" onclick="addMissingWarframes();">Add Missing Warframes</button>
<button class="btn btn-primary" onclick="addMissingWeapons();">Add Missing Weapons</button>
<button class="btn btn-success" onclick="maxRankAllWarframes()">Max Rank All Warframes</button>
<button class="btn btn-success" onclick="maxRankAllWeapons()">Max Rank All Weapons</button>
</div>
</div>
</div> </div>
<div id="powersuit-route" data-route="~ /webui/powersuit/(.+)" data-title="Inventory | OpenWF WebUI"> <div id="powersuit-route" data-route="~ /webui/powersuit/(.+)" data-title="Inventory | OpenWF WebUI">
<h3 class="mb-0"></h3> <h3 class="mb-0"></h3>

View File

@ -605,6 +605,46 @@ function addMissingWarframes() {
} }
} }
function maxRankAllWarframes() {
const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
req.done(data => {
window.itemListPromise.then(itemMap => {
const batchData = { Suits: [], SpecialItems: [] };
data.Suits.forEach(item => {
if (item.XP < 1_600_000) {
batchData.Suits.push({
ItemId: { $oid: item.ItemId.$oid },
XP: 1_600_000 - item.XP
});
}
if ("exalted" in itemMap[item.ItemType]) {
for (const exaltedType of itemMap[item.ItemType].exalted) {
const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType);
if (exaltedItem) {
const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000;
if (exaltedItem.XP < exaltedCap) {
batchData.SpecialItems.push({
ItemId: { $oid: exaltedItem.ItemId.$oid },
XP: exaltedCap
});
}
}
}
}
});
if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) {
return sendBatchGearExp(batchData);
}
alert("No Warframes to rank up.");
});
});
}
coderabbitai[bot] commented 2025-01-15 06:59:58 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add error handling and improve user feedback.

The function needs the following improvements:

  1. Error handling for API calls
  2. Loading state feedback for long operations
  3. Constants for XP thresholds

Consider this implementation:

+const WARFRAME_MAX_XP = 1_600_000;
+const WEAPON_MAX_XP = 800_000;

 function maxRankAllWarframes() {
+    const button = document.querySelector('button[onclick="maxRankAllWarframes()"]');
+    button.disabled = true;
+    button.textContent = 'Processing...';
+
     const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
-    req.done(data => {
+    req.done(data => {
         window.itemListPromise.then(itemMap => {
             const batchData = { Suits: [], SpecialItems: [] };
 
             data.Suits.forEach(item => {
-                if (item.XP < 1_600_000) {
+                if (item.XP < WARFRAME_MAX_XP) {
                     batchData.Suits.push({
                         ItemId: { $oid: item.ItemId.$oid },
-                        XP: 1_600_000 - item.XP
+                        XP: WARFRAME_MAX_XP - item.XP
                     });
                 }
 
                 if ("exalted" in itemMap[item.ItemType]) {
                     for (const exaltedType of itemMap[item.ItemType].exalted) {
                         const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType);
                         if (exaltedItem) {
-                            const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000;
+                            const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP;
                             if (exaltedItem.XP < exaltedCap) {
                                 batchData.SpecialItems.push({
                                     ItemId: { $oid: exaltedItem.ItemId.$oid },
                                     XP: exaltedCap - exaltedItem.XP
                                 });
                             }
                         }
                     }
                 }
             });
 
             if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) {
-                return sendBatchGearExp(batchData);
+                return sendBatchGearExp(batchData).finally(() => {
+                    button.disabled = false;
+                    button.textContent = 'Max Rank All Warframes';
+                });
             }
 
             alert("No Warframes to rank up.");
+            button.disabled = false;
+            button.textContent = 'Max Rank All Warframes';
         });
+    }).fail(error => {
+        console.error('Failed to fetch inventory:', error);
+        alert('Failed to fetch inventory. Please try again.');
+        button.disabled = false;
+        button.textContent = 'Max Rank All Warframes';
     });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

const WARFRAME_MAX_XP = 1_600_000;
const WEAPON_MAX_XP = 800_000;

function maxRankAllWarframes() {
    const button = document.querySelector('button[onclick="maxRankAllWarframes()"]');
    button.disabled = true;
    button.textContent = 'Processing...';

    const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
    req.done(data => {
        window.itemListPromise.then(itemMap => {
            const batchData = { Suits: [], SpecialItems: [] };

            data.Suits.forEach(item => {
                if (item.XP < WARFRAME_MAX_XP) {
                    batchData.Suits.push({
                        ItemId: { $oid: item.ItemId.$oid },
                        XP: WARFRAME_MAX_XP - item.XP
                    });
                }

                if ("exalted" in itemMap[item.ItemType]) {
                    for (const exaltedType of itemMap[item.ItemType].exalted) {
                        const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType);
                        if (exaltedItem) {
                            const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP;
                            if (exaltedItem.XP < exaltedCap) {
                                batchData.SpecialItems.push({
                                    ItemId: { $oid: exaltedItem.ItemId.$oid },
                                    XP: exaltedCap - exaltedItem.XP
                                });
                            }
                        }
                    }
                }
            });

            if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) {
                return sendBatchGearExp(batchData).finally(() => {
                    button.disabled = false;
                    button.textContent = 'Max Rank All Warframes';
                });
            }

            alert("No Warframes to rank up.");
            button.disabled = false;
            button.textContent = 'Max Rank All Warframes';
        });
    }).fail(error => {
        console.error('Failed to fetch inventory:', error);
        alert('Failed to fetch inventory. Please try again.');
        button.disabled = false;
        button.textContent = 'Max Rank All Warframes';
    });
}
🧰 Tools
🪛 eslint

[error] 608-608: 'maxRankAllWarframes' is defined but never used.

(@typescript-eslint/no-unused-vars)


[error] 609-609: '$' is not defined.

(no-undef)

_:hammer_and_wrench: Refactor suggestion_ **Add error handling and improve user feedback.** The function needs the following improvements: 1. Error handling for API calls 2. Loading state feedback for long operations 3. Constants for XP thresholds Consider this implementation: ```diff +const WARFRAME_MAX_XP = 1_600_000; +const WEAPON_MAX_XP = 800_000; function maxRankAllWarframes() { + const button = document.querySelector('button[onclick="maxRankAllWarframes()"]'); + button.disabled = true; + button.textContent = 'Processing...'; + const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1"); - req.done(data => { + req.done(data => { window.itemListPromise.then(itemMap => { const batchData = { Suits: [], SpecialItems: [] }; data.Suits.forEach(item => { - if (item.XP < 1_600_000) { + if (item.XP < WARFRAME_MAX_XP) { batchData.Suits.push({ ItemId: { $oid: item.ItemId.$oid }, - XP: 1_600_000 - item.XP + XP: WARFRAME_MAX_XP - item.XP }); } if ("exalted" in itemMap[item.ItemType]) { for (const exaltedType of itemMap[item.ItemType].exalted) { const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType); if (exaltedItem) { - const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000; + const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP; if (exaltedItem.XP < exaltedCap) { batchData.SpecialItems.push({ ItemId: { $oid: exaltedItem.ItemId.$oid }, XP: exaltedCap - exaltedItem.XP }); } } } } }); if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) { - return sendBatchGearExp(batchData); + return sendBatchGearExp(batchData).finally(() => { + button.disabled = false; + button.textContent = 'Max Rank All Warframes'; + }); } alert("No Warframes to rank up."); + button.disabled = false; + button.textContent = 'Max Rank All Warframes'; }); + }).fail(error => { + console.error('Failed to fetch inventory:', error); + alert('Failed to fetch inventory. Please try again.'); + button.disabled = false; + button.textContent = 'Max Rank All Warframes'; }); } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion const WARFRAME_MAX_XP = 1_600_000; const WEAPON_MAX_XP = 800_000; function maxRankAllWarframes() { const button = document.querySelector('button[onclick="maxRankAllWarframes()"]'); button.disabled = true; button.textContent = 'Processing...'; const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1"); req.done(data => { window.itemListPromise.then(itemMap => { const batchData = { Suits: [], SpecialItems: [] }; data.Suits.forEach(item => { if (item.XP < WARFRAME_MAX_XP) { batchData.Suits.push({ ItemId: { $oid: item.ItemId.$oid }, XP: WARFRAME_MAX_XP - item.XP }); } if ("exalted" in itemMap[item.ItemType]) { for (const exaltedType of itemMap[item.ItemType].exalted) { const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType); if (exaltedItem) { const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP; if (exaltedItem.XP < exaltedCap) { batchData.SpecialItems.push({ ItemId: { $oid: exaltedItem.ItemId.$oid }, XP: exaltedCap - exaltedItem.XP }); } } } } }); if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) { return sendBatchGearExp(batchData).finally(() => { button.disabled = false; button.textContent = 'Max Rank All Warframes'; }); } alert("No Warframes to rank up."); button.disabled = false; button.textContent = 'Max Rank All Warframes'; }); }).fail(error => { console.error('Failed to fetch inventory:', error); alert('Failed to fetch inventory. Please try again.'); button.disabled = false; button.textContent = 'Max Rank All Warframes'; }); } ````` </details> <!-- suggestion_end --> <details> <summary>🧰 Tools</summary> <details> <summary>🪛 eslint</summary> [error] 608-608: 'maxRankAllWarframes' is defined but never used. (@typescript-eslint/no-unused-vars) --- [error] 609-609: '$' is not defined. (no-undef) </details> </details> <!-- This is an auto-generated comment by CodeRabbit -->
function addMissingWeapons() { function addMissingWeapons() {
const requests = []; const requests = [];
document.querySelectorAll("#datalist-weapons option").forEach(elm => { document.querySelectorAll("#datalist-weapons option").forEach(elm => {
@ -620,6 +660,34 @@ function addMissingWeapons() {
} }
} }
function maxRankAllWeapons() {
const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
req.done(data => {
const batchData = {};
["LongGuns", "Pistols", "Melee"].forEach(category => {
data[category].forEach(item => {
if (item.XP < 800_000) {
if (!batchData[category]) {
batchData[category] = [];
}
batchData[category].push({
ItemId: { $oid: item.ItemId.$oid },
XP: 800_000 - item.XP
});
}
});
});
if (Object.keys(batchData).length > 0) {
return sendBatchGearExp(batchData);
}
alert("No weapons to rank up.");
});
}
function addGearExp(category, oid, xp) { function addGearExp(category, oid, xp) {
const data = {}; const data = {};
data[category] = [ data[category] = [
@ -641,6 +709,18 @@ function addGearExp(category, oid, xp) {
}); });
} }
function sendBatchGearExp(data) {
revalidateAuthz(() => {
$.post({
url: "/api/missionInventoryUpdate.php?" + window.authz,
contentType: "text/plain",
data: JSON.stringify(data)
}).done(() => {
updateInventory();
});
});
}
function renameGear(category, oid, name) { function renameGear(category, oid, name) {
revalidateAuthz(() => { revalidateAuthz(() => {
$.post({ $.post({