Added user rank changes to admin page.
This commit is contained in:
parent
064109556c
commit
8a4a21cff0
13 changed files with 276 additions and 30 deletions
69
www/js/adminPanel.js
Normal file
69
www/js/adminPanel.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*Canopy - The next generation of stoner streaming software
|
||||
Copyright (C) 2024 Rainbownapkin and the TTN Community
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
class canopyAdminUtils{
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
async setUserRank(user, rank){
|
||||
var response = await fetch(`/api/admin/changeRank`,{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
//Unfortunately JSON doesn't natively handle ES6 maps, and god forbid someone update the standard in a way that's backwards compatible...
|
||||
body: JSON.stringify({user, rank})
|
||||
});
|
||||
|
||||
if(response.status == 200){
|
||||
return await response.json();
|
||||
}else{
|
||||
utils.ux.displayResponseError(await response.json());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class adminUserList{
|
||||
constructor(){
|
||||
this.rankSelectors = document.querySelectorAll(".admin-user-list-rank-select");
|
||||
|
||||
this.setupInput();
|
||||
}
|
||||
|
||||
setupInput(){
|
||||
this.rankSelectors.forEach((rankSelector)=>{
|
||||
rankSelector.addEventListener("change", this.setRank.bind(this))
|
||||
});
|
||||
}
|
||||
|
||||
async setRank(event){
|
||||
const user = event.target.id.replace("admin-user-list-rank-select-","");
|
||||
const rank = event.target.value;
|
||||
|
||||
this.updateSelect(await adminUtil.setUserRank(user, rank), event.target);
|
||||
}
|
||||
|
||||
updateSelect(update, select){
|
||||
if(update != null){
|
||||
select.value = update.rank;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const adminUtil = new canopyAdminUtils();
|
||||
const userList = new adminUserList();
|
||||
|
|
@ -172,7 +172,7 @@ class deleteAccountPrompt{
|
|||
if(response.status == 200){
|
||||
window.location.pathname = '/';
|
||||
}else{
|
||||
displayResponseError(await response.json());
|
||||
utils.ux.displayResponseError(await response.json());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@ class canopyUXUtils{
|
|||
constructor(){
|
||||
}
|
||||
|
||||
async displayResponseError(body){
|
||||
const errors = body.errors;
|
||||
errors.forEach((err)=>{
|
||||
window.alert(`ERROR: ${err.msg} \nTYPE: ${err.type} \nDATE: ${err.date}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static clickDragger = class{
|
||||
constructor(handle, element, leftHandle = true){
|
||||
|
|
@ -117,13 +124,7 @@ class canopyAjaxUtils{
|
|||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
//Profile
|
||||
async displayResponseError(body){
|
||||
const err = body.msg;
|
||||
window.alert(`ERROR:\n${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
async register(user, pass, passConfirm, email){
|
||||
var response = await fetch(`/api/account/register`,{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue