Finished up with toke command list in admin panel.

This commit is contained in:
rainbow napkin 2024-12-12 19:23:11 -05:00
parent 59fe38a5fe
commit 5fe1620c20
7 changed files with 132 additions and 7 deletions

View file

@ -21,6 +21,7 @@ const {mongoose} = require('mongoose');
//const {userModel} = require('./userSchema'); //const {userModel} = require('./userSchema');
const userSchema = require('./userSchema'); const userSchema = require('./userSchema');
const channelPermissionSchema = require('./channel/channelPermissionSchema'); const channelPermissionSchema = require('./channel/channelPermissionSchema');
const {errorHandler} = require('../utils/loggerUtils');
//This originally belonged to the permissionSchema, but this avoids circular dependencies. //This originally belonged to the permissionSchema, but this avoids circular dependencies.
//We could update all references but quite honestly I that would be uglier, this should have a copy too... //We could update all references but quite honestly I that would be uglier, this should have a copy too...
@ -119,8 +120,12 @@ permissionSchema.statics.rankToNum = function(rank){
} }
permissionSchema.statics.permCheck = async function(user, perm){ permissionSchema.statics.permCheck = async function(user, perm){
if(user != null){
const userDB = await userSchema.userModel.findOne({user: user.user}); const userDB = await userSchema.userModel.findOne({user: user.user});
return await this.permCheckByUserDoc(userDB, perm); return await this.permCheckByUserDoc(userDB, perm);
}else{
return await this.permCheckByUserDoc(null, perm);
}
} }
permissionSchema.statics.permCheckByUserDoc = async function(user, perm){ permissionSchema.statics.permCheckByUserDoc = async function(user, perm){

View file

@ -28,6 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.-->
<%- include('partial/adminPanel/userList', {user, userList, rankEnum}) %> <%- include('partial/adminPanel/userList', {user, userList, rankEnum}) %>
<%- include('partial/adminPanel/permList', {permList, rankEnum}) %> <%- include('partial/adminPanel/permList', {permList, rankEnum}) %>
<%- include('partial/adminPanel/userBanList') %> <%- include('partial/adminPanel/userBanList') %>
<%- include('partial/adminPanel/tokeCommandList') %>
</div> </div>
</body> </body>
<footer> <footer>

View file

@ -13,6 +13,12 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>.--> along with this program. If not, see <https://www.gnu.org/licenses/>.-->
<div id="admin-channel-list-div" class="admin-list-div"> <div id="toke-command-list-div" class="admin-list-div">
<h3>Toke Command List:</h3> <h3>Toke Command List:</h3>
<div class="control-prompt">
<input placeholder="Add Command..." id="new-toke-command-input" class="control-prompt">
<button id="new-toke-command-button" class="positive-button">Add</button>
</div>
<div class="dynamic-container toke-command-list">
</div>
</div> </div>

View file

@ -20,7 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
} }
.admin-panel-container-div{ .admin-panel-container-div{
margin: 0 auto; margin: 0 auto 5em;
max-width: 100%; max-width: 100%;
} }
@ -101,3 +101,32 @@ img.admin-list-entry-item{
#admin-ban-list-entry-expiration-date-title{ #admin-ban-list-entry-expiration-date-title{
width: 11em; width: 11em;
} }
#toke-command-list-div{
/*Maybe I suck at CSS but I can't get relative percentage-based heights to play nice here.
Either way sizing this by total viewheight isn't too big a deal. At least here...*/
min-height: 9em;
max-height: 20vh;
}
div.toke-command-list{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));
text-align: center;
padding: 1em;
overflow-y: auto;
}
span.toke-command-list{
display: flex;
}
p.toke-command-list{
white-space: nowrap;
flex: 1;
margin: auto 0;
}
i.toke-command-list{
margin: 0.2em;
}

View file

@ -13,6 +13,9 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>.*/ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
body{
height: 100%;
}
div#channel-flexbox{ div#channel-flexbox{
flex: 1; flex: 1;

View file

@ -20,11 +20,10 @@ html{
} }
body{ body{
height: 100%; min-height: 100%;
margin: 0; margin: 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
form{ form{

View file

@ -390,7 +390,89 @@ class adminUserBanList{
} }
} }
class adminTokeCommandList{
constructor(){
this.tokeCommandList = document.querySelector('div.toke-command-list');
this.newTokeCommandPrompt = document.querySelector('#new-toke-command-input');
this.newTokeCommandButton = document.querySelector('#new-toke-command-button');
//Setup input
this.setupInput();
//Pull the toke list on load
this.getTokeList();
}
setupInput(){
this.newTokeCommandButton.addEventListener('click', this.addToke.bind(this));
}
async addToke(event){
//Send out the new toke command and get the new list
const tokeList = await adminUtil.addTokeCommand(this.newTokeCommandPrompt.value);
//clear the prompt
this.newTokeCommandPrompt.value = "";
//render the returned list
this.renderTokeList(tokeList);
}
async getTokeList(){
const tokeList = await adminUtil.getTokeCommands();
this.renderTokeList(tokeList);
}
clearTokeList(){
this.tokeCommandList.innerHTML = "";
}
async deleteToke(event){
const name = event.target.id.replace("toke-command-delete-","");
const tokeList = await adminUtil.deleteTokeCommand(name);
this.renderTokeList(tokeList);
}
renderTokeList(tokeList){
if(tokeList != null){
//Clear our the toke list
this.clearTokeList();
//For each toke in the received list
tokeList.forEach((toke)=>{
//generate a toke command span, and append it to the toke list div
this.tokeCommandList.appendChild(this.generateTokeSpan(toke));
});
}
}
generateTokeSpan(toke){
//Create toke command span
const tokeSpan = document.createElement('span');
tokeSpan.classList.add('toke-command-list');
//Create toke command label
const tokeLabel = document.createElement('p');
tokeLabel.innerHTML = `!${toke}`;
tokeLabel.classList.add('toke-command-list');
//Create toke command delete icon
const tokeDelete = document.createElement('i');
tokeDelete.classList.add('toke-command-list', 'bi-trash-fill', 'toke-command-delete');
tokeDelete.id = `toke-command-delete-${toke}`;
tokeDelete.addEventListener('click', this.deleteToke.bind(this));
//append span contents to tokeSpan
tokeSpan.appendChild(tokeLabel);
tokeSpan.appendChild(tokeDelete);
//return the toke span
return tokeSpan
}
}
const adminUtil = new canopyAdminUtils(); const adminUtil = new canopyAdminUtils();
const userList = new adminUserList(); const userList = new adminUserList();
const permissionList = new adminPermissionList(); const permissionList = new adminPermissionList();
const userBanList = new adminUserBanList(); const userBanList = new adminUserBanList();
const tokeCommandList = new adminTokeCommandList();