From 059888dc1af43c3b2a7359b9e0394fe93c92eb90 Mon Sep 17 00:00:00 2001 From: Noah Burney Date: Fri, 14 Feb 2025 19:08:08 -0600 Subject: [PATCH] [webui] add edit button to host slots --- data/webui/template/www/index.tmpl.html | 5 +++- data/webui/template/www/js/settings.tmpl.js | 27 +++++++++++++++++++++ lib/device/sio/fuji.cpp | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/data/webui/template/www/index.tmpl.html b/data/webui/template/www/index.tmpl.html index b8772770d..092df984a 100644 --- a/data/webui/template/www/index.tmpl.html +++ b/data/webui/template/www/index.tmpl.html @@ -281,7 +281,10 @@

Need help? Go to the HOSTSLIST {% for hs in range(1, 9) %}
-
Host {{ hs }}
+
{% if tweaks.fujinet_pc %} {% else %} diff --git a/data/webui/template/www/js/settings.tmpl.js b/data/webui/template/www/js/settings.tmpl.js index 9a8c0d738..83b49acb8 100644 --- a/data/webui/template/www/js/settings.tmpl.js +++ b/data/webui/template/www/js/settings.tmpl.js @@ -14,6 +14,32 @@ function toggleExperimental(evt) { localStorage.setItem('fujinet.experimental', evt.target.checked); } +function setupHostEditing() { + const editLinks = document.querySelectorAll('a.edit-host'); + editLinks.forEach(link => { + link.addEventListener('click', e => { + e.preventDefault(); + const hs = Number(link.dataset.hostslot) - 1; + const currentHostname = link.dataset.hostname; + + const updatedHostname = prompt(`Enter hostname for slot ${hs + 1}`, currentHostname); + + // Abort on [Cancel] + if (updatedHostname === null) { + return; + } + + fetch(`/hosts?hostslot=${hs}&hostname=${updatedHostname}`, { method: 'POST' }) + .then(() => { + location.reload(); + }) + .catch(e => { + alert("Error: Could not update host"); + }); + }); + }); +} + function changeTz() { const selElement = document.getElementById("select_tz"); const setElement = document.getElementById("txt_timezone") @@ -170,3 +196,4 @@ setInputValue(current_pclink == 1, "pclink-yes", "pclink-no"); {% endif %} setupExperimentalToggle(); +setupHostEditing(); diff --git a/lib/device/sio/fuji.cpp b/lib/device/sio/fuji.cpp index 5d27ef623..4a9213504 100644 --- a/lib/device/sio/fuji.cpp +++ b/lib/device/sio/fuji.cpp @@ -2781,6 +2781,7 @@ std::string sioFuji::get_host_prefix(int host_slot) fujiHost *sioFuji::set_slot_hostname(int host_slot, char *hostname) { _fnHosts[host_slot].set_hostname(hostname); + _populate_config_from_slots(); return &_fnHosts[host_slot]; }