Skip to content

Commit

Permalink
improve: UX for filename and delete logs
Browse files Browse the repository at this point in the history
  • Loading branch information
luftaquila committed Oct 21, 2024
1 parent fb4fbf9 commit a6ecafa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
31 changes: 27 additions & 4 deletions viewer/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ <h2><i class="fa fw fa-file-import"></i>File Management</h2>
<span id="export-json" class="btn small blue disabled"><i class="fas fw fa-file-code"></i>Export JSON</span>
<span id="export-csv" class="btn small blue disabled"><i class="fas fw fa-file-csv"></i>Export CSV</span>
</div>

<div style="font-size: 0.8rem;">
<i class="fas fa-fw fa-info-circle"></i> The timestamp at the beginning of the record's filename is important. Do NOT change it.
</div>
</article>

<article>
Expand Down Expand Up @@ -88,7 +92,8 @@ <h2><i class="fa fw fa-chart-line"></i>Graph Viewer</h2>
</div>

<div style="text-align: center;">
<span id="export-image" class="btn purple small disabled"><i class="fas fw fa-file-image"></i>Export Graph Image</span>
<span id="export-image" class="btn purple small disabled"><i class="fas fw fa-file-image"></i>Export Graph
Image</span>
</div>
</article>
</div>
Expand All @@ -109,11 +114,29 @@ <h2><i class="fa fw fa-microchip"></i>Device</h2>
</article>

<article>
<h2><i class="fa fw fa-tower-broadcast"></i>Command</h2>
<h2><i class="fa fw fa-clock"></i>Clock synchronization</h2>

<div style="font-size: 0.8rem;">
<i class="fas fa-fw fa-info-circle"></i> Set the device clock to match the current time of the host PC.
</div>

<div style="display: flex; gap: 1rem;">
<span id="cmd-rtc" class="btn small green disabled"><i class="fas fw fa-arrows-rotate"></i>Sync RTC</span>
</div>
</article>

<article>
<h2><i class="fa fw fa-eraser"></i>Delete records</h2>

<div style="font-size: 0.8rem; line-height: 1.2rem;">
<i class="fas fa-fw fa-info-circle"></i> Delete all log files stored in the device storage.<br>
<i class="fas fa-fw fa-info-circle" style="color: transparent;"></i> Disconnect and re-connect the device to see the changes.<br>
<i class="fas fa-fw fa-triangle-exclamation" style="color: orange"></i> This operation cannot be undone.
</div>

<div style="display: flex; gap: 1rem;">
<span id="cmd-rtc" class="btn small green disabled"><i class="fas fw fa-clock"></i>Sync Clock</span>
<span id="cmd-del" class="btn small red disabled"><i class="fas fw fa-trash"></i>Delete All Logs</span>
<span id="cmd-del" class="btn small red disabled"><i class="fas fw fa-trash"></i>Delete</span>
<span id="cmd-del-unlock" class="btn small purple disabled"><i class="fas fw fa-lock"></i>Unlock</span>
</div>
</article>
</div>
Expand Down
24 changes: 23 additions & 1 deletion viewer/web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function setup() {
ext = file.name.split('.').pop();
filename = file.name.replace(`.${ext}`, '');

if (!/^\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}/.test(filename)) {
return notyf.error("*.log file should contain the timestamp in the filename");
}

document.getElementById("file-selected").innerText = "Processing data...";

switch (ext) {
Expand Down Expand Up @@ -133,6 +137,8 @@ function setup() {
document.getElementById("connect").classList.add('orange');
document.getElementById("cmd-rtc").classList.add('disabled');
document.getElementById("cmd-del").classList.add('disabled');
document.getElementById("cmd-del-unlock").classList.add('disabled');
document.getElementById("cmd-del-unlock").innerHTML = `<i class="fas fw fa-lock"></i>Unlock`;

notyf.error("Device disconnected");
});
Expand All @@ -158,7 +164,7 @@ function setup() {
document.getElementById("connect").classList.remove('orange');
document.getElementById("connect").classList.add('green', 'disabled');
document.getElementById("cmd-rtc").classList.remove('disabled');
document.getElementById("cmd-del").classList.remove('disabled');
document.getElementById("cmd-del-unlock").classList.remove('disabled');

notyf.success("Device connected");
});
Expand Down Expand Up @@ -193,6 +199,22 @@ function setup() {
notyf.success("Device RTC synchronized");
});

document.getElementById("cmd-del-unlock").addEventListener("click", e => {
switch (e.target.innerText) {
case "Unlock": {
document.getElementById("cmd-del").classList.remove('disabled');
document.getElementById("cmd-del-unlock").innerHTML = `<i class="fas fw fa-lock-open"></i>Lock`;
break;
}

case "Lock": {
document.getElementById("cmd-del").classList.add('disabled');
document.getElementById("cmd-del-unlock").innerHTML = `<i class="fas fw fa-lock"></i>Unlock`;
break;
}
}
});

document.getElementById("cmd-del").addEventListener("click", async e => {
let res = await transceive(new Uint8Array([USB_CMD_MAGIC, USB_CMD.indexOf("USB_CMD_DEL"), ...new Array(6).fill(0)]), LEN_DEVICE_RES);

Expand Down

0 comments on commit a6ecafa

Please sign in to comment.