fucking shitty race condition or something idek what to call that
This commit is contained in:
parent
d62a5e7e80
commit
bee19d5af9
1 changed files with 89 additions and 94 deletions
183
src/ts/main.ts
183
src/ts/main.ts
|
@ -101,64 +101,61 @@ elements.searchUsersForm.addEventListener('submit', async e => {
|
||||||
elements.usersTableBody.innerHTML = "";
|
elements.usersTableBody.innerHTML = "";
|
||||||
elements.usersPageCount.innerText = data.totalPageCount!.toString(10);
|
elements.usersPageCount.innerText = data.totalPageCount!.toString(10);
|
||||||
elements.usersPage.max = data.totalPageCount!.toString(10);
|
elements.usersPage.max = data.totalPageCount!.toString(10);
|
||||||
for (var user of data.users!) {
|
data.users?.forEach(user => {
|
||||||
(() => {
|
var row = elements.usersTableBody.insertRow();
|
||||||
var _user = user;
|
var cell = row.insertCell();
|
||||||
var row = elements.usersTableBody.insertRow();
|
cell.innerText = user.id.toString(10);
|
||||||
var cell = row.insertCell();
|
cell = row.insertCell();
|
||||||
cell.innerText = user.id.toString(10);
|
cell.innerText = user.username;
|
||||||
cell = row.insertCell();
|
cell = row.insertCell();
|
||||||
cell.innerText = user.username;
|
cell.innerText = user.email;
|
||||||
cell = row.insertCell();
|
cell = row.insertCell();
|
||||||
cell.innerText = user.email;
|
// Rank dropdown
|
||||||
cell = row.insertCell();
|
var rankSelect = document.createElement('select');
|
||||||
// Rank dropdown
|
rankSelect.classList.add('form-select');
|
||||||
var rankSelect = document.createElement('select');
|
rankSelect.innerHTML = `<option value="1">User</option><option value="2">Administrator</option><option value="3">Moderator</option>`;
|
||||||
rankSelect.classList.add('form-select');
|
rankSelect.value = user.rank.toString(10);
|
||||||
rankSelect.innerHTML = `<option value="1">User</option><option value="2">Administrator</option><option value="3">Moderator</option>`;
|
rankSelect.addEventListener('change', async e => {
|
||||||
rankSelect.value = _user.rank.toString(10);
|
var newRank = parseInt(rankSelect.value);
|
||||||
rankSelect.addEventListener('change', async e => {
|
// @ts-ignore
|
||||||
var newRank = parseInt(rankSelect.value);
|
if (!window.confirm(`Are you sure you want to set ${user.username}'s rank to ${RankString[newRank]}?`)) {
|
||||||
// @ts-ignore
|
e.preventDefault();
|
||||||
if (!window.confirm(`Are you sure you want to set ${_user.username}'s rank to ${RankString[newRank]}?`)) {
|
rankSelect.value = user.rank.toString(10);
|
||||||
e.preventDefault();
|
return false;
|
||||||
rankSelect.value = _user.rank.toString(10);
|
}
|
||||||
return false;
|
var result = await auth.updateUser(user.username, newRank);
|
||||||
}
|
if (!result.success) {
|
||||||
var result = await auth.updateUser(_user.username, newRank);
|
alert("Failed to set rank: " + result.error);
|
||||||
if (!result.success) {
|
}
|
||||||
alert("Failed to set rank: " + result.error);
|
});
|
||||||
}
|
cell.appendChild(rankSelect);
|
||||||
});
|
cell = row.insertCell();
|
||||||
cell.appendChild(rankSelect);
|
cell.innerText = user.banned ? "Yes" : "No";
|
||||||
cell = row.insertCell();
|
cell = row.insertCell();
|
||||||
cell.innerText = user.banned ? "Yes" : "No";
|
cell.innerText = user.dateOfBirth;
|
||||||
cell = row.insertCell();
|
cell = row.insertCell();
|
||||||
cell.innerText = user.dateOfBirth;
|
cell.innerText = user.dateJoined;
|
||||||
cell = row.insertCell();
|
cell = row.insertCell();
|
||||||
cell.innerText = user.dateJoined;
|
cell.innerText = user.registrationIp;
|
||||||
cell = row.insertCell();
|
cell = row.insertCell();
|
||||||
cell.innerText = user.registrationIp;
|
var developerCheckbox = document.createElement('input');
|
||||||
cell = row.insertCell();
|
developerCheckbox.type = 'checkbox';
|
||||||
var developerCheckbox = document.createElement('input');
|
developerCheckbox.checked = user.developer;
|
||||||
developerCheckbox.type = 'checkbox';
|
developerCheckbox.addEventListener('change', async e => {
|
||||||
developerCheckbox.checked = _user.developer;
|
var developer = developerCheckbox.checked;
|
||||||
developerCheckbox.addEventListener('change', async e => {
|
// @ts-ignore
|
||||||
var developer = developerCheckbox.checked;
|
if (!window.confirm(`Are you sure you want to ${developer ? "grant" : "revoke"} developer status ${developer ? "to" : "from"} ${_user.username}?`)) {
|
||||||
// @ts-ignore
|
e.preventDefault();
|
||||||
if (!window.confirm(`Are you sure you want to ${developer ? "grant" : "revoke"} developer status ${developer ? "to" : "from"} ${_user.username}?`)) {
|
developerCheckbox.checked = !developer;
|
||||||
e.preventDefault();
|
return false;
|
||||||
developerCheckbox.checked = !developer;
|
}
|
||||||
return false;
|
var result = await auth.updateUser(user.username, undefined, developer);
|
||||||
}
|
if (!result.success) {
|
||||||
var result = await auth.updateUser(_user.username, undefined, developer);
|
alert("Failed to update developer status: " + result.error);
|
||||||
if (!result.success) {
|
}
|
||||||
alert("Failed to update developer status: " + result.error);
|
});
|
||||||
}
|
cell.appendChild(developerCheckbox);
|
||||||
});
|
});
|
||||||
cell.appendChild(developerCheckbox);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -171,43 +168,41 @@ elements.searchBotsForm.addEventListener('submit', async e => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
elements.botsTableBody.innerHTML = "";
|
elements.botsTableBody.innerHTML = "";
|
||||||
for (const bot of data.bots!) {
|
data.bots?.forEach(bot => {
|
||||||
(()=>{
|
var row = elements.botsTableBody.insertRow();
|
||||||
var row = elements.botsTableBody.insertRow();
|
var cell = row.insertCell();
|
||||||
var cell = row.insertCell();
|
cell.innerText = bot.id.toString(10);
|
||||||
cell.innerText = bot.id.toString(10);
|
cell = row.insertCell();
|
||||||
cell = row.insertCell();
|
cell.innerText = bot.username;
|
||||||
cell.innerText = bot.username;
|
cell = row.insertCell();
|
||||||
cell = row.insertCell();
|
if (auth!.account!.rank === 2) {
|
||||||
if (auth!.account!.rank === 2) {
|
var rankSelect = document.createElement('select');
|
||||||
var rankSelect = document.createElement('select');
|
rankSelect.classList.add('form-select');
|
||||||
rankSelect.classList.add('form-select');
|
rankSelect.innerHTML = `<option value="1">User</option><option value="2">Administrator</option><option value="3">Moderator</option>`;
|
||||||
rankSelect.innerHTML = `<option value="1">User</option><option value="2">Administrator</option><option value="3">Moderator</option>`;
|
rankSelect.value = bot.rank.toString(10);
|
||||||
rankSelect.value = bot.rank.toString(10);
|
rankSelect.addEventListener('change', async e => {
|
||||||
rankSelect.addEventListener('change', async e => {
|
var newRank = parseInt(rankSelect.value);
|
||||||
var newRank = parseInt(rankSelect.value);
|
|
||||||
// @ts-ignore
|
|
||||||
if (!window.confirm(`Are you sure you want to set ${bot.username}'s rank to ${RankString[newRank]}?`)) {
|
|
||||||
e.preventDefault();
|
|
||||||
rankSelect.value = bot.rank.toString(10);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var result = await auth.adminUpdateBot(bot.username, newRank);
|
|
||||||
if (!result.success) {
|
|
||||||
alert("Failed to set rank: " + result.error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cell.appendChild(rankSelect);
|
|
||||||
} else {
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
cell.innerText = RankString[bot.rank];
|
if (!window.confirm(`Are you sure you want to set ${bot.username}'s rank to ${RankString[newRank]}?`)) {
|
||||||
}
|
e.preventDefault();
|
||||||
cell = row.insertCell();
|
rankSelect.value = bot.rank.toString(10);
|
||||||
cell.innerText = bot.owner;
|
return false;
|
||||||
cell = row.insertCell();
|
}
|
||||||
cell.innerText = bot.created;
|
var result = await auth.adminUpdateBot(bot.username, newRank);
|
||||||
})();
|
if (!result.success) {
|
||||||
}
|
alert("Failed to set rank: " + result.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cell.appendChild(rankSelect);
|
||||||
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
|
cell.innerText = RankString[bot.rank];
|
||||||
|
}
|
||||||
|
cell = row.insertCell();
|
||||||
|
cell.innerText = bot.owner;
|
||||||
|
cell = row.insertCell();
|
||||||
|
cell.innerText = bot.created;
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue