Skip to content

Commit

Permalink
Merge pull request #60 from HB9HIL/qrg_input
Browse files Browse the repository at this point in the history
Qrg input
  • Loading branch information
m0urs authored Nov 13, 2024
2 parents 13a6947 + 8504eff commit af497cb
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 20 deletions.
15 changes: 15 additions & 0 deletions application/controllers/User_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public function del_fav() {
public function dismissVersionDialog() {
$this->user_options_model->set_option('version_dialog', 'confirmed', array('boolean' => 'true'));
}

public function get_qrg_units() {

$qrg_units = [];

foreach($this->session->get_userdata() as $key => $value) {
if (strpos($key, 'qrgunit_') === 0) {
$band = str_replace('qrgunit_', '', $key);
$qrg_units[$band] = $value;
}
}

header('Content-Type: application/json');
echo json_encode($qrg_units);
}
}


Expand Down
2 changes: 1 addition & 1 deletion application/views/bands/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<td style="text-align: center; vertical-align: middle;" ><?php echo $band->data;?></td>
<td style="text-align: center; vertical-align: middle;" ><?php echo $band->cw;?></td>
<td style="text-align: center; vertical-align: middle;" class='band_<?php echo $band->bandid ?>'>
<select class="form-select unitselect" name="unit_<?php echo $band->id; ?>">
<select style="min-width: 80px;" class="form-select unitselect" name="unit_<?php echo $band->id; ?>">
<option value="Hz" <?php if ($this->frequency->qrg_unit($band->band) == 'Hz') { echo 'selected';} ?>><?= __("Hz"); ?></option>
<option value="kHz" <?php if ($this->frequency->qrg_unit($band->band) == 'kHz') { echo 'selected';} ?>><?= __("kHz"); ?></option>
<option value="MHz" <?php if ($this->frequency->qrg_unit($band->band) == 'MHz') { echo 'selected';} ?>><?= __("MHz"); ?></option>
Expand Down
6 changes: 5 additions & 1 deletion application/views/contesting/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@

<div class="mb-3 col-md-2">
<label for="frequency"><?= __("Frequency"); ?></label>
<input type="text" class="form-control form-control-sm" id="frequency" name="freq_display" value="<?php echo $this->session->userdata('freq'); ?>" />
<div class="input-group input-group-sm">
<input type="text" class="form-control form-control-sm" id="freq_calculated" name="freq_calculated" value="0" />
<small class="input-group-text btn-included-on-field" id="qrg_unit">...</small>
</div>
<input style="display: none;" type="text" class="form-control form-control-sm" id="frequency" name="freq_display" value="<?php echo $this->session->userdata('freq'); ?>" />
</div>

<div class="mb-3 col-md-2">
Expand Down
2 changes: 2 additions & 0 deletions application/views/interface_assets/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ function searchButtonPress() {

<?php } ?>
<?php if ( $this->uri->segment(1) == "qso" || ($this->uri->segment(1) == "contesting" && $this->uri->segment(2) != "add")) { ?>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/sections/qrg_handler.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/moment.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/datetime-moment.js"></script>

Expand Down Expand Up @@ -1209,6 +1210,7 @@ function searchButtonPress() {
$(".radio_login_error" ).remove();
}
cat2UI($('#frequency'),data.frequency,false,true,function(d){
$('#frequency').trigger('change');
if ($("#band").val() != frequencyToBand(d)) {
$("#band").val(frequencyToBand(d)).trigger('change'); // Let's only change if we really have a different band!
}
Expand Down
6 changes: 5 additions & 1 deletion application/views/qso/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@
</div>
<div class="mb-3 col">
<label for="frequency"><?= __("Frequency"); ?></label>
<input type="text" tabindex="3" class="form-control form-control-sm" id="frequency" name="freq_display" value="<?php echo $this->session->userdata('freq'); ?>" />
<div class="input-group input-group-sm">
<input type="text" tabindex="3" class="form-control form-control-sm" id="freq_calculated" name="freq_calculated" value="0" />
<small class="input-group-text btn-included-on-field" id="qrg_unit">...</small>
</div>
<input style="display: none;" type="text" class="form-control form-control-sm" id="frequency" name="freq_display" value="<?php echo $this->session->userdata('freq'); ?>" />
</div>
</div>

Expand Down
24 changes: 15 additions & 9 deletions assets/js/sections/contesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ $(document).ready(async function () {
await restoreContestSession(sessiondata); // wait for restoring until finished
setRst($("#mode").val());
$('#contestname').val($('#contestname_select').val());

// Clear the localStorage for the qrg units
localStorage.clear();
set_qrg();
});

// Always update the contestname
Expand Down Expand Up @@ -471,16 +475,17 @@ function highlight(term, base) {
// Only set the frequency when not set by userdata/PHP.
if ($('#frequency').val() == "") {
$.get('qso/band_to_freq/' + $('#band').val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result);
$('#frequency').val(result).trigger("change");
$('#frequency_rx').val("");
set_qrg();
});
}

/* on mode change */
$('#mode').change(function () {
if ($('#radio').val() == '0') {
$.get('qso/band_to_freq/' + $('#band').val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result);
$('#frequency').val(result).trigger("change");
$('#frequency_rx').val("");
});
}
Expand All @@ -491,12 +496,13 @@ $('#mode').change(function () {
/* Calculate Frequency */
/* on band change */
$('#band').change(function () {
if ($('#radio').val() == '0') {
$.get('qso/band_to_freq/' + $(this).val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result);
$('#frequency_rx').val("");
});
if ($('#radio').val() == '0') {
$.get('qso/band_to_freq/' + $(this).val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result).trigger("change");
$('#frequency_rx').val("");
});
}
set_qrg();
checkIfWorkedBefore();
});

Expand All @@ -507,7 +513,7 @@ $('#band').change(function () {
$('#radio').change(function () {
if ($('#radio').val() == '0') {
$.get('qso/band_to_freq/' + $('#band').val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result);
$('#frequency').val(result).trigger("change");
$('#frequency_rx').val("");
});
}
Expand Down Expand Up @@ -767,7 +773,7 @@ async function restoreContestSession(data) {
$("#frequency").val(settings.freq_display);
} else {
$.get('qso/band_to_freq/' + settings.band + '/' + settings.mode, function (result) {
$('#frequency').val(result);
$('#frequency').val(result).trigger("change");
});
}
}
Expand Down
129 changes: 129 additions & 0 deletions assets/js/sections/qrg_handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
$('#qrg_unit').on('click', function () {
if ($(this).html() == 'Hz') {
$(this).html('kHz');
$("#freq_calculated").val($("#frequency").val() / 1000);
localStorage.setItem('qrgunit_' + $('#band').val(), 'kHz');
} else if ($(this).html() == 'kHz') {
$(this).html('MHz');
$("#freq_calculated").val($("#frequency").val() / 1000000);
localStorage.setItem('qrgunit_' + $('#band').val(), 'MHz');
} else if ($(this).html() == 'MHz') {
$(this).html('GHz');
$("#freq_calculated").val($("#frequency").val() / 1000000000);
localStorage.setItem('qrgunit_' + $('#band').val(), 'GHz');
} else if ($(this).html() == 'GHz') {
$(this).html('Hz');
$("#freq_calculated").val($("#frequency").val());
localStorage.setItem('qrgunit_' + $('#band').val(), 'Hz');
}
});

async function set_qrg() {

let frequency = $('#frequency').val();
let band = $('#band').val();

// check if there are qrgunits in the localStorage
if (!localStorage.getItem('qrgunit_' + band)) {
// console.log('fetching qrg units');
await $.getJSON(base_url + 'index.php/user_options/get_qrg_units', async function (result) {
$.each(result, function(key, value) {
localStorage.setItem('qrgunit_' + key, value);
});
});
}

let qrgunit = localStorage.getItem('qrgunit_' + band);

if (qrgunit != null) {
$('#qrg_unit').html(localStorage.getItem('qrgunit_' + band));
} else {
$('#qrg_unit').html('...');
}

if (qrgunit == 'Hz') {
$("#freq_calculated").val(frequency);
} else if (qrgunit == 'kHz') {
$("#freq_calculated").val(frequency / 1000);
} else if (qrgunit == 'MHz') {
$("#freq_calculated").val(frequency / 1000000);
} else if (qrgunit == 'GHz') {
$("#freq_calculated").val(frequency / 1000000000);
}
}

async function set_new_qrg() {
let new_qrg = $('#freq_calculated').val().trim();
let parsed_qrg = parseFloat(new_qrg);
let unit = $('#qrg_unit').html();

// check if the input contains a unit and parse the qrg
if (/^\d+(\.\d+)?\s*hz$/i.test(new_qrg)) {
unit = 'Hz';
parsed_qrg = parseFloat(new_qrg);
} else if (/^\d+(\.\d+)?\s*khz$/i.test(new_qrg)) {
unit = 'kHz';
parsed_qrg = parseFloat(new_qrg);
} else if (/^\d+(\.\d+)?\s*mhz$/i.test(new_qrg)) {
unit = 'MHz';
parsed_qrg = parseFloat(new_qrg);
} else if (/^\d+(\.\d+)?\s*ghz$/i.test(new_qrg)) {
unit = 'GHz';
parsed_qrg = parseFloat(new_qrg);
}

// update the unit if there was any change
$('#qrg_unit').html(unit);

// calculate the other stuff
let qrg_hz;
switch (unit) {
case 'Hz':
qrg_hz = parsed_qrg;
localStorage.setItem('qrgunit_' + $('#band').val(), 'Hz');
break;
case 'kHz':
qrg_hz = parsed_qrg * 1000;
localStorage.setItem('qrgunit_' + $('#band').val(), 'kHz');
break;
case 'MHz':
qrg_hz = parsed_qrg * 1000000;
localStorage.setItem('qrgunit_' + $('#band').val(), 'MHz');
break;
case 'GHz':
qrg_hz = parsed_qrg * 1000000000;
localStorage.setItem('qrgunit_' + $('#band').val(), 'GHz');
break;
default:
qrg_hz = 0;
console.error('Invalid unit');
}

$('#frequency').val(qrg_hz);
$('#freq_calculated').val(parsed_qrg);
$('#band').val(frequencyToBand(qrg_hz));

}

$('#frequency').on('change', function () {
// console.log('frequency changed');
set_qrg();
});

$('#freq_calculated').on('input', function () {
$(this).val($(this).val().replace(',', '.'));
});

$('#freq_calculated').on('change', function () {
// console.log('freq_calculated changed');
set_new_qrg();
});

$('#freq_calculated').on('keydown', function (e) {
if (e.which === 13) {
e.preventDefault();
set_new_qrg().then(() => {
$("#qso_input").trigger('submit');
});
}
});
29 changes: 21 additions & 8 deletions assets/js/sections/qso.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ $(document).on("click", "#fav_recall", function (event) {
$('#band_rx').val(favs[this.innerText].band_rx);
$('#band').val(favs[this.innerText].band);
$('#frequency_rx').val(favs[this.innerText].frequency_rx);
$('#frequency').val(favs[this.innerText].frequency);
$('#frequency').val(favs[this.innerText].frequency).trigger("change");
$('#selectPropagation').val(favs[this.innerText].prop_mode);
$('#mode').val(favs[this.innerText].mode).on("change");
});
Expand Down Expand Up @@ -273,7 +273,7 @@ bc.onmessage = function (ev) {
}
setTimeout(() => {
if (ev.data.frequency != null) {
$('#frequency').val(ev.data.frequency);
$('#frequency').val(ev.data.frequency).trigger("change");
$("#band").val(frequencyToBand(ev.data.frequency));
}
if (ev.data.frequency_rx != "") {
Expand Down Expand Up @@ -365,7 +365,7 @@ $(document).on('change', 'input', function () {
}
$("#band").val(frequencyToBand(val2[0].Uplink_Freq));
$("#band_rx").val(frequencyToBand(val2[0].Downlink_Freq));
$("#frequency").val(val2[0].Uplink_Freq);
$("#frequency").val(val2[0].Uplink_Freq).trigger("change");
$("#frequency_rx").val(val2[0].Downlink_Freq);
$("#selectPropagation").val('SAT');
}
Expand Down Expand Up @@ -568,6 +568,8 @@ function reset_fields() {
$("#callsign").on("focusout", function () {
if ($(this).val().length >= 3 && preventLookup == false) {

$("#noticer").fadeOut(1000);

// Temp store the callsign
var temp_callsign = $(this).val();

Expand All @@ -591,7 +593,7 @@ $("#callsign").on("focusout", function () {
lookupCall = $.getJSON(base_url + 'index.php/logbook/json/' + find_callsign + '/' + json_band + '/' + json_mode + '/' + $('#stationProfile').val() + '/' + $('#start_date').val(), async function (result) {

// Make sure the typed callsign and json result match
if ($('#callsign').val = result.callsign) {
if ($('#callsign').val().toUpperCase().replace('Ø', '0') == result.callsign) {

// Reset QSO fields
resetDefaultQSOFields();
Expand Down Expand Up @@ -813,7 +815,12 @@ $("#callsign").on("focusout", function () {

// Get DXX Summary
getDxccResult(result.dxcc.adif, convert_case(result.dxcc.entity));
}
}
// else {
// console.log("Callsigns do not match, skipping lookup");
// console.log("Typed Callsign: " + $('#callsign').val());
// console.log("Returned Callsign: " + result.callsign);
// }
});
} else {
// Reset QSO fields
Expand Down Expand Up @@ -857,7 +864,7 @@ $('#start_date').on('change', function () {
$('.mode').on('change', function () {
if ($('#radio').val() == 0) {
$.get(base_url + 'index.php/qso/band_to_freq/' + $('#band').val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result);
$('#frequency').val(result).trigger("change");
});
}
$('#frequency_rx').val("");
Expand All @@ -868,14 +875,15 @@ $('.mode').on('change', function () {
$('#band').on('change', function () {
if ($('#radio').val() == 0) {
$.get(base_url + 'index.php/qso/band_to_freq/' + $(this).val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result);
$('#frequency').val(result).trigger("change");
});
}
$('#frequency_rx').val("");
$('#band_rx').val("");
$("#selectPropagation").val("");
$("#sat_name").val("");
$("#sat_mode").val("");
set_qrg();
});

/* On Key up Calculate Bearing and Distance */
Expand Down Expand Up @@ -1171,6 +1179,10 @@ $(document).ready(function () {
set_timers();
updateStateDropdown('#dxcc_id', '#stateInputLabel', '#location_us_county', '#stationCntyInputQso');

// Clear the localStorage for the qrg units
localStorage.clear();
set_qrg();

$("#locator").popover({ placement: 'top', title: 'Gridsquare Formatting', content: "Enter multiple (4-digit) grids separated with commas. For example: IO77,IO78" })
.focus(function () {
$('#locator').popover('show');
Expand Down Expand Up @@ -1388,8 +1400,9 @@ $(document).ready(function () {
// Only set the frequency when not set by userdata/PHP.
if ($('#frequency').val() == "") {
$.get(base_url + 'index.php/qso/band_to_freq/' + $('#band').val() + '/' + $('.mode').val(), function (result) {
$('#frequency').val(result);
$('#frequency').val(result).trigger("change");
$('#frequency_rx').val("");
set_qrg();
});
}

Expand Down

0 comments on commit af497cb

Please sign in to comment.