Skip to content

Commit f701a04

Browse files
authored
Merge pull request #8 from HB9HIL/station_lookup
Station lookup
2 parents 5883ff0 + e448aeb commit f701a04

File tree

3 files changed

+103
-9
lines changed

3 files changed

+103
-9
lines changed

index.html

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,39 @@
8787
border: 1px solid #727272;
8888
}
8989

90+
.form-control:focus {
91+
color: inherit;
92+
background-color: #1c1c1c;
93+
}
94+
95+
.form-control:disabled, .form-control[readonly] {
96+
background-color: #3e3e3e;
97+
opacity: 1;
98+
}
99+
90100
#buttonsRow {
91101
position: fixed;
92102
bottom: 8px;
93103
width: 100%;
94-
padding: 10px; /* Optional: Füge Padding hinzu, um die Knöpfe zu trennen */
104+
padding: 10px;
105+
}
106+
107+
#reload_icon {
108+
width: 16px;
109+
height: 16px;
110+
margin-left: 4px;
111+
margin-bottom: 2px;
112+
vertical-align: middle;
113+
fill: white;
114+
}
115+
116+
label {
117+
display: flex;
118+
align-items: center;
119+
}
120+
121+
label svg {
122+
cursor: pointer;
95123
}
96124
</style>
97125

@@ -142,10 +170,16 @@
142170
</div>
143171
</div>
144172
<div class="col">
145-
<div class="mb-3">
146-
<label for="wavelog_key">Wavelog-Station-ID</label>
147-
<input type="number" class="form-control form-control-sm" name="wavelog_id"
148-
id="wavelog_id" value="" />
173+
<div class="mb-3" style="position: relative;">
174+
<label for="wavelog_id" style="display: inline-block;">
175+
Wavelog-Station-ID
176+
<svg id="reload_icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
177+
<path d="M463.5 224l8.5 0c13.3 0 24-10.7 24-24l0-128c0-9.7-5.8-18.5-14.8-22.2s-19.3-1.7-26.2 5.2L413.4 96.6c-87.6-86.5-228.7-86.2-315.8 1c-87.5 87.5-87.5 229.3 0 316.8s229.3 87.5 316.8 0c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0c-62.5 62.5-163.8 62.5-226.3 0s-62.5-163.8 0-226.3c62.2-62.2 162.7-62.5 225.3-1L327 183c-6.9 6.9-8.9 17.2-5.2 26.2s12.5 14.8 22.2 14.8l119.5 0z" />
178+
</svg>
179+
</label>
180+
<select id="wavelog_id" class="form-control form-control-sm" disabled>
181+
<option value="">No stations loaded</option>
182+
</select>
149183
</div>
150184
</div>
151185
</div>

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ storage.has('basic', function(error, hasKey) {
4242

4343
function createWindow () {
4444
const mainWindow = new BrowserWindow({
45-
width: 420,
45+
width: 430,
4646
height: 250,
4747
resizable: false,
4848
autoHideMenuBar: app.isPackaged,

renderer.js

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ const {ipcRenderer} = require('electron')
1414
const bt_save=select("#save");
1515
const bt_quit=select("#quit");
1616
const bt_test=select("#test");
17+
const input_key=select("#wavelog_key");
18+
const input_url=select("#wavelog_url");
1719
var oldCat={ vfo: 0, mode: "SSB" };
1820

1921
$(document).ready(function() {
2022

2123
cfg=ipcRenderer.sendSync("get_config", '');
2224
$("#wavelog_url").val(cfg.wavelog_url);
2325
$("#wavelog_key").val(cfg.wavelog_key);
24-
$("#wavelog_id").val(cfg.wavelog_id);
26+
// $("#wavelog_id").val(cfg.wavelog_id);
2527
$("#wavelog_radioname").val(cfg.wavelog_radioname);
2628
$("#flrig_host").val(cfg.flrig_host);
2729
$("#flrig_port").val(cfg.flrig_port);
@@ -67,6 +69,19 @@ $(document).ready(function() {
6769
console.log(x);
6870
});
6971

72+
input_key.addEventListener('change', () => {
73+
getStations();
74+
});
75+
input_url.addEventListener('change', () => {
76+
getStations();
77+
});
78+
$('#reload_icon').on('click', () => {
79+
getStations();
80+
});
81+
if (cfg.wavelog_key != "" && cfg.wavelog_url != "") {
82+
getStations();
83+
}
84+
7085
getsettrx();
7186

7287
$("#flrig_ena").on( "click",function() {
@@ -78,15 +93,15 @@ $(document).ready(function() {
7893

7994
$("#config-tab").on("click",function() {
8095
obj={};
81-
obj.width=420;
96+
obj.width=430;
8297
obj.height=550;
8398
obj.ani=false;
8499
resizeme(obj);
85100
});
86101

87102
$("#status-tab").on("click",function() {
88103
obj={};
89-
obj.width=420;
104+
obj.width=430;
90105
obj.height=250;
91106
obj.ani=false;
92107
resizeme(obj);
@@ -208,3 +223,48 @@ function updateUtcTime() {
208223

209224
document.getElementById('utc').innerHTML = formattedTime;
210225
}
226+
227+
async function getStations() {
228+
let select = $('#wavelog_id');
229+
select.empty();
230+
select.prop('disabled', true);
231+
try {
232+
let x = await fetch($('#wavelog_url').val().trim() + '/api/station_info/' + $('#wavelog_key').val().trim(), {
233+
method: 'GET',
234+
rejectUnauthorized: false,
235+
headers: {
236+
Accept: 'application/json',
237+
'Content-Type': 'application/json',
238+
},
239+
});
240+
241+
if (!x.ok) {
242+
throw new Error(`HTTP error! Status: ${x.status}`);
243+
}
244+
245+
let data = await x.json();
246+
fillDropdown(data);
247+
248+
} catch (error) {
249+
select.append(new Option('Failed to load stations', '0'));
250+
console.error('Could not load station locations:', error.message);
251+
}
252+
}
253+
254+
function fillDropdown(data) {
255+
let select = $('#wavelog_id');
256+
select.empty();
257+
select.prop('disabled', false);
258+
259+
data.forEach(function(station) {
260+
let optionText = station.station_profile_name + " (" + station.station_callsign + ", ID: " + station.station_id + ")";
261+
let optionValue = station.station_id;
262+
select.append(new Option(optionText, optionValue));
263+
});
264+
265+
if (cfg.wavelog_id && data.some(station => station.station_id == cfg.wavelog_id)) {
266+
select.val(cfg.wavelog_id);
267+
} else {
268+
select.val(data.length > 0 ? data[0].station_id : null);
269+
}
270+
}

0 commit comments

Comments
 (0)