Skip to content

Commit d6eaaaf

Browse files
committed
Basic JS
1 parent 9648283 commit d6eaaaf

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ static void _reply_directory_html(socketpool_socket_obj_t *socket, FF_DIR *dir,
442442
socketpool_socket_send(socket, (const uint8_t *)ok_response, strlen(ok_response));
443443
_send_chunk(socket, "<!DOCTYPE html><html><head><title>");
444444
_send_chunk(socket, path);
445-
_send_chunk(socket, "</title><meta charset=\"UTF-8\"></head><body><h1>");
445+
_send_chunk(socket, "</title><meta charset=\"UTF-8\"></head>");
446+
_send_chunk(socket, "<script src=\"http://127.0.0.1:8000/circuitpython.js\" defer=true></script>");
447+
_send_chunk(socket, "<body><h1>");
446448
_send_chunk(socket, path);
447449
_send_chunk(socket, "</h1><pre>");
448450
if (strlen(path) > 1) {
@@ -468,18 +470,15 @@ static void _reply_directory_html(socketpool_socket_obj_t *socket, FF_DIR *dir,
468470
// entry->file_size = file_info.fsize;
469471
// }
470472
// _send_chunk(socket, "<li>");
471-
bool editable = false;
472473
if ((file_info.fattrib & AM_DIR) != 0) {
473474
_send_chunk(socket, "🗀\t");
474475
} else if (_endswith(file_info.fname, ".txt") ||
475476
_endswith(file_info.fname, ".py") ||
476477
_endswith(file_info.fname, ".js") ||
477478
_endswith(file_info.fname, ".json")) {
478479
_send_chunk(socket, "🖹\t");
479-
editable = true;
480480
} else if (_endswith(file_info.fname, ".html")) {
481481
_send_chunk(socket, "🌐\t");
482-
editable = true;
483482
} else {
484483
_send_chunk(socket, "⬇\t");
485484
}
@@ -494,13 +493,15 @@ static void _reply_directory_html(socketpool_socket_obj_t *socket, FF_DIR *dir,
494493

495494
_send_chunk(socket, file_info.fname);
496495
_send_chunk(socket, "</a>");
497-
if (editable) {
498-
_send_chunk(socket, "<a>✏️</a>");
499-
}
500-
_send_chunk(socket, "<a>🗑️</a><br/>");
496+
_send_chunk(socket, "<button value=\"");
497+
_send_chunk(socket, file_info.fname);
498+
_send_chunk(socket, "\" class=\"delete\">🗑️</button><br/>");
501499
res = f_readdir(dir, &file_info);
502500
}
503-
_send_chunk(socket, "</pre>Upload:<input type=\"file\" multiple></body></html>");
501+
_send_chunk(socket, "</pre><hr><input type=\"file\" id=\"files\" multiple><button type=\"submit\" id=\"upload\">Upload</button>");
502+
503+
_send_chunk(socket, "<hr>+🗀<input type=\"text\" id=\"name\"><button type=\"submit\" id=\"mkdir\">Create Directory</button>");
504+
_send_chunk(socket, "</body></html>");
504505
_send_chunk(socket, "");
505506
}
506507

tools/circuitpython.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
console.log("Hello world");
2+
3+
function mkdir(e) {
4+
console.log("mkdir");
5+
console.log(e);
6+
}
7+
8+
function upload(e) {
9+
console.log("upload");
10+
console.log(e);
11+
}
12+
13+
function del(e) {
14+
console.log("delete");
15+
console.log(e);
16+
if (confirm("Delete" + e.target.value + "?")) {
17+
console.log("do it");
18+
}
19+
}
20+
21+
document.getElementById("mkdir").onclick = mkdir;
22+
document.getElementById("upload").onclick = upload;
23+
24+
const collection = document.getElementsByClassName("delete");
25+
for (let i = 0; i < collection.length; i++) {
26+
collection[i].onclick = del;
27+
}

0 commit comments

Comments
 (0)