Skip to content

Commit

Permalink
feat(www): expose storage toggle in web UI
Browse files Browse the repository at this point in the history
This patch adds a new icon to the web UI to switch the storage between
the target and the host. This is mostly useful to switch between booting
from a mtda managed storage and a local storage.

Signed-off-by: Felix Moessbauer <[email protected]>
  • Loading branch information
fmoessbauer authored and chombourger committed Dec 19, 2023
1 parent a2f0a25 commit 8d571b4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mtda/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<div class="title" id="mtda_title">MTDA</div>
<ul class="nav">
<li><a href="#" id=power-toggle><i id=power-status-icon class="large material-icons">power</i></a></li>
<li><a href="#" id=storage-toggle><i id=storage-status-icon class="large material-icons">no_sim</i></a></li>
<li><a href="#" id=keyboard-show><i class="large material-icons">keyboard</i></a></li>
<li id="mtda_status">Connecting...</li>
<li id="vnc_status">Loading Video</li>
Expand All @@ -103,6 +104,15 @@
return false;
});
});
$(function() {
$('a#storage-toggle').bind('click', function() {
document.getElementById("storage-status-icon").innerHTML = "downloading"
$.getJSON('./storage-toggle', function(data) {
// do nothing
});
return false;
});
});
$(function() {
$('a#keyboard-show').bind('click', function() {
Keyboard.open('', function(data) {
Expand Down Expand Up @@ -135,6 +145,7 @@
const version = document.getElementById("mtda_version");
const video = document.getElementById("video");
const power_status = document.getElementById("power-status-icon")
const storage_status = document.getElementById("storage-status-icon")

socket.on("console-output", function (data) {
term.write(data.output);
Expand Down Expand Up @@ -175,6 +186,22 @@
default: power_status.innerHTML = "help"
}
});

socket.on("storage-event", (data) => {
switch(data.event) {
case 'HOST':
storage_status.innerHTML = "save";
storage_status.title = "switch storage to target"
break;
case 'TARGET':
storage_status.innerHTML = "eject";
storage_status.title = "switch storage to host"
break;
default:
storage_status.innerHTML = "unknown_document"
storage_status.title = "storage status unknown"
}
});
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions mtda/www.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def connect():
data = mtda.console_dump()
socket.emit("console-output", {"output": data}, namespace="/mtda")

status, _, _ = mtda.storage_status(session_id())
socket.emit("storage-event", {"event": status}, namespace="/mtda")

if mtda.video is not None:
fmt = mtda.video.format
url = urlparse(request.base_url)
Expand Down Expand Up @@ -111,6 +114,20 @@ def power_toggle():
return ''


@app.route('/storage-toggle')
def storage_toggle():
sid = session_id()
mtda = app.config['mtda']
if mtda is not None:
status, _, _ = mtda.storage_status(session=sid)
if status == CONSTS.STORAGE.ON_HOST:
return 'TARGET' if mtda.storage_to_target(session=sid) else 'HOST'
elif status == CONSTS.STORAGE.ON_TARGET:
return 'HOST' if mtda.storage_to_host(session=sid) else 'TARGET'
return status
return ''


def session_id():
sid = None
if 'id' in session:
Expand Down

0 comments on commit 8d571b4

Please sign in to comment.