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,7 +42,8 @@ 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_deviceid",
"hamlib_deviceport", "hamlib_deviceport",
"hamlib_stop_bits", "hamlib_stop_bits",
"hamlib_data_bits", "hamlib_data_bits",
@ -55,11 +56,8 @@ const contrib = [
"hamlib_rigctld_port", "hamlib_rigctld_port",
"hamlib_rigctld_ip", "hamlib_rigctld_ip",
"hamlib_rigctld_path", "hamlib_rigctld_path",
"hamlib_rigctld_server_port" "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,26 +552,20 @@ 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")
.addEventListener("click", () => { .addEventListener("click", () => {
@ -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) {
function loadSettings(elements){ elements.forEach(function (id) {
elements.forEach(function(id) {
let element = document.getElementById(id); let element = document.getElementById(id);
if(element.tagName === 'SELECT') { if (element.tagName === "SELECT") {
element.value = config.elem; element.value = config.elem;
// add selected value // add selected value
for(var i = 0, j = element.options.length; i < j; ++i) { for (var i = 0, j = element.options.length; i < j; ++i) {
if(element.options[i].innerHTML === config.elem) { if (element.options[i].innerHTML === config.elem) {
element.selectedIndex = i; element.selectedIndex = i;
break; break;
} }
} }
} else if (element.tagName === "INPUT" && element.type === "text") {
} else if (element.tagName === 'INPUT' && element.type === 'text') { element.value = config.elem;
} else if (element.tagName === "INPUT" && element.type === "radio") {
element.value = config.elem; element.value = config.elem;
} else if (element.tagName === 'INPUT' && element.type === 'radio') { if (config.elem === "True") {
element.value = config.elem;
if(config.elem === "True"){
element.checked = true; element.checked = true;
} else { } else {
element.checked = false; element.checked = false;
} }
} }
}); });
} }

View file

@ -369,7 +369,6 @@
> >
PTT Test PTT Test
</button> </button>
</div> </div>
</div> </div>
<div <div
@ -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,9 +400,10 @@
<!-- 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"
@ -425,7 +424,7 @@
/> />
</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"
@ -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">
@ -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>