Skip to content

Commit

Permalink
Clean up of all calls to SendGetHttp url->cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
md8n committed Jan 22, 2025
1 parent 4aeb457 commit 786a025
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 57 deletions.
24 changes: 14 additions & 10 deletions www/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,23 @@ const Monitor_output_Update = (message) => {
};

function SendCustomCommand() {
let cmd = id("custom_cmd_txt").value;
const url = "/command?commandText=";
cmd = cmd.trim();
if (cmd.trim().length === 0) return;
CustomCommand_history.push(cmd);
let elem = id("custom_cmd_txt");
if (!elem) {
return;
}
let cmdTxt = elem.value.trim();
if (!cmdTxt) {
return;
}

CustomCommand_history.push(cmdTxt);
CustomCommand_history.slice(-40);
CustomCommand_history_index = CustomCommand_history.length;
id("custom_cmd_txt").value = "";
Monitor_output_Update(`${cmd}\n`);
cmd = encodeURI(cmd);
//because # is not encoded
cmd = cmd.replace("#", "%23");
SendGetHttp(url + cmd, SendCustomCommandSuccess, SendCustomCommandFailed);
Monitor_output_Update(`${cmdTxt}\n`);

const cmd = `/command?commandText=${encodeURI(cmd).replace("#", "%23")}`;
SendGetHttp( cmd, SendCustomCommandSuccess, SendCustomCommandFailed);
}

function CustomCommand_OnKeyUp(event) {
Expand Down
29 changes: 14 additions & 15 deletions www/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,24 @@ function config_display_override(display_it) {
}
}

function getprinterconfig(is_override) {
var cmd = commandtxt;
if ((typeof is_override != 'undefined') && is_override) {
cmd = "M503";
config_override_List = [];
is_override_config = true;
} else is_override_config = false;
var url = "/command?plain=" + encodeURIComponent(cmd);
SendGetHttp(url);
function getprinterconfig(is_override = false) {
is_override_config = is_override;
if (is_override) {
// Clear out the list
config_override_List.length = 0;
}
var cmd = `/command?plain=${encodeURIComponent(is_override ? "M503" : commandtx)}`;
SendGetHttp(cmd);
}

function Apply_config_override() {
var url = "/command?plain=" + encodeURIComponent("M500");
SendGetHttp(url, getESPUpdateconfigSuccess);
var cmd = `/command?plain=${encodeURIComponent("M500")}`;
SendGetHttp(cmd, getESPUpdateconfigSuccess);
}

function Delete_config_override() {
var url = "/command?plain=" + encodeURIComponent("M502");
SendGetHttp(url, getESPUpdateconfigSuccess);
var cmd = `/command?plain=${encodeURIComponent("M502")}`;
SendGetHttp(cmd, getESPUpdateconfigSuccess);
}

function getESPUpdateconfigSuccess(response) {
Expand Down Expand Up @@ -290,8 +289,8 @@ function configGetvalue(index, is_override) {
id('icon_config_' + prefix + index).className = "form-control-feedback has-success ico_feedback";
id('icon_config_' + prefix + index).innerHTML = get_icon_svg("ok");
id('status_config_' + prefix + index).className = "form-group has-feedback has-success";
var url = "/command?plain=" + encodeURIComponent(cmd);
SendGetHttp(url, setESPconfigSuccess, setESPconfigfailed);
var cmd = `/command?plain=${encodeURIComponent(cmd)}`;
SendGetHttp(cmd, setESPconfigSuccess, setESPconfigfailed);
}
}

Expand Down
4 changes: 2 additions & 2 deletions www/js/connectdlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ const retryconnect = () => {

id("connectbtn").removeEventListener("click", retryconnect);

const url = `/command?plain=${encodeURIComponent("[ESP800]")}`;
SendGetHttp(url, connectsuccess, connectfailed);
const cmd = `/command?plain=${encodeURIComponent("[ESP800]")}`;
SendGetHttp(cmd, connectsuccess, connectfailed);
};
2 changes: 1 addition & 1 deletion www/js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function ProcessGetHttp(cmd, resultfn, errorfn) {
}

if (cmd.startsWith("/command")) {
cmd += (url.indexOf("?") == -1) ? "?" : "&";
cmd += (cmd.indexOf("?") == -1) ? "?" : "&";
cmd += `PAGEID=${pageID()}`;
}
//console.log("GET:" + cmd);
Expand Down
13 changes: 6 additions & 7 deletions www/js/logindlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const logindlg = (closefunc, check_first = false) => {
displayBlock("login_content");

if (check_first) {
const url = "/login";
SendGetHttp(url, checkloginsuccess);
const cmd = "/login";
SendGetHttp(cmd, checkloginsuccess);
} else {
showModal();
}
Expand Down Expand Up @@ -86,13 +86,12 @@ function loginsuccess(response_text) {
function SubmitLogin() {
const user = id("login_user_text").value.trim();
const password = id("login_password_text").value.trim();
const url =
`/login?USER=${encodeURIComponent(user)}&PASSWORD=${encodeURIComponent(password)}&SUBMIT=yes`;
const cmd = `/login?USER=${encodeURIComponent(user)}&PASSWORD=${encodeURIComponent(password)}&SUBMIT=yes`;
setHTML("current_ID", user);
setHTML("current_auth_level", "");
displayNone("login_content");
displayBlock("login_loader");
SendGetHttp(url, loginsuccess, loginfailed);
SendGetHttp(cmd, loginsuccess, loginfailed);
}

function DisconnectionSuccess(response_text) {
Expand All @@ -114,7 +113,7 @@ function DisconnectionFailed(error_code, response) {

function DisconnectLogin(answer) {
if (answer === "yes") {
const url = "/login?DISCONNECT=yes";
SendGetHttp(url, DisconnectionSuccess, DisconnectionFailed);
const cmd = "/login?DISCONNECT=yes";
SendGetHttp(cmd, DisconnectionSuccess, DisconnectionFailed);
}
}
4 changes: 2 additions & 2 deletions www/js/passworddlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function SubmitChangePassword() {
const user = encodeURIComponent(id("current_ID").innerHTML.trim());
const password = encodeURIComponent(id("password_password_text").value.trim());
const newpassword = encodeURIComponent(id("password_password_text1").value.trim());
const url = `/login?USER=${user}&PASSWORD=${password}&NEWPASSWORD=${newpassword}&SUBMIT=yes`;
const cmd = `/login?USER=${user}&PASSWORD=${password}&NEWPASSWORD=${newpassword}&SUBMIT=yes`;
displayBlock("password_loader");
displayNone("change_password_content");
SendGetHttp(url, ChangePasswordsuccess, ChangePasswordfailed);
SendGetHttp(cmd, ChangePasswordsuccess, ChangePasswordfailed);
}
4 changes: 2 additions & 2 deletions www/js/preferencesdlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function initpreferences() {
}

function getpreferenceslist() {
var url = preferences_file_name;
var cmd = preferences_file_name;
preferenceslist = [];
//removeIf(production)
var response = defaultpreferenceslist;
processPreferencesGetSuccess(response);
return;
//endRemoveIf(production)
SendGetHttp(url, processPreferencesGetSuccess, processPreferencesGetFailed);
SendGetHttp(cmd, processPreferencesGetSuccess, processPreferencesGetFailed);
}

function prefs_toggledisplay(id_source, forcevalue) {
Expand Down
21 changes: 12 additions & 9 deletions www/js/printercmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ var grbl_errorfn = null;

function noop() {}
function SendPrinterCommand(cmd, echo_on, processfn, errorfn, id, max_id, extra_arg) {
var url = "/command?commandText=";
var cmdTxt = "/command?commandText=";
var push_cmd = true;
if (typeof echo_on !== 'undefined') {
push_cmd = echo_on;
}
if (cmd.length == 0) return;
if (push_cmd) Monitor_output_Update("[#]" + cmd + "\n");
if (push_cmd) {
Monitor_output_Update("[#]" + cmd + "\n");
}
//removeIf(production)
console.log(cmd);
if (typeof processfn !== 'undefined') processfn("Test response");
Expand All @@ -24,20 +26,20 @@ function SendPrinterCommand(cmd, echo_on, processfn, errorfn, id, max_id, extra_
processfn = noop;
errorfn = noop;
}
cmd = encodeURI(cmd);
cmd = cmd.replace("#", "%23");
cmd = encodeURI(cmd).replace("#", "%23");
if (extra_arg) {
cmd += "&" + extra_arg;
}
SendGetHttp(url + cmd, processfn, errorfn, id, max_id);
SendGetHttp(cmdTxt + cmd, processfn, errorfn, id, max_id);
//console.log(cmd);
}

function SendPrinterSilentCommand(cmd, processfn, errorfn, id, max_id) {
var url = "/command_silent?commandText=";
if (cmd.length == 0) return;
if (!cmd) {
return;
}
//removeIf(production)
console.log(cmd);
console.info(cmd);
if (typeof processfn !== 'undefined') processfn("Test response");
else SendPrinterCommandSuccess("Test response");
return;
Expand All @@ -46,7 +48,8 @@ function SendPrinterSilentCommand(cmd, processfn, errorfn, id, max_id) {
if (typeof errorfn === 'undefined' || errorfn == null) errorfn = SendPrinterCommandFailed;
cmd = encodeURI(cmd);
cmd = cmd.replace("#", "%23");
SendGetHttp(url + cmd, processfn, errorfn, id, max_id);
var cmdTxt = `/command_silent?commandText=${cmd}`;
SendGetHttp(cmdTxt, processfn, errorfn, id, max_id);
//console.log(cmd);
}

Expand Down
4 changes: 2 additions & 2 deletions www/js/scanwifidlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function refresh_scanwifi() {
getscanWifiSuccess(testResponse.join(""));
return;
//endRemoveIf(production)
const url = `/command?plain=${encodeURIComponent("[ESP410]")}`;
SendGetHttp(url, getscanWifiSuccess, getscanWififailed);
const cmd = `/command?plain=${encodeURIComponent("[ESP410]")}`;
SendGetHttp(cmd, getscanWifiSuccess, getscanWififailed);
}

function process_scanWifi_answer(response_text) {
Expand Down
8 changes: 4 additions & 4 deletions www/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function refreshSettings(hide_setting_list) {
displayNone('settings_refresh_btn')

scl = []
var url = '/command?plain=' + encodeURIComponent('[ESP400]')
SendGetHttp(url, getESPsettingsSuccess, getESPsettingsfailed)
var cmd = '/command?plain=' + encodeURIComponent('[ESP400]')
SendGetHttp(cmd, getESPsettingsSuccess, getESPsettingsfailed)
}

function defval(i) {
Expand Down Expand Up @@ -467,8 +467,8 @@ function settingsetvalue(i, j) {
setIcon(i, j, 'has-success ico_feedback')
setIconHTML(i, j, get_icon_svg('ok'))
setStatus(i, j, 'has-feedback has-success')
var url = '/command?plain=' + encodeURIComponent(cmd)
SendGetHttp(url, setESPsettingsSuccess, setESPsettingsfailed)
var cmdTxt = '/command?plain=' + encodeURIComponent(cmd)
SendGetHttp(cmdTxt, setESPsettingsSuccess, setESPsettingsfailed)
}
}

Expand Down
4 changes: 2 additions & 2 deletions www/js/statusdlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ function refreshstatus() {
const text = modal.element.getElementsByClassName("modal-text")[0];
text.innerHTML = "";
displayNone("status_msg");
const url = `/command?plain=${encodeURIComponent("[ESP420]plain")}`;
SendGetHttp(url, statussuccess, statusfailed);
const cmd = `/command?plain=${encodeURIComponent("[ESP420]plain")}`;
SendGetHttp(cmd, statussuccess, statusfailed);
}
2 changes: 1 addition & 1 deletion www/js/tablet.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function scaleUnits(target) {

function tabletUpdateModal() {
const newUnits = modal.units === 'G21' ? 'mm' : 'Inch'
if (getText('units') !== newUnits) {
if (getValue('units') !== newUnits) {
setText('units', newUnits)
setJogSelector(modal.units)
scaleUnits("disM")
Expand Down

0 comments on commit 786a025

Please sign in to comment.