This commit is contained in:
Alex Orid 2021-05-12 01:04:48 -04:00
parent 99f5ee8e72
commit c5313fe853
4 changed files with 95 additions and 63 deletions

View File

@ -143,6 +143,11 @@ def get_data():
return handle_request_get(request.args['request_name'], request.args['request_type'], requestData) return handle_request_get(request.args['request_name'], request.args['request_type'], requestData)
@api.route('/api/v1/user_client/set', methods=['GET'])
def set_data():
if 'request_type' not in request.args:
return flask.make_response('{\"text\":"Argument \'request_type\' not in request"}', 400)
if __name__ == "__main__": if __name__ == "__main__":
init() init()

View File

@ -101,21 +101,14 @@
<div id="Commands" style="padding-top: 20px;"><div class="rowsInMain center card"> <div id="Commands" style="padding-top: 20px;"><div class="rowsInMain center card">
<a class="btn-floating btn-large waves-effect waves-light blue right" style="margin-right: 10px;"> <a onclick="updateCommandList()" class="btn-floating btn-large waves-effect waves-light blue right" style="margin-right: 10px;">
<i class="material-icons">refresh</i> <i class="material-icons">refresh</i>
</a> </a>
<h3>Commands:</h3></div> <h3>Commands:</h3></div>
<div class="rowsInMain row card" style="margin-right: 20px;margin-left: 20px;margin-top: 30px;margin-bottom: 30px;"> <div id="CommandRowWrapper">
<div class="col s12 switch" style="top: -20px;position: relative;padding-left: 10px;"><label>Enabled:<input type="checkbox"><span class="lever"></span></label></div>
<div class="col s4"><p>Command Name:</p>
<div class="input-field inline" style="width: 80%;">
<input disabled id="command_inline " type="text" value="!testerino" class="validate">
<label for="command_inline">Command</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="Rewards" style="padding-top: 20px;"></div><div class="rowsInMain center card"> <div id="Rewards" style="padding-top: 20px;"></div><div class="rowsInMain center card">
@ -294,7 +287,6 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -17,6 +17,20 @@ async function BotStatus() {
BotStatus(); BotStatus();
async function setValue(request_type, command, isEnabled) {
let newCommandState = {
'request_type': request_type,
'command_name': command,
'is_enabled': isEnabled
}
let params = "?command_name="+encodeURIComponent(newCommandState.command_name)+"&"+"is_enabled="+encodeURIComponent(newCommandState.is_enabled);
let targetURL = "http://127.0.0.1:42055/api/v1/user_client/set"+params;
//console.log(targetURL)
let a = await fetch_GetList(targetURL);
//console.log("return: "+a);
updateCommandList();
}
fetch_GetList = (fetchURL) => response = fetch(fetchURL) fetch_GetList = (fetchURL) => response = fetch(fetchURL)
.then((response) => { .then((response) => {
return response.text(); return response.text();
@ -45,11 +59,11 @@ GetList = async (listType) => {
async function GetListCommands() { async function GetListCommands() {
let returnedList = await GetList("Commands"); let returnedList = await GetList("Commands");
let obj_main = JSON.parse(returnedList); let obj_main = JSON.parse(returnedList);
console.log(returnedList); //console.log(returnedList);
console.log(obj_main); //console.log(obj_main);
console.log(typeof obj_main['message']) //console.log(typeof obj_main['message'])
console.log(obj_main.message); //console.log(obj_main.message);
//var obj_temp = JSON.parse(obj_main.message['!lights']); //var obj_temp = JSON.parse(obj_main.message['!lights']);
let data = atob(obj_main.message); let data = atob(obj_main.message);
@ -59,8 +73,29 @@ async function GetListCommands() {
return notDictionary return notDictionary
} }
function updateCommandList() { async function updateCommandList() {
let returnedCommands = GetListCommands(); $("#CommandRowWrapper").empty();
let returnedCommands = await GetListCommands();
for (x in returnedCommands){
//console.log(x)
var commandName = returnedCommands[x].command
var isCommandEnabled = ""
if (returnedCommands[x].isCommandEnabled == "true") {
isCommandEnabled = "checked"
}
var commandTemplate = ""+
"<div class=\"rowsInMain row card\" style=\"margin-right: 20px;margin-left: 20px;margin-top: 30px;margin-bottom: 30px;\">" +
"<div class=\"col s12 switch\" style=\"top: -20px;position: relative;padding-left: 10px;\"><label>Enabled:<input "+ isCommandEnabled +" disabled type=\"checkbox\"><span class=\"lever\"></span></label></div>" +
"<div class=\"col s4\"><p>Command Name:</p>" +
"<div class=\"input-field inline\" style=\"width: 80%;\">" +
"<p style =\"color:grey;\">Command</p>" +
"<input disabled id=\"command_inline\" type=\"text\" value=\""+ commandName +"\" class=\"validate\">" +
"</div></div></div></div>"
$("#CommandRowWrapper").append(commandTemplate);
}
//var commandName = "!testerino"
//var isCommandEnabled = "" // if == "checked" will start off with the isEnabled bool enabled
} }
updateCommandList(); updateCommandList();