Prettified Code!

This commit is contained in:
DJ2LS 2023-02-12 14:44:38 +00:00 committed by GitHub Action
parent 3a36baabac
commit 6683d0a1a7
3 changed files with 153 additions and 182 deletions

View file

@ -43,7 +43,8 @@ if (!fs.existsSync(configFolder)) {
} }
// create config file if not exists with defaults // create config file if not exists with defaults
const configDefaultSettings = '{\ const configDefaultSettings =
'{\
"tnc_host": "127.0.0.1",\ "tnc_host": "127.0.0.1",\
"tnc_port": "3000",\ "tnc_port": "3000",\
"daemon_host": "127.0.0.1",\ "daemon_host": "127.0.0.1",\

View file

@ -42,24 +42,22 @@ const contrib = [
]; ];
//let elements = document.querySelectorAll('[id^="hamlib_"]'); // get all elements starting with... //let elements = document.querySelectorAll('[id^="hamlib_"]'); // get all elements starting with...
const hamlib_elements = ["hamlib_deviceid", const hamlib_elements = [
"hamlib_deviceport", "hamlib_deviceid",
"hamlib_stop_bits", "hamlib_deviceport",
"hamlib_data_bits", "hamlib_stop_bits",
"hamlib_handshake", "hamlib_data_bits",
"hamlib_serialspeed", "hamlib_handshake",
"hamlib_dtrstate", "hamlib_serialspeed",
"hamlib_pttprotocol", "hamlib_dtrstate",
"hamlib_ptt_port", "hamlib_pttprotocol",
"hamlib_dcd", "hamlib_ptt_port",
"hamlib_rigctld_port", "hamlib_dcd",
"hamlib_rigctld_ip", "hamlib_rigctld_port",
"hamlib_rigctld_path", "hamlib_rigctld_ip",
"hamlib_rigctld_server_port" "hamlib_rigctld_path",
] "hamlib_rigctld_server_port",
];
// SET dbfs LEVEL GLOBAL // SET dbfs LEVEL GLOBAL
// this is an attempt of reducing CPU LOAD // this is an attempt of reducing CPU LOAD
@ -203,8 +201,6 @@ window.addEventListener("DOMContentLoaded", () => {
// load settings by function // load settings by function
loadSettings(hamlib_elements); loadSettings(hamlib_elements);
document.getElementById("tnc_adress").value = config.tnc_host; document.getElementById("tnc_adress").value = config.tnc_host;
document.getElementById("tnc_port").value = config.tnc_port; document.getElementById("tnc_port").value = config.tnc_port;
@ -219,10 +215,6 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("myCallSSID").value = ssid; document.getElementById("myCallSSID").value = ssid;
document.getElementById("myGrid").value = config.mygrid; document.getElementById("myGrid").value = config.mygrid;
// hamlib settings // hamlib settings
document.getElementById("hamlib_deviceid").value = config.hamlib_deviceid; document.getElementById("hamlib_deviceid").value = config.hamlib_deviceid;
@ -386,32 +378,27 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("radio-control-switch-rigctld").checked = true; document.getElementById("radio-control-switch-rigctld").checked = true;
document.getElementById("radio-control-switch-help").checked = false; document.getElementById("radio-control-switch-help").checked = false;
document.getElementById("radio-control-disabled").style.visibility = document.getElementById("radio-control-disabled").style.visibility =
"hidden"; "hidden";
document.getElementById("radio-control-disabled").style.display = "none"; document.getElementById("radio-control-disabled").style.display = "none";
document.getElementById("radio-control-help").style.visibility = document.getElementById("radio-control-help").style.visibility = "hidden";
"hidden";
document.getElementById("radio-control-help").style.display = "none"; document.getElementById("radio-control-help").style.display = "none";
document.getElementById("radio-control-rigctld").style.visibility = document.getElementById("radio-control-rigctld").style.visibility =
"visible"; "visible";
document.getElementById("radio-control-rigctld").style.display = document.getElementById("radio-control-rigctld").style.display = "block";
"block";
} else { } else {
document.getElementById("radio-control-switch-disabled").checked = true; document.getElementById("radio-control-switch-disabled").checked = true;
document.getElementById("radio-control-switch-help").checked = false; document.getElementById("radio-control-switch-help").checked = false;
document.getElementById("radio-control-switch-rigctld").checked = false; document.getElementById("radio-control-switch-rigctld").checked = false;
document.getElementById("radio-control-help").style.display = "none"; document.getElementById("radio-control-help").style.display = "none";
document.getElementById("radio-control-help").style.visibility = document.getElementById("radio-control-help").style.visibility = "hidden";
"hidden";
document.getElementById("radio-control-rigctld").style.visibility = document.getElementById("radio-control-rigctld").style.visibility =
"hidden"; "hidden";
document.getElementById("radio-control-rigctld").style.display = document.getElementById("radio-control-rigctld").style.display = "none";
"none";
} }
// remote tnc // remote tnc
@ -485,13 +472,11 @@ window.addEventListener("DOMContentLoaded", () => {
"visible"; "visible";
document.getElementById("radio-control-help").style.display = "none"; document.getElementById("radio-control-help").style.display = "none";
document.getElementById("radio-control-help").style.visibility = document.getElementById("radio-control-help").style.visibility = "hidden";
"hidden";
document.getElementById("radio-control-rigctld").style.visibility = document.getElementById("radio-control-rigctld").style.visibility =
"hidden"; "hidden";
document.getElementById("radio-control-rigctld").style.display = document.getElementById("radio-control-rigctld").style.display = "none";
"none";
config.radiocontrol = "disabled"; config.radiocontrol = "disabled";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
@ -514,8 +499,7 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("radio-control-rigctld").style.visibility = document.getElementById("radio-control-rigctld").style.visibility =
"hidden"; "hidden";
document.getElementById("radio-control-rigctld").style.display = document.getElementById("radio-control-rigctld").style.display = "none";
"none";
config.radiocontrol = "rigctld"; config.radiocontrol = "rigctld";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
@ -533,19 +517,16 @@ window.addEventListener("DOMContentLoaded", () => {
"hidden"; "hidden";
document.getElementById("radio-control-help").style.display = "none"; document.getElementById("radio-control-help").style.display = "none";
document.getElementById("radio-control-help").style.visibility = document.getElementById("radio-control-help").style.visibility = "hidden";
"hidden";
document.getElementById("radio-control-rigctld").style.visibility = document.getElementById("radio-control-rigctld").style.visibility =
"visible"; "visible";
document.getElementById("radio-control-rigctld").style.display = document.getElementById("radio-control-rigctld").style.display = "block";
"block";
config.radiocontrol = "rigctld"; config.radiocontrol = "rigctld";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}); });
document document
.getElementById("hamlib_rigctld_path") .getElementById("hamlib_rigctld_path")
.addEventListener("click", () => { .addEventListener("click", () => {
@ -571,25 +552,19 @@ window.addEventListener("DOMContentLoaded", () => {
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}); });
// hamlib event listener for saving settings
// hamlib event listener for saving settings hamlib_elements.forEach(function (elem) {
hamlib_elements.forEach(function(elem) { try {
try{ document.getElementById(elem).addEventListener("change", function () {
document.getElementById(elem).addEventListener("change", function() { config.elem = document.getElementById(elem).value;
config.elem = document.getElementById(elem).value; fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); console.log(config.elem);
console.log(config.elem) });
}); } catch (e) {
} catch(e){ console.log(e);
console.log(e) console.log(elem);
console.log(elem) }
});
}
});
document document
.getElementById("hamlib_rigctld_start") .getElementById("hamlib_rigctld_start")
@ -602,33 +577,39 @@ window.addEventListener("DOMContentLoaded", () => {
paramList = paramList.concat("-m", hamlib_deviceid); paramList = paramList.concat("-m", hamlib_deviceid);
// hamlib deviceport setting // hamlib deviceport setting
if (document.getElementById("hamlib_deviceport").value !== 'ignore') { if (document.getElementById("hamlib_deviceport").value !== "ignore") {
var hamlib_deviceport = var hamlib_deviceport =
document.getElementById("hamlib_deviceport").value; document.getElementById("hamlib_deviceport").value;
paramList = paramList.concat("-r", hamlib_deviceport); paramList = paramList.concat("-r", hamlib_deviceport);
} }
// hamlib serialspeed setting // hamlib serialspeed setting
if (document.getElementById("hamlib_serialspeed").value !== 'ignore') { if (document.getElementById("hamlib_serialspeed").value !== "ignore") {
var hamlib_serialspeed = var hamlib_serialspeed =
document.getElementById("hamlib_serialspeed").value; document.getElementById("hamlib_serialspeed").value;
paramList = paramList.concat("-s", hamlib_serialspeed); paramList = paramList.concat("-s", hamlib_serialspeed);
} }
// hamlib databits setting // hamlib databits setting
if (document.getElementById("hamlib_data_bits").value !== 'ignore') { if (document.getElementById("hamlib_data_bits").value !== "ignore") {
var hamlib_data_bits = document.getElementById("hamlib_data_bits").value; var hamlib_data_bits =
paramList = paramList.concat("--set-conf=data_bits=" + hamlib_data_bits); document.getElementById("hamlib_data_bits").value;
paramList = paramList.concat(
"--set-conf=data_bits=" + hamlib_data_bits
);
} }
// hamlib stopbits setting // hamlib stopbits setting
if (document.getElementById("hamlib_stop_bits").value !== 'ignore') { if (document.getElementById("hamlib_stop_bits").value !== "ignore") {
var hamlib_stop_bits = document.getElementById("hamlib_stop_bits").value; var hamlib_stop_bits =
paramList = paramList.concat("--set-conf=stop_bits=" + hamlib_stop_bits); document.getElementById("hamlib_stop_bits").value;
paramList = paramList.concat(
"--set-conf=stop_bits=" + hamlib_stop_bits
);
} }
// hamlib handshake setting // hamlib handshake setting
if (document.getElementById("hamlib_handshake").value !== 'ignore') { if (document.getElementById("hamlib_handshake").value !== "ignore") {
var hamlib_handshake = var hamlib_handshake =
document.getElementById("hamlib_handshake").value; document.getElementById("hamlib_handshake").value;
paramList = paramList.concat( paramList = paramList.concat(
@ -637,26 +618,26 @@ window.addEventListener("DOMContentLoaded", () => {
} }
// hamlib dcd setting // hamlib dcd setting
if (document.getElementById("hamlib_dcd").value !== 'ignore') { if (document.getElementById("hamlib_dcd").value !== "ignore") {
var hamlib_dcd = document.getElementById("hamlib_dcd").value; var hamlib_dcd = document.getElementById("hamlib_dcd").value;
paramList = paramList.concat("--dcd-type=" + hamlib_dcd); paramList = paramList.concat("--dcd-type=" + hamlib_dcd);
} }
// hamlib ptt port // hamlib ptt port
if (document.getElementById("hamlib_ptt_port").value !== 'ignore') { if (document.getElementById("hamlib_ptt_port").value !== "ignore") {
var hamlib_ptt_port = document.getElementById("hamlib_ptt_port").value; var hamlib_ptt_port = document.getElementById("hamlib_ptt_port").value;
paramList = paramList.concat("-p", hamlib_ptt_port); paramList = paramList.concat("-p", hamlib_ptt_port);
} }
// hamlib ptt type // hamlib ptt type
if (document.getElementById("hamlib_pttprotocol").value !== 'ignore') { if (document.getElementById("hamlib_pttprotocol").value !== "ignore") {
var hamlib_ptt_type = var hamlib_ptt_type =
document.getElementById("hamlib_pttprotocol").value; document.getElementById("hamlib_pttprotocol").value;
paramList = paramList.concat("--ptt-type=" + hamlib_ptt_type); paramList = paramList.concat("--ptt-type=" + hamlib_ptt_type);
} }
// hamlib dtr state // hamlib dtr state
if (document.getElementById("hamlib_dtrstate").value !== 'ignore') { if (document.getElementById("hamlib_dtrstate").value !== "ignore") {
var hamlib_dtrstate = document.getElementById("hamlib_dtrstate").value; var hamlib_dtrstate = document.getElementById("hamlib_dtrstate").value;
paramList = paramList.concat("--set-conf=dtr_state=" + hamlib_dtrstate); paramList = paramList.concat("--set-conf=dtr_state=" + hamlib_dtrstate);
} }
@ -1289,7 +1270,6 @@ window.addEventListener("DOMContentLoaded", () => {
if (!confirm("Stop the TNC?")) return; if (!confirm("Stop the TNC?")) return;
daemon.stopTNC(); daemon.stopTNC();
}); });
// TEST HAMLIB // TEST HAMLIB
@ -1330,7 +1310,6 @@ window.addEventListener("DOMContentLoaded", () => {
// START TRANSMISSION // START TRANSMISSION
document.getElementById("startTransmission").addEventListener("click", () => { document.getElementById("startTransmission").addEventListener("click", () => {
var fileList = document.getElementById("dataModalFile").files; var fileList = document.getElementById("dataModalFile").files;
console.log(fileList); console.log(fileList);
var reader = new FileReader(); var reader = new FileReader();
@ -3083,35 +3062,30 @@ function displayToast(
}); });
} }
function loadSettings(elements) {
elements.forEach(function (id) {
let element = document.getElementById(id);
function loadSettings(elements){ if (element.tagName === "SELECT") {
elements.forEach(function(id) { element.value = config.elem;
let element = document.getElementById(id);
if(element.tagName === 'SELECT') { // add selected value
element.value = config.elem; for (var i = 0, j = element.options.length; i < j; ++i) {
if (element.options[i].innerHTML === config.elem) {
// add selected value element.selectedIndex = i;
for(var i = 0, j = element.options.length; i < j; ++i) { break;
if(element.options[i].innerHTML === config.elem) {
element.selectedIndex = i;
break;
}
}
} else if (element.tagName === 'INPUT' && element.type === 'text') {
element.value = config.elem;
} else if (element.tagName === 'INPUT' && element.type === 'radio') {
element.value = config.elem;
if(config.elem === "True"){
element.checked = true;
} else {
element.checked = false;
}
} }
}
} else if (element.tagName === "INPUT" && element.type === "text") {
element.value = config.elem;
} else if (element.tagName === "INPUT" && element.type === "radio") {
element.value = config.elem;
if (config.elem === "True") {
}); element.checked = true;
} } else {
element.checked = false;
}
}
});
}

View file

@ -338,40 +338,39 @@
disabled disabled
</label> </label>
<div <div
class="btn-group btn-group-sm" class="btn-group btn-group-sm"
role="group" role="group"
aria-label="radio-control-switch-rigctld" aria-label="radio-control-switch-rigctld"
>
<input
type="radio"
class="btn-check"
name="radio-control-switch"
id="radio-control-switch-rigctld"
autocomplete="off"
/>
<label
class="btn btn-sm btn-outline-secondary"
for="radio-control-switch-rigctld"
> >
Hamlib <input
</label> type="radio"
</div> class="btn-check"
<div class="btn-group" role="group"> name="radio-control-switch"
<button id="radio-control-switch-rigctld"
type="button" autocomplete="off"
id="testHamlib" />
class="btn btn-sm btn-outline-secondary" <label
data-bs-placement="bottom" class="btn btn-sm btn-outline-secondary"
data-bs-toggle="tooltip" for="radio-control-switch-rigctld"
data-bs-html="true" >
title="Test your hamlib settings and toggle PTT once. Button will become <strong class='text-success'>green</strong> on success and <strong class='text-danger'>red</strong> if fails." Hamlib
> </label>
PTT Test
</button>
</div>
</div> </div>
<div class="btn-group" role="group">
<button
type="button"
id="testHamlib"
class="btn btn-sm btn-outline-secondary"
data-bs-placement="bottom"
data-bs-toggle="tooltip"
data-bs-html="true"
title="Test your hamlib settings and toggle PTT once. Button will become <strong class='text-success'>green</strong> on success and <strong class='text-danger'>red</strong> if fails."
>
PTT Test
</button>
</div>
</div>
<div <div
class="btn-group btn-group-sm" class="btn-group btn-group-sm"
role="group" role="group"
@ -391,7 +390,6 @@
<i class="bi bi-question-circle"></i> <i class="bi bi-question-circle"></i>
</label> </label>
</div> </div>
</div> </div>
<div class="card-body p-2"> <div class="card-body p-2">
<!-- RADIO CONTROL DISABLED --> <!-- RADIO CONTROL DISABLED -->
@ -402,30 +400,31 @@
<!-- RADIO CONTROL RIGCTLD INFO--> <!-- RADIO CONTROL RIGCTLD INFO-->
<div id="radio-control-rigctld"> <div id="radio-control-rigctld">
<div class="input-group input-group-sm mb-1"> <div class="input-group input-group-sm mb-1">
<div class="input-group input-group-sm mb-1"> <div class="input-group input-group-sm mb-1">
<span class="input-group-text">Rigctld Network settings</span> <span class="input-group-text"
>Rigctld Network settings</span
>
<span class="input-group-text">IP</span> <span class="input-group-text">IP</span>
<input <input
type="text" type="text"
class="form-control" class="form-control"
placeholder="rigctld IP" placeholder="rigctld IP"
id="hamlib_rigctld_ip" id="hamlib_rigctld_ip"
aria-label="Device IP" aria-label="Device IP"
aria-describedby="basic-addon1" aria-describedby="basic-addon1"
/> />
<span class="input-group-text">Port</span> <span class="input-group-text">Port</span>
<input <input
type="text" type="text"
class="form-control" class="form-control"
placeholder="rigctld port" placeholder="rigctld port"
id="hamlib_rigctld_port" id="hamlib_rigctld_port"
aria-label="Device Port" aria-label="Device Port"
aria-describedby="basic-addon1" aria-describedby="basic-addon1"
/> />
</div> </div>
<span class="input-group-text">Rigctld application</span> <span class="input-group-text">Rigctld application</span>
<button <button
class="btn btn-outline-success" class="btn btn-outline-success"
type="button" type="button"
@ -449,22 +448,18 @@
Stop Stop
</button> </button>
</div> </div>
</div> </div>
<!-- RADIO CONTROL HELP --> <!-- RADIO CONTROL HELP -->
<div id="radio-control-help"> <div id="radio-control-help">
<strong>VOX:</strong> disable rigctld usage <strong>VOX:</strong> disable rigctld usage
<br> <br />
<strong>HAMLIB locally:</strong> configure in settings, then start/stop service. <strong>HAMLIB locally:</strong> configure in settings, then
<br> start/stop service.
<strong>HAMLIB remotely:</strong> Enter IP/Port, connection happens automatically. <br />
<strong>HAMLIB remotely:</strong> Enter IP/Port, connection
happens automatically.
</div> </div>
</div> </div>
<div class="card-footer text-muted small" id="hamlib_info_field"> <div class="card-footer text-muted small" id="hamlib_info_field">
Select your radio and PTT settings. Start/Stop Hamlib Rigctld Select your radio and PTT settings. Start/Stop Hamlib Rigctld
@ -2090,7 +2085,9 @@
</select> </select>
</div> </div>
<div class="input-group input-group-sm mb-1"> <div class="input-group input-group-sm mb-1">
<span class="input-group-text" style="width: 180px">Data bits</span> <span class="input-group-text" style="width: 180px"
>Data bits</span
>
<select <select
class="form-select form-select-sm" class="form-select form-select-sm"
@ -2112,7 +2109,7 @@
aria-label=".form-select-sm" aria-label=".form-select-sm"
id="hamlib_stop_bits" id="hamlib_stop_bits"
> >
<option selected value="ignore">-- ignore --</option> <option selected value="ignore">-- ignore --</option>
<option value="1">1</option> <option value="1">1</option>
<option value="2">2</option> <option value="2">2</option>
</select> </select>
@ -2127,7 +2124,7 @@
aria-label=".form-select-sm" aria-label=".form-select-sm"
id="hamlib_handshake" id="hamlib_handshake"
> >
<option selected value="ignore">-- ignore --</option> <option selected value="ignore">-- ignore --</option>
<option value="None">None (Default)</option> <option value="None">None (Default)</option>
</select> </select>
</div> </div>
@ -2141,12 +2138,12 @@
>PTT Device Port</span >PTT Device Port</span
> >
<select <select
class="form-select form-select-sm" class="form-select form-select-sm"
aria-label=".form-select-sm" aria-label=".form-select-sm"
id="hamlib_ptt_port" id="hamlib_ptt_port"
> <option selected value="ignore">-- ignore --</option> >
<option selected value="ignore">-- ignore --</option>
</select> </select>
</div> </div>
<div class="input-group input-group-sm mb-1"> <div class="input-group input-group-sm mb-1">
@ -2160,7 +2157,7 @@
id="hamlib_pttprotocol" id="hamlib_pttprotocol"
style="width: 0.5rem" style="width: 0.5rem"
> >
<option selected value="ignore">-- ignore --</option> <option selected value="ignore">-- ignore --</option>
<option value="NONE">NONE</option> <option value="NONE">NONE</option>
<option value="RIG">RIG</option> <option value="RIG">RIG</option>
<option value="USB">USB</option> <option value="USB">USB</option>
@ -2179,7 +2176,7 @@
id="hamlib_dcd" id="hamlib_dcd"
style="width: 0.5rem" style="width: 0.5rem"
> >
<option selected value="ignore">-- ignore --</option> <option selected value="ignore">-- ignore --</option>
<option value="NONE">NONE</option> <option value="NONE">NONE</option>
<option value="RIG">RIG/CAT</option> <option value="RIG">RIG/CAT</option>
<option value="DSR">DSR</option> <option value="DSR">DSR</option>
@ -2197,7 +2194,7 @@
id="hamlib_dtrstate" id="hamlib_dtrstate"
style="width: 0.5rem" style="width: 0.5rem"
> >
<option selected value="ignore">-- ignore --</option> <option selected value="ignore">-- ignore --</option>
<option value="OFF">OFF</option> <option value="OFF">OFF</option>
<option value="ON">ON</option> <option value="ON">ON</option>
</select> </select>
@ -2219,7 +2216,6 @@
class="form-select form-select-sm" class="form-select form-select-sm"
id="tuning_range_fmin" id="tuning_range_fmin"
> >
<option value="-50.0">-50.0</option> <option value="-50.0">-50.0</option>
<option value="-100.0">-100.0</option> <option value="-100.0">-100.0</option>
<option value="-150.0">-150.0</option> <option value="-150.0">-150.0</option>