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

View file

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