Skip to content

Commit

Permalink
[webui] add edit button to host slots
Browse files Browse the repository at this point in the history
  • Loading branch information
nwah authored and tschak909 committed Feb 15, 2025
1 parent 1d73914 commit 059888d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion data/webui/template/www/index.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ <h3 style="text-align: center;">Need help? Go to the <a href="https://github.com
<header class="module-header">HOSTS<span class="logowob"></span>LIST</header>
{% for hs in range(1, 9) %}
<div class="{{ loop.cycle('detline', 'detline alt') }}">
<div class="deth detlinecol">Host {{ hs }}</div>
<div class="deth detlinecol">
Host {{ hs }}
<a href="#" class="edit-host" data-hostslot="{{ hs }}" data-hostname="<%FN_HOST{{ hs }}%>">[EDIT]</a>
</div>
{% if tweaks.fujinet_pc %}
<div class="det detlinecol"><a href="/browse/host/{{ hs }}"><%FN_HOST{{ hs }}%> :: <%FN_HOST{{ hs }}PREFIX%></a></div>
{% else %}
Expand Down
27 changes: 27 additions & 0 deletions data/webui/template/www/js/settings.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -170,3 +196,4 @@ setInputValue(current_pclink == 1, "pclink-yes", "pclink-no");
{% endif %}

setupExperimentalToggle();
setupHostEditing();
1 change: 1 addition & 0 deletions lib/device/sio/fuji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down

0 comments on commit 059888d

Please sign in to comment.