editing normal nodetText
This commit is contained in:
@@ -40,6 +40,48 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||
padding: 10px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
#nodes-container {
|
||||
margin-top: 20px;
|
||||
border: 1px solid #ccc;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.node-item {
|
||||
border-bottom: 1px solid #eee;
|
||||
padding: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.modal {
|
||||
display: none; /* Hidden by default */
|
||||
position: fixed; /* Stay in place */
|
||||
z-index: 1; /* Sit on top */
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%; /* Full width */
|
||||
height: 100%; /* Full height */
|
||||
overflow: auto; /* Enable scroll if needed */
|
||||
background-color: rgb(0,0,0); /* Fallback color */
|
||||
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
|
||||
}
|
||||
.modal-content {
|
||||
background-color: #fefefe;
|
||||
margin: 15% auto; /* 15% from the top and centered */
|
||||
padding: 20px;
|
||||
border: 1px solid #888;
|
||||
width: 80%; /* Could be more or less, depending on screen size */
|
||||
}
|
||||
.close {
|
||||
color: #aaa;
|
||||
float: right;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.close:hover,
|
||||
.close:focus {
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -53,6 +95,37 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div id="nodes-container">
|
||||
<h2>Current Text Nodes</h2>
|
||||
<div id="nodes-list"></div>
|
||||
</div>
|
||||
|
||||
<div id="modify-modal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close" onclick="closeModal()">×</span>
|
||||
<h3>Modify Text Node</h3>
|
||||
<div class="text-input-group">
|
||||
<input type="hidden" id="modifyIdInput">
|
||||
<b>Node ID:</b> <span id="modifyIdDisplay"></span>
|
||||
</div>
|
||||
<div class="text-input-group">
|
||||
<input type="text" id="modifyTextInput" placeholder="New text...">
|
||||
<div class="param-explanation">New text for the node.</div>
|
||||
</div>
|
||||
<div class="text-input-group">
|
||||
<input type="color" id="modifyColorPicker">
|
||||
<div class="param-explanation">New color for the text.</div>
|
||||
</div>
|
||||
<div class="text-input-group">
|
||||
<input type="number" id="modifySlownessInput" placeholder="Slowness" min="0" max="255">
|
||||
<div class="param-explanation">Animation slowness (0-255).</div>
|
||||
</div>
|
||||
<div class="text-buttons">
|
||||
<button class="button" onclick="modifyText()">Save Changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-controls">
|
||||
<h3>Add Text Node (Full Control)</h3>
|
||||
<pre><code>void addNewTextNode(char text[TEXT_MAX_LENGTH + 1], uint32_t color, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0, unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true, short disappear_time = -1)</code></pre>
|
||||
@@ -172,6 +245,11 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||
}
|
||||
if(fontSize) data += "&fontSize=" + fontSize;
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
fetchNodes();
|
||||
}
|
||||
};
|
||||
xhr.send(data);
|
||||
}
|
||||
|
||||
@@ -202,8 +280,82 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||
if(y) data += "&y=" + y;
|
||||
if(fontSize) data += "&fontSize=" + fontSize;
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
fetchNodes();
|
||||
}
|
||||
};
|
||||
xhr.send(data);
|
||||
}
|
||||
|
||||
function modifyText() {
|
||||
const id = document.getElementById('modifyIdInput').value;
|
||||
const color = document.getElementById('modifyColorPicker').value;
|
||||
const text = document.getElementById('modifyTextInput').value;
|
||||
const slowness = document.getElementById('modifySlownessInput').value;
|
||||
|
||||
if (!id) {
|
||||
alert('Please enter a node ID.');
|
||||
return;
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/modify-text", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
||||
let data = "id=" + id + "&color=" + encodeURIComponent(color) + "&text=" + encodeURIComponent(text) + "&slowness=" + slowness;
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
fetchNodes();
|
||||
closeModal();
|
||||
}
|
||||
};
|
||||
xhr.send(data);
|
||||
}
|
||||
|
||||
function fetchNodes() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "/nodes", true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var nodes = JSON.parse(this.responseText);
|
||||
var nodesList = document.getElementById('nodes-list');
|
||||
nodesList.innerHTML = '';
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
var color = '#' + ('000000' + node.color.toString(16)).slice(-6);
|
||||
var nodeDiv = document.createElement('div');
|
||||
nodeDiv.className = 'node-item';
|
||||
nodeDiv.innerHTML = '<b>ID:</b> ' + node.id + ', <b>Text:</b> ' + node.text + ', <b>Color:</b> <span style="color:' + color + '">' + color + '</span>' +
|
||||
'<button style="margin-left: 10px;" onclick="populateModifyForm(' + node.id + ', \'' + color + '\', \'' + node.text + '\', ' + node.slowness + ')">Modify</button>';
|
||||
nodesList.appendChild(nodeDiv);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function populateModifyForm(id, color, text, slowness) {
|
||||
document.getElementById('modifyIdInput').value = id;
|
||||
document.getElementById('modifyIdDisplay').innerText = id;
|
||||
document.getElementById('modifyColorPicker').value = color;
|
||||
document.getElementById('modifyTextInput').value = text;
|
||||
document.getElementById('modifySlownessInput').value = slowness;
|
||||
document.getElementById('modify-modal').style.display = "block";
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
document.getElementById('modify-modal').style.display = "none";
|
||||
}
|
||||
|
||||
window.onclick = function(event) {
|
||||
if (event.target == document.getElementById('modify-modal')) {
|
||||
closeModal();
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(fetchNodes, 5000);
|
||||
window.onload = fetchNodes;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user