feat(webui): add "add missing mods" (#804)
Co-authored-by: Chinosu <46995931+Chinosu@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									a8fb9095c5
								
							
						
					
					
						commit
						fc8537ba4d
					
				@ -199,6 +199,12 @@
 | 
			
		||||
                                </table>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="card mb-3">
 | 
			
		||||
                            <h5 class="card-header">Bulk Actions</h5>
 | 
			
		||||
                            <div class="card-body">
 | 
			
		||||
                                <button class="btn btn-primary" onclick="doAddAllMods();">Add Missing Mods</button>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
@ -1077,6 +1077,50 @@ function doHelminthUnlockAll() {
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function doAddAllMods() {
 | 
			
		||||
    let modsAll = new Set();
 | 
			
		||||
    for (const child of document.getElementById("datalist-mods").children) {
 | 
			
		||||
        modsAll.add(child.getAttribute("data-key"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    revalidateAuthz(() => {
 | 
			
		||||
        const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
 | 
			
		||||
        req.done(data => {
 | 
			
		||||
            for (const modOwned of data.RawUpgrades) {
 | 
			
		||||
                if (modOwned.ItemCount ?? 1 > 0) {
 | 
			
		||||
                    modsAll.delete(modOwned.ItemType);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            modsAll = Array.from(modsAll);
 | 
			
		||||
            if (
 | 
			
		||||
                modsAll.length != 0 &&
 | 
			
		||||
                window.confirm("Are you sure you want to add " + modsAll.length + " mods to your account?")
 | 
			
		||||
            ) {
 | 
			
		||||
                // Batch to avoid PayloadTooLargeError
 | 
			
		||||
                const batches = [];
 | 
			
		||||
                for (let i = 0; i < modsAll.length; i += 1000) {
 | 
			
		||||
                    batches.push(modsAll.slice(i, i + 1000));
 | 
			
		||||
                }
 | 
			
		||||
                batches.forEach(batch => {
 | 
			
		||||
                    $.post({
 | 
			
		||||
                        url: "/api/missionInventoryUpdate.php?" + window.authz,
 | 
			
		||||
                        contentType: "text/plain",
 | 
			
		||||
                        data: JSON.stringify({
 | 
			
		||||
                            RawUpgrades: batch.map(mod => ({
 | 
			
		||||
                                ItemType: mod,
 | 
			
		||||
                                ItemCount: 21 // To fully upgrade certain arcanes
 | 
			
		||||
                            }))
 | 
			
		||||
                        })
 | 
			
		||||
                    }).done(function () {
 | 
			
		||||
                        updateInventory();
 | 
			
		||||
                    });
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Powersuit Route
 | 
			
		||||
 | 
			
		||||
single.getRoute("#powersuit-route").on("beforeload", function () {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user