test client: update to reflect config file refactoring

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-08-05 06:25:34 -04:00
parent d572a13655
commit 72bba79830
2 changed files with 16 additions and 82 deletions

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="/js/main.js?v=0.1.17" type="module"></script> <script src="/js/main.js?v=0.1.18" type="module"></script>
</head> </head>
<body> <body>
<h3>Klippy Web API Test</h3> <h3>Klippy Web API Test</h3>
@ -56,14 +56,13 @@
</div> </div>
<div id=filetype> <div id=filetype>
<input type="radio" name="file_type" value="gcodes" checked="true">GCodes<br/> <input type="radio" name="file_type" value="gcodes" checked="true">GCodes<br/>
<input type="radio" name="file_type" value="config">Config Files <input type="radio" name="file_type" value="config">Config Files<br/>
<input type="radio" name="file_type" value="config_examples">Config Examples
</div> </div>
</div> </div>
<br/> <br/>
Progress: <progress id="progressbar" value="0" max="100"></progress> Progress: <progress id="progressbar" value="0" max="100"></progress>
<span id="upload_progress">0%</span><br/><br/> <span id="upload_progress">0%</span><br/><br/>
<button id="btnwritecfg" class="toggleable" style="width: 12em">Upload printer.cfg</button>
<button id="btngetcfg" class="toggleable" style="width: 12em">Download printer.cfg</button><br/><br/>
<button id="btnqueryendstops" style="width: 9em">Query Endstops</button> <button id="btnqueryendstops" style="width: 9em">Query Endstops</button>
<button id="btnsubscribe" style="width: 9em">Post Subscription</button> <button id="btnsubscribe" style="width: 9em">Post Subscription</button>
<button id="btngetsub" style="width: 9em">Get Subscription</button> <button id="btngetsub" style="width: 9em">Get Subscription</button>

View File

@ -96,11 +96,11 @@ var api = {
moonraker_log: { moonraker_log: {
url: "/server/files/moonraker.log" url: "/server/files/moonraker.log"
}, },
printer_cfg: { cfg_files: {
url: "/server/files/config/printer.cfg" url: "/server/files/config/"
}, },
included_cfg_files: { cfg_examples: {
url: "/server/files/config/include/" url: "/server/files/config_examples/"
}, },
// Machine APIs // Machine APIs
@ -128,7 +128,6 @@ var paused = false;
var klippy_ready = false; var klippy_ready = false;
var api_type = 'http'; var api_type = 'http';
var is_printing = false; var is_printing = false;
var upload_location = "gcodes"
var file_list_type = "gcodes"; var file_list_type = "gcodes";
var json_rpc = new JsonRPC(); var json_rpc = new JsonRPC();
@ -196,19 +195,6 @@ function update_filelist(filelist) {
} }
} }
function update_configlist(cfglist) {
$("#filelist").empty();
// Add base printer.cfg
$("#filelist").append(
"<option value='printer.cfg'>printer.cfg</option>");
for (let file of cfglist) {
let fname = "include/" + file.filename;
$("#filelist").append(
"<option value='" + fname + "'>" +
fname + "</option>");
}
}
var last_progress = 0; var last_progress = 0;
function update_progress(loaded, total) { function update_progress(loaded, total) {
let progress = parseInt(loaded / total * 100); let progress = parseInt(loaded / total * 100);
@ -241,10 +227,7 @@ function get_file_list() {
.then((result) => { .then((result) => {
// result is an "ok" acknowledgment that the gcode has // result is an "ok" acknowledgment that the gcode has
// been successfully processed // been successfully processed
if (file_list_type == "config") update_filelist(result);
update_configlist(result);
else
update_filelist(result);
}) })
.catch((error) => { .catch((error) => {
update_error(api.file_list.method, error); update_error(api.file_list.method, error);
@ -934,7 +917,6 @@ window.onload = () => {
// Hidden file element's click is forwarded to the button // Hidden file element's click is forwarded to the button
$('#btnupload').click(() => { $('#btnupload').click(() => {
if (api_type == "http") { if (api_type == "http") {
upload_location = file_list_type;
$('#upload-file').click(); $('#upload-file').click();
} else { } else {
console.log("File Upload not supported over websocket") console.log("File Upload not supported over websocket")
@ -956,13 +938,7 @@ window.onload = () => {
if (api_type == 'http') { if (api_type == 'http') {
let fdata = new FormData(); let fdata = new FormData();
fdata.append("file", file); fdata.append("file", file);
if (upload_location.startsWith("config")) { fdata.append("root", file_list_type);
fdata.append("root", "config");
if (upload_location == "config_main")
fdata.append("primary_config", "true");
} else {
fdata.append("root", upload_location);
}
let settings = { let settings = {
url: api.upload.url, url: api.upload.url,
data: fdata, data: fdata,
@ -1003,16 +979,9 @@ window.onload = () => {
if (api_type == 'http') { if (api_type == 'http') {
let url = api.gcode_files.url + filename; let url = api.gcode_files.url + filename;
if (file_list_type == "config") { if (file_list_type == "config") {
url = api.included_cfg_files.url + filename; url = api.cfg_files.url + filename;
if (filename.startsWith("include/")) { } else if (file_list_type == "config_examples") {
url = api.included_cfg_files.url + filename.slice(8); url = api.cfg_examples.url + filename;
} else if (filename == "printer.cfg") {
url = api.printer_cfg.url;
}
else {
console.log("Cannot download file: " + filename);
return false;
}
} }
let dl_url = "http://" + location.host + url; let dl_url = "http://" + location.host + url;
if (apikey != null) { if (apikey != null) {
@ -1043,13 +1012,10 @@ window.onload = () => {
if (api_type == 'http') { if (api_type == 'http') {
let url = api.gcode_files.url + filename; let url = api.gcode_files.url + filename;
if (file_list_type == "config") { if (file_list_type == "config") {
url = api.included_cfg_files.url + filename; url = api.cfg_files.url + filename;
if (filename.startsWith("include/")) { } else if (file_list_type != "gcodes") {
url = api.included_cfg_files.url + filename.slice(8); console.log("Cannot delete file");
} else { return false;
console.log("Cannot Delete printer.cfg");
return false;
}
} }
let settings = { let settings = {
url: url, url: url,
@ -1158,37 +1124,6 @@ window.onload = () => {
} }
}); });
$('#btnwritecfg').click(() => {
if (api_type == "http") {
upload_location = "config_main";
$('#upload-file').click();
} else {
console.log("File Upload not supported over websocket")
}
});
$('#btngetcfg').click(() => {
if (api_type == 'http') {
let dl_url = "http://" + location.host + api.printer_cfg.url;
if (apikey != null) {
let settings = {
url: api.oneshot_token.url,
headers: {"X-Api-Key": apikey}
};
$.get(settings, (resp, status) => {
let token = resp.result;
dl_url += "?token=" + token;
do_download(dl_url);
return false;
});
} else {
do_download(dl_url);
}
} else {
console.log("Get Log not supported over websocket")
}
});
$('#btnqueryendstops').click(() => { $('#btnqueryendstops').click(() => {
if (api_type == 'http') { if (api_type == 'http') {
let settings = {url: api.query_endstops.url}; let settings = {url: api.query_endstops.url};