Skip to content

Commit 4147228

Browse files
committed
feat: dashboard can send notes to server log
1 parent 3ff9c76 commit 4147228

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

src/dashboard/public/dashboard.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ <h2>Bangle.js watch list</h2>
145145
<!-- </div> -->
146146
<!-- <div class="ui-grid info"><h3>Details</h3></div> -->
147147
<!-- <div class="ui-grid commands"><h2>Commands</h2></div> -->
148+
<div class="ui-grid ui-center server-notes" id="serverNotes"></div>
148149
<div class="ui-grid ui-center footer">BEATLab 2024</div>
149150
</div>
150151
<script type="module" src="/javascripts/client.js"></script>

src/dashboard/public/stylesheets/layout.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ h3 {
4545
"leftSide watchList na"
4646
"leftSide watchList na"
4747
/*"leftSide commands na"*/
48+
"leftSide server-notes na"
4849
"footer footer footer";
4950
& > * {
5051
border-left: 2px solid rgba(0, 0, 0, 0);
@@ -56,6 +57,10 @@ h3 {
5657
/*}*/
5758
}
5859

60+
.server-notes {
61+
grid-area: server-notes;
62+
}
63+
5964
.footer {
6065
grid-area: footer;
6166
}

src/dashboard/src/app/server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ io.on("connection", (socket: Socket) => {
121121
logger.log("info", `Client Info: ${msg}`);
122122
});
123123

124+
socket.on("btn-note", (note): void => {
125+
logger.log("info", `SERVER NOTE: {"Performance": ${JSON.stringify(note)}}`);
126+
});
127+
124128
socket.on("ui-btn", (msg): void => {
125129
logger.log("info", `Client UI: ${msg}`);
126130
});
@@ -129,7 +133,8 @@ io.on("connection", (socket: Socket) => {
129133
// Handle button presses sent from client
130134
logger.log(
131135
"info",
132-
`Button click: '${data.cmd}' on device: '${data.device}' [msg: '${data.msg}']`,
136+
`SERVER NOTE: {"Command": ${JSON.stringify(data)}}`,
137+
// `Button click: '${data.cmd}' on device: '${data.device}' [msg: '${data.msg}']`,
133138
);
134139
if (data.device == "all") {
135140
// Send command to all watches

src/dashboard/src/public/javascripts/client.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,79 @@ let ctlButtons = {
354354
sendCommand: "Send Cmd: ",
355355
};
356356

357+
function addServerNotes(id: string) {
358+
let selElement = document.getElementById(id)!;
359+
const form = document.createElement("form");
360+
form.id = "myForm";
361+
362+
const textLabel = document.createElement("label");
363+
textLabel.setAttribute("for", "textInput");
364+
textLabel.textContent = "Enter note:";
365+
366+
const textInput = document.createElement("input");
367+
textInput.type = "text";
368+
textInput.id = "textInput";
369+
textInput.name = "textInput";
370+
textInput.required = true;
371+
372+
const optionLabel = document.createElement("label");
373+
optionLabel.textContent = "Section:";
374+
375+
const option1 = document.createElement("input");
376+
option1.type = "radio";
377+
option1.id = "option1";
378+
option1.name = "options";
379+
option1.value = "Start";
380+
option1.required = true;
381+
382+
const option1Label = document.createElement("label");
383+
option1Label.setAttribute("for", "option1");
384+
option1Label.textContent = "Start";
385+
386+
const option2 = document.createElement("input");
387+
option2.type = "radio";
388+
option2.id = "option2";
389+
option2.name = "options";
390+
option2.value = "End";
391+
392+
const option2Label = document.createElement("label");
393+
option2Label.setAttribute("for", "option2");
394+
option2Label.textContent = "End";
395+
396+
const submitButton = document.createElement("button");
397+
submitButton.type = "submit";
398+
submitButton.textContent = "Create Note";
399+
400+
form.appendChild(textLabel);
401+
form.appendChild(textInput);
402+
form.appendChild(optionLabel);
403+
form.appendChild(option1);
404+
form.appendChild(option1Label);
405+
form.appendChild(option2);
406+
form.appendChild(option2Label);
407+
form.appendChild(submitButton);
408+
409+
selElement.appendChild(form);
410+
411+
form.addEventListener("submit", function (event) {
412+
event.preventDefault();
413+
const textInputValue = textInput.value;
414+
const selectedOption = document.querySelector(
415+
'input[name="options"]:checked',
416+
)?.value;
417+
418+
if (selectedOption) {
419+
let note = { text: textInputValue, section: selectedOption };
420+
console.log("Sending note:", JSON.stringify(note));
421+
socket.emit("btn-note", note);
422+
} else {
423+
alert("Please select an option");
424+
}
425+
});
426+
}
427+
357428
addButtons("main-controls", ctlButtons, "all");
429+
addServerNotes("serverNotes");
358430

359431
// TODO: collapsible
360432
// TODO: explain symbols/offsets/...

0 commit comments

Comments
 (0)