Resolves issue when no previous contest qsos have been set and table was empty

Should resolve #2919 #2139
这个提交包含在:
Peter Goodhall 2024-01-14 18:04:35 +00:00
父节点 e2d7edcf81
当前提交 4128425f2d
共有 3 个文件被更改,包括 203 次插入97 次删除

查看文件

@ -50,6 +50,15 @@ class Contesting extends CI_Controller {
echo json_encode($this->Contesting_model->getSessionQsos($qso)); echo json_encode($this->Contesting_model->getSessionQsos($qso));
} }
public function getSessionFreshQsos() {
$this->load->model('Contesting_model');
$contest_id = $this->input->post('contest_id');
header('Content-Type: application/json');
echo json_encode($this->Contesting_model->getSessionFreshQsos($contest_id));
}
public function getSession() { public function getSession() {
$this->load->model('Contesting_model'); $this->load->model('Contesting_model');

查看文件

@ -29,6 +29,34 @@ class Contesting_model extends CI_Model {
return $data->result(); return $data->result();
} }
function getSessionFreshQsos($contest_id) {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$contestid = $contest_id;
// save contestid to debug
// Get current date and time
$now = new DateTime();
$now->modify('-1 minute');
$date = $now->format('Y-m-d H:i:s');
$sql = "SELECT date_format(col_time_on, '%d-%m-%Y %H:%i:%s') as col_time_on, col_call, col_band, col_mode,
col_submode, col_rst_sent, col_rst_rcvd, coalesce(col_srx, '') col_srx, coalesce(col_srx_string, '') col_srx_string,
coalesce(col_stx, '') col_stx, coalesce(col_stx_string, '') col_stx_string, coalesce(col_gridsquare, '') col_gridsquare,
coalesce(col_vucc_grids, '') col_vucc_grids FROM " .
$this->config->item('table_name') .
" WHERE station_id = " . $station_id .
" AND COL_TIME_ON >= '" . $date . "'" .
" AND COL_CONTEST_ID = '" . $contestid . "'" .
" ORDER BY COL_PRIMARY_KEY ASC";
$data = $this->db->query($sql);
return $data->result();
}
function getSession() { function getSession() {
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('Stations'); $CI->load->model('Stations');

查看文件

@ -1,9 +1,9 @@
// Callsign always has focus on load // Callsign always has focus on load
$("#callsign").focus(); $("#callsign").focus();
var sessiondata={}; var sessiondata = {};
$(document).ready(async function () { $(document).ready(async function () {
sessiondata=await getSession(); // save sessiondata global (we need it later, when adding qso) sessiondata = await getSession(); // save sessiondata global (we need it later, when adding qso)
await restoreContestSession(sessiondata); // wait for restoring until finished await restoreContestSession(sessiondata); // wait for restoring until finished
setRst($("#mode").val()); setRst($("#mode").val());
}); });
@ -66,13 +66,13 @@ function setSession(formdata) {
} }
// realtime clock // realtime clock
if ( ! manual ) { if (!manual) {
$(function ($) { $(function ($) {
handleStart = setInterval(function() { getUTCTimeStamp($('.input_time')); }, 500); handleStart = setInterval(function () { getUTCTimeStamp($('.input_time')); }, 500);
}); });
$(function ($) { $(function ($) {
handleDate = setInterval(function() { getUTCDateStamp($('.input_date')); }, 1000); handleDate = setInterval(function () { getUTCDateStamp($('.input_date')); }, 1000);
}); });
} }
@ -113,10 +113,10 @@ document.onkeyup = function (e) {
logQso(); logQso();
// Enter in received exchange logs QSO // Enter in received exchange logs QSO
} else if ((e.which == 13) && ( } else if ((e.which == 13) && (
($(document.activeElement).attr("id") == "exch_rcvd") ($(document.activeElement).attr("id") == "exch_rcvd")
|| ($(document.activeElement).attr("id") == "exch_gridsquare_r") || ($(document.activeElement).attr("id") == "exch_gridsquare_r")
|| ($(document.activeElement).attr("id") == "exch_serial_r") || ($(document.activeElement).attr("id") == "exch_serial_r")
) )
) { ) {
logQso(); logQso();
} else if (e.which == 27) { } else if (e.which == 27) {
@ -181,22 +181,22 @@ document.onkeyup = function (e) {
}; };
/* time input shortcut */ /* time input shortcut */
$('#start_time').change(function() { $('#start_time').change(function () {
var raw_time = $(this).val(); var raw_time = $(this).val();
if(raw_time.match(/^\d\[0-6]d$/)) { if (raw_time.match(/^\d\[0-6]d$/)) {
raw_time = "0"+raw_time; raw_time = "0" + raw_time;
} }
if(raw_time.match(/^[012]\d[0-5]\d$/)) { if (raw_time.match(/^[012]\d[0-5]\d$/)) {
raw_time = raw_time.substring(0,2)+":"+raw_time.substring(2,4); raw_time = raw_time.substring(0, 2) + ":" + raw_time.substring(2, 4);
$('#start_time').val(raw_time); $('#start_time').val(raw_time);
} }
}); });
/* date input shortcut */ /* date input shortcut */
$('#start_date').change(function() { $('#start_date').change(function () {
raw_date = $(this).val(); raw_date = $(this).val();
if(raw_date.match(/^[12]\d{3}[01]\d[0123]\d$/)) { if (raw_date.match(/^[12]\d{3}[01]\d[0123]\d$/)) {
raw_date = raw_date.substring(0,4)+"-"+raw_date.substring(4,6)+"-"+raw_date.substring(6,8); raw_date = raw_date.substring(0, 4) + "-" + raw_date.substring(4, 6) + "-" + raw_date.substring(6, 8);
$('#start_date').val(raw_date); $('#start_date').val(raw_date);
} }
}); });
@ -210,13 +210,13 @@ $("#callsign").keyup(function () {
url: 'lookup/scp', url: 'lookup/scp',
method: 'POST', method: 'POST',
data: { data: {
callsign: $(this).val().toUpperCase() callsign: $(this).val().toUpperCase()
}, },
success: function(result) { success: function (result) {
$('.callsign-suggestions').text(result); $('.callsign-suggestions').text(result);
highlight(call.toUpperCase()); highlight(call.toUpperCase());
} }
}); });
checkIfWorkedBefore(); checkIfWorkedBefore();
var qTable = $('.qsotable').DataTable(); var qTable = $('.qsotable').DataTable();
@ -241,7 +241,7 @@ function checkIfWorkedBefore() {
'contest': $("#contestname").val() 'contest': $("#contestname").val()
}, },
success: function (result) { success: function (result) {
if (result.message.substr(0,6) == 'Worked') { if (result.message.substr(0, 6) == 'Worked') {
$('#callsign_info').text(result.message); $('#callsign_info').text(result.message);
} }
} }
@ -388,31 +388,31 @@ function logQso() {
case 'Exchange': case 'Exchange':
exchsent = $("#exch_sent").val(); exchsent = $("#exch_sent").val();
exchrcvd = $("#exch_rcvd").val(); exchrcvd = $("#exch_rcvd").val();
break; break;
case 'Gridsquare': case 'Gridsquare':
gridr = gridsquare; gridr = gridsquare;
vuccr = vucc; vuccr = vucc;
break; break;
case 'Serial': case 'Serial':
serials = $("#exch_serial_s").val(); serials = $("#exch_serial_s").val();
serialr = $("#exch_serial_r").val(); serialr = $("#exch_serial_r").val();
break; break;
case 'Serialexchange': case 'Serialexchange':
exchsent = $("#exch_sent").val(); exchsent = $("#exch_sent").val();
exchrcvd = $("#exch_rcvd").val(); exchrcvd = $("#exch_rcvd").val();
serials = $("#exch_serial_s").val(); serials = $("#exch_serial_s").val();
serialr = $("#exch_serial_r").val(); serialr = $("#exch_serial_r").val();
break; break;
case 'Serialgridsquare': case 'Serialgridsquare':
gridr = gridsquare; gridr = gridsquare;
vuccr = vucc; vuccr = vucc;
serials = $("#exch_serial_s").val(); serials = $("#exch_serial_s").val();
serialr = $("#exch_serial_r").val(); serialr = $("#exch_serial_r").val();
break; break;
} }
var data = [[ var data = [[
@ -446,7 +446,7 @@ function logQso() {
} }
$('#name').val(""); $('#name').val("");
$('#callsign').val(""); $('#callsign').val("");
$('#comment').val(""); $('#comment').val("");
$('#exch_rcvd').val(""); $('#exch_rcvd').val("");
@ -455,6 +455,8 @@ function logQso() {
$("#callsign").focus(); $("#callsign").focus();
setSession(formdata); setSession(formdata);
// try setting session data
console.log(sessiondata);
await refresh_qso_table(sessiondata); await refresh_qso_table(sessiondata);
var qTable = $('.qsotable').DataTable(); var qTable = $('.qsotable').DataTable();
qTable.search('').order([0, 'desc']).draw(); qTable.search('').order([0, 'desc']).draw();
@ -470,23 +472,23 @@ async function getSession() {
type: 'post', type: 'post',
}); });
} }
async function restoreContestSession(data) { async function restoreContestSession(data) {
if (data) { if (data) {
if (data.copytodok == "1") { if (data.copytodok == "1") {
$('#copyexchangetodok').prop('checked', true); $('#copyexchangetodok').prop('checked', true);
} }
if (data.contestid != "") { if (data.contestid != "") {
$("#contestname").val(data.contestid); $("#contestname").val(data.contestid);
} }
if (data.exchangetype != "") { if (data.exchangetype != "") {
$("#exchangetype").val(data.exchangetype); $("#exchangetype").val(data.exchangetype);
setExchangetype(data.exchangetype); setExchangetype(data.exchangetype);
setSerial(data); setSerial(data);
} }
if (data.exchangesent != "") { if (data.exchangesent != "") {
$("#exch_sent").val(data.exchangesent); $("#exch_sent").val(data.exchangesent);
} }
@ -500,70 +502,137 @@ async function restoreContestSession(data) {
} }
async function refresh_qso_table(data) { async function refresh_qso_table(data) {
$.ajax({ if (data && data.qso) {
url: base_url + 'index.php/contesting/getSessionQsos', $.ajax({
type: 'post', url: base_url + 'index.php/contesting/getSessionQsos',
data: { 'qso': data.qso, }, type: 'post',
success: function (html) { data: { 'qso': data.qso, },
var mode = ''; success: function (html) {
$(".contest_qso_table_contents").empty(); var mode = '';
$.each(html, function () { $(".contest_qso_table_contents").empty();
if (this.col_submode == null || this.col_submode == '') { $.each(html, function () {
mode = this.col_mode; if (this.col_submode == null || this.col_submode == '') {
} else { mode = this.col_mode;
mode = this.col_submode; } else {
} mode = this.col_submode;
}
$(".qsotable tbody").prepend('<tr>' + $(".qsotable tbody").prepend('<tr>' +
'<td>' + this.col_time_on + '</td>' + '<td>' + this.col_time_on + '</td>' +
'<td>' + this.col_call + '</td>' + '<td>' + this.col_call + '</td>' +
'<td>' + this.col_band + '</td>' + '<td>' + this.col_band + '</td>' +
'<td>' + mode + '</td>' + '<td>' + mode + '</td>' +
'<td>' + this.col_rst_sent + '</td>' + '<td>' + this.col_rst_sent + '</td>' +
'<td>' + this.col_rst_rcvd + '</td>' + '<td>' + this.col_rst_rcvd + '</td>' +
'<td>' + this.col_stx_string + '</td>' + '<td>' + this.col_stx_string + '</td>' +
'<td>' + this.col_srx_string + '</td>' + '<td>' + this.col_srx_string + '</td>' +
'<td>' + this.col_stx + '</td>' + '<td>' + this.col_stx + '</td>' +
'<td>' + this.col_srx + '</td>' + '<td>' + this.col_srx + '</td>' +
'<td>' + this.col_gridsquare + '</td>' + '<td>' + this.col_gridsquare + '</td>' +
'<td>' + this.col_vucc_grids + '</td>' + '<td>' + this.col_vucc_grids + '</td>' +
'</tr>'); '</tr>');
});
if (!$.fn.DataTable.isDataTable('.qsotable')) {
$.fn.dataTable.moment('DD-MM-YYYY HH:mm:ss');
$('.qsotable').DataTable({
"stateSave": true,
"pageLength": 25,
responsive: false,
"scrollY": "400px",
"scrollCollapse": true,
"paging": false,
"scrollX": true,
"language": {
url: getDataTablesLanguageUrl(),
},
order: [0, 'desc'],
"columnDefs": [
{
"render": function ( data, type, row ) {
return pad(row[8],3);
},
"targets" : 8
},
{
"render": function ( data, type, row ) {
return pad(row[9],3);
},
"targets" : 9
}
]
}); });
if (!$.fn.DataTable.isDataTable('.qsotable')) {
$.fn.dataTable.moment('DD-MM-YYYY HH:mm:ss');
$('.qsotable').DataTable({
"stateSave": true,
"pageLength": 25,
responsive: false,
"scrollY": "400px",
"scrollCollapse": true,
"paging": false,
"scrollX": true,
"language": {
url: getDataTablesLanguageUrl(),
},
order: [0, 'desc'],
"columnDefs": [
{
"render": function (data, type, row) {
return pad(row[8], 3);
},
"targets": 8
},
{
"render": function (data, type, row) {
return pad(row[9], 3);
},
"targets": 9
}
]
});
}
} }
} });
}); } else {
// Runs when no session is set usually when its a clean contest
var selectElement = document.getElementById('contestname');
var selected_contest_id = selectElement.options[selectElement.selectedIndex].value;
$.ajax({
url: base_url + 'index.php/contesting/getSessionFreshQsos',
type: 'post',
data: { 'contest_id': selected_contest_id },
success: function (html) {
var mode = '';
$(".contest_qso_table_contents").empty();
$.each(html, function () {
if (this.col_submode == null || this.col_submode == '') {
mode = this.col_mode;
} else {
mode = this.col_submode;
}
$(".qsotable tbody").prepend('<tr>' +
'<td>' + this.col_time_on + '</td>' +
'<td>' + this.col_call + '</td>' +
'<td>' + this.col_band + '</td>' +
'<td>' + mode + '</td>' +
'<td>' + this.col_rst_sent + '</td>' +
'<td>' + this.col_rst_rcvd + '</td>' +
'<td>' + this.col_stx_string + '</td>' +
'<td>' + this.col_srx_string + '</td>' +
'<td>' + this.col_stx + '</td>' +
'<td>' + this.col_srx + '</td>' +
'<td>' + this.col_gridsquare + '</td>' +
'<td>' + this.col_vucc_grids + '</td>' +
'</tr>');
});
if (!$.fn.DataTable.isDataTable('.qsotable')) {
$.fn.dataTable.moment('DD-MM-YYYY HH:mm:ss');
$('.qsotable').DataTable({
"stateSave": true,
"pageLength": 25,
responsive: false,
"scrollY": "400px",
"scrollCollapse": true,
"paging": false,
"scrollX": true,
"language": {
url: getDataTablesLanguageUrl(),
},
order: [0, 'desc'],
"columnDefs": [
{
"render": function (data, type, row) {
return pad(row[8], 3);
},
"targets": 8
},
{
"render": function (data, type, row) {
return pad(row[9], 3);
},
"targets": 9
}
]
});
}
}
});
}
} }
function pad (str, max) { function pad(str, max) {
str = str.toString(); str = str.toString();
return str.length < max ? pad("0" + str, max) : str; return str.length < max ? pad("0" + str, max) : str;
} }
@ -572,12 +641,12 @@ function getUTCTimeStamp(el) {
var now = new Date(); var now = new Date();
var localTime = now.getTime(); var localTime = now.getTime();
var utc = localTime + (now.getTimezoneOffset() * 60000); var utc = localTime + (now.getTimezoneOffset() * 60000);
$(el).attr('value', ("0" + now.getUTCHours()).slice(-2)+':'+("0" + now.getUTCMinutes()).slice(-2)+':'+("0" + now.getUTCSeconds()).slice(-2)); $(el).attr('value', ("0" + now.getUTCHours()).slice(-2) + ':' + ("0" + now.getUTCMinutes()).slice(-2) + ':' + ("0" + now.getUTCSeconds()).slice(-2));
} }
function getUTCDateStamp(el) { function getUTCDateStamp(el) {
var now = new Date(); var now = new Date();
var localTime = now.getTime(); var localTime = now.getTime();
var utc = localTime + (now.getTimezoneOffset() * 60000); var utc = localTime + (now.getTimezoneOffset() * 60000);
$(el).attr('value', ("0" + now.getUTCDate()).slice(-2)+'-'+("0" + (now.getUTCMonth()+1)).slice(-2)+'-'+now.getUTCFullYear()); $(el).attr('value', ("0" + now.getUTCDate()).slice(-2) + '-' + ("0" + (now.getUTCMonth() + 1)).slice(-2) + '-' + now.getUTCFullYear());
} }