[Contest logging] Moved contest session from local storage to database

这个提交包含在:
Andreas 2023-04-10 18:54:24 +02:00
父节点 853720592b
当前提交 b481fdbb38
共有 5 个文件被更改,包括 320 次插入175 次删除

查看文件

@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
| be upgraded / downgraded to. | be upgraded / downgraded to.
| |
*/ */
$config['migration_version'] = 116; $config['migration_version'] = 117;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

查看文件

@ -42,17 +42,39 @@ class Contesting extends CI_Controller {
} }
public function getSessionQsos() { public function getSessionQsos() {
//load model
$this->load->model('Contesting_model'); $this->load->model('Contesting_model');
$qso = $this->input->post('qso'); $qso = $this->input->post('qso');
// get QSOs to fill the table header('Content-Type: application/json');
$data = $this->Contesting_model->getSessionQsos($qso); echo json_encode($this->Contesting_model->getSessionQsos($qso));
}
public function getSession() {
$this->load->model('Contesting_model');
header('Content-Type: application/json');
echo json_encode($this->Contesting_model->getSession());
}
public function deleteSession() {
$this->load->model('Contesting_model');
$qso = $this->input->post('qso');
$data = $this->Contesting_model->deleteSession($qso);
return json_encode($data); return json_encode($data);
} }
public function setSession() {
$this->load->model('Contesting_model');
$this->Contesting_model->setSession();
return json_encode("ok");
}
public function create() { public function create() {
$this->load->model('Contesting_model'); $this->load->model('Contesting_model');
$this->load->library('form_validation'); $this->load->library('form_validation');
@ -161,10 +183,10 @@ class Contesting extends CI_Controller {
$band = $this->input->post('band'); $band = $this->input->post('band');
$mode = $this->input->post('mode'); $mode = $this->input->post('mode');
$contest = $this->input->post('contest'); $contest = $this->input->post('contest');
$qso = $this->input->post('qso');
$this->load->model('Contesting_model'); $this->load->model('Contesting_model');
$result = $this->Contesting_model->checkIfWorkedBefore($call, $band, $mode, $contest, $qso);
$result = $this->Contesting_model->checkIfWorkedBefore($call, $band, $mode, $contest);
header('Content-Type: application/json'); header('Content-Type: application/json');
if ($result->num_rows()) { if ($result->num_rows()) {

查看文件

@ -0,0 +1,69 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Migration_add_contest_session_table extends CI_Migration
{
public function up()
{
if (!$this->db->table_exists('contest_session')) {
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => 20,
'unsigned' => TRUE,
'auto_increment' => TRUE,
'unique' => TRUE
),
'contestid' => array(
'type' => 'VARCHAR',
'constraint' => 100,
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'exchangetype' => array(
'type' => 'VARCHAR',
'constraint' => 20,
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'exchangesent' => array(
'type' => 'VARCHAR',
'constraint' => 20,
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'serialsent' => array(
'type' => 'VARCHAR',
'constraint' => 20,
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'copytodok' => array(
'type' => 'bigint',
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'qso' => array(
'type' => 'VARCHAR',
'constraint' => 100,
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'station_id' => array(
'type' => 'bigint',
'unsigned' => TRUE,
'auto_increment' => FALSE
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('contest_session');
}
}
public function down()
{
$this->dbforge->drop_table('contest_session');
}
}

查看文件

@ -26,8 +26,78 @@ class Contesting_model extends CI_Model {
" ORDER BY COL_PRIMARY_KEY ASC"; " ORDER BY COL_PRIMARY_KEY ASC";
$data = $this->db->query($sql); $data = $this->db->query($sql);
header('Content-Type: application/json'); return $data->result();
echo json_encode($data->result()); }
function getSession() {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$sql = "SELECT * from contest_session where station_id = " . $station_id;
$data = $this->db->query($sql);
return $data->row();
}
function deleteSession() {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$sql = "delete from contest_session where station_id = " . $station_id;
$this->db->query($sql);
return;
}
function setSession() {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$qso = "";
if ($this->input->post('callsign')) {
$qso = xss_clean($this->input->post('start_date', true)) . ' ' . xss_clean($this->input->post('start_time', true)) . ',' . xss_clean($this->input->post('callsign', true)) . ',' . xss_clean($this->input->post('contestname', true));
}
$data = array(
'contestid' => xss_clean($this->input->post('contestname', true)),
'exchangetype' => xss_clean($this->input->post('exchangetype', true)),
'exchangesent' => xss_clean($this->input->post('exch_sent', true)),
'serialsent' => xss_clean($this->input->post('exch_serial_s', true)),
'copytodok' => xss_clean($this->input->post('copyexchangetodok', true)),
'qso' => $qso,
'station_id' => $station_id,
);
$sql = "SELECT * from contest_session where station_id = " . $station_id;
$querydata = $this->db->query($sql);
if ($querydata->num_rows() == 0) {
$this->db->insert('contest_session', $data);
return;
}
$result = $querydata->row();
if ($result->qso != "") {
$data['qso'] = $result->qso;
}
$this->updateSession($data, $station_id);
return;
}
function updateSession($data, $station_id) {
$this->db->where('station_id', $station_id);
$this->db->update('contest_session', $data);
} }
function getActivecontests() { function getActivecontests() {
@ -137,12 +207,15 @@ class Contesting_model extends CI_Model {
return true; return true;
} }
function checkIfWorkedBefore($call, $band, $mode, $contest, $qso) { function checkIfWorkedBefore($call, $band, $mode, $contest) {
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('Stations'); $CI->load->model('Stations');
$station_id = $CI->Stations->find_active(); $station_id = $CI->Stations->find_active();
$qsoarray = explode(',', $qso); $contest_session = $this->getSession();
if ($contest_session) {
$qsoarray = explode(',', $contest_session->qso);
$date = DateTime::createFromFormat('d-m-Y H:i:s', $qsoarray[0]); $date = DateTime::createFromFormat('d-m-Y H:i:s', $qsoarray[0]);
$date = $date->format('Y-m-d H:i:s'); $date = $date->format('Y-m-d H:i:s');
@ -160,4 +233,6 @@ class Contesting_model extends CI_Model {
return $query; return $query;
} }
return;
}
} }

查看文件

@ -2,11 +2,11 @@
$("#callsign").focus(); $("#callsign").focus();
$(document).ready(function () { $(document).ready(function () {
restoreContestSession(); getSession().done(restoreContestSession);
setRst($("#mode").val()); setRst($("#mode").val());
}); });
// This erases the contest logging session which is stored in localStorage // Resets the logging form and deletes session from database
function reset_contest_session() { function reset_contest_session() {
$('#name').val(""); $('#name').val("");
$('.callsign-suggestions').text(""); $('.callsign-suggestions').text("");
@ -18,7 +18,6 @@ function reset_contest_session() {
$('#exch_sent').val(""); $('#exch_sent').val("");
$('#exch_rcvd').val(""); $('#exch_rcvd').val("");
$("#exch_gridsquare_r").val(""); $("#exch_gridsquare_r").val("");
$("#exch_gridsquare_s").val("");
$("#callsign").focus(); $("#callsign").focus();
setRst($("#mode").val()); setRst($("#mode").val());
@ -28,28 +27,42 @@ function reset_contest_session() {
$(".contest_qso_table_contents").empty(); $(".contest_qso_table_contents").empty();
$('#copyexchangetodok').prop('checked', false); $('#copyexchangetodok').prop('checked', false);
localStorage.removeItem("contestid"); $.ajax({
localStorage.removeItem("exchangetype"); url: base_url + 'index.php/contesting/deleteSession',
localStorage.removeItem("qso"); type: 'post',
localStorage.removeItem("exchangereceived"); success: function (data) {
localStorage.removeItem("exchangesent");
localStorage.removeItem("serialreceived"); }
localStorage.removeItem("serialsent"); });
localStorage.removeItem("gridsquarereceived");
localStorage.removeItem("gridsquaresent");
localStorage.removeItem("copytodok");
} }
// Storing the contestid in contest session // Storing the contestid in contest session
$('#contestname').change(function () { $('#contestname').change(function () {
localStorage.setItem("contestid", $("#contestname").val()); var formdata = new FormData(document.getElementById("qso_input"));
setSession(formdata);
}); });
// Storing the exchange type in contest session // Storing the exchange type in contest session
$('#exchangetype').change(function () { $('#exchangetype').change(function () {
localStorage.setItem("exchangetype", $('#exchangetype').val()); var exchangetype = $("#exchangetype").val();
var formdata = new FormData(document.getElementById("qso_input"));
setSession(formdata);
setExchangetype(exchangetype);
}); });
function setSession(formdata) {
$.ajax({
url: base_url + 'index.php/contesting/setSession',
type: 'post',
data: formdata,
processData: false,
contentType: false,
success: function (data) {
}
});
}
// realtime clock // realtime clock
if ( ! manual ) { if ( ! manual ) {
$(function ($) { $(function ($) {
@ -212,16 +225,17 @@ $("#callsign").keyup(function () {
}); });
function checkIfWorkedBefore() { function checkIfWorkedBefore() {
var call = $("#callsign").val();
if (call.length >= 3) {
$('#callsign_info').text(""); $('#callsign_info').text("");
$.ajax({ $.ajax({
url: base_url + 'index.php/contesting/checkIfWorkedBefore', url: base_url + 'index.php/contesting/checkIfWorkedBefore',
type: 'post', type: 'post',
data: { data: {
'call': $("#callsign").val(), 'call': call,
'mode': $("#mode").val(), 'mode': $("#mode").val(),
'band': $("#band").val(), 'band': $("#band").val(),
'contest': $("#contestname").val(), 'contest': $("#contestname").val()
'qso': localStorage.getItem("qso")
}, },
success: function (result) { success: function (result) {
if (result.message == 'Worked before') { if (result.message == 'Worked before') {
@ -229,6 +243,7 @@ function checkIfWorkedBefore() {
} }
} }
}); });
}
} }
function reset_log_fields() { function reset_log_fields() {
@ -295,12 +310,16 @@ $('#band').change(function () {
checkIfWorkedBefore(); checkIfWorkedBefore();
}); });
$('#exchangetype').change(function () { function setSerial(data) {
var exchangetype = $("#exchangetype").val(); var serialsent = 1;
setExchangetype(exchangetype); if (data.serialsent != "") {
}); serialsent = data.serialsent;
}
$("#exch_serial_s").val(serialsent);
}
function setExchangetype(exchangetype) { function setExchangetype(exchangetype) {
getSession().done(setSerial);
// Perhaps a better approach is to hide everything, then just enable the things you need // Perhaps a better approach is to hide everything, then just enable the things you need
$(".exchanger").hide(); $(".exchanger").hide();
$(".exchanges").hide(); $(".exchanges").hide();
@ -310,29 +329,21 @@ function setExchangetype(exchangetype) {
$(".gridsquares").hide(); $(".gridsquares").hide();
$("#exch_serial_s").val(""); $("#exch_serial_s").val("");
var serialsent = localStorage.getItem("serialsent");
if (serialsent == null) {
serialsent = 1;
}
if (exchangetype == 'Exchange') { if (exchangetype == 'Exchange') {
$(".exchanger").show(); $(".exchanger").show();
$(".exchanges").show(); $(".exchanges").show();
} }
else if (exchangetype == 'Serial') { else if (exchangetype == 'Serial') {
$("#exch_serial_s").val(serialsent);
$(".serials").show(); $(".serials").show();
$(".serialr").show(); $(".serialr").show();
} }
else if (exchangetype == 'Serialexchange') { else if (exchangetype == 'Serialexchange') {
$("#exch_serial_s").val(serialsent);
$(".exchanger").show(); $(".exchanger").show();
$(".exchanges").show(); $(".exchanges").show();
$(".serials").show(); $(".serials").show();
$(".serialr").show(); $(".serialr").show();
} }
else if (exchangetype == 'Serialgridsquare') { else if (exchangetype == 'Serialgridsquare') {
$("#exch_serial_s").val(serialsent);
$(".serials").show(); $(".serials").show();
$(".serialr").show(); $(".serialr").show();
$(".gridsquarer").show(); $(".gridsquarer").show();
@ -428,10 +439,7 @@ function logQso() {
contentType: false, contentType: false,
enctype: 'multipart/form-data', enctype: 'multipart/form-data',
success: function (html) { success: function (html) {
if (localStorage.getItem("qso") == null) { setSession(formdata);
localStorage.setItem("qso", $("#start_date").val() + ' ' + $("#start_time").val() + ',' + $("#callsign").val().toUpperCase() + ',' + $("#contestname").val());
}
$('#name').val(""); $('#name').val("");
$('#callsign').val(""); $('#callsign').val("");
@ -445,17 +453,6 @@ function logQso() {
} }
$("#callsign").focus(); $("#callsign").focus();
// Store contest session
localStorage.setItem("contestid", $("#contestname").val());
localStorage.setItem("exchangetype", $("#exchangetype").val());
localStorage.setItem("exchangereceived", $("#exch_rcvd").val().toUpperCase());
localStorage.setItem("exchangesent", $("#exch_sent").val().toUpperCase());
localStorage.setItem("serialreceived", $("#exch_serial_r").val());
localStorage.setItem("serialsent", $("#exch_serial_s").val());
localStorage.setItem("gridsquarereceived", $("#exch_gridsquare_r").val());
localStorage.setItem("gridsquaresent", $("#exch_gridsquare_s").val());
localStorage.setItem("copytodok", $('#copyexchangetodok').is(":checked"));
var qTable = $('.qsotable').DataTable(); var qTable = $('.qsotable').DataTable();
qTable.search('').draw(); qTable.search('').draw();
} }
@ -463,60 +460,41 @@ function logQso() {
} }
} }
// We are restoring the settings in the contest logging form here function getSession() {
function restoreContestSession() { return $.ajax({
var dokcopy = localStorage.getItem("copytodok"); url: base_url + 'index.php/contesting/getSession',
if (dokcopy != null) { type: 'post',
});
}
function restoreContestSession(data) {
if (data) {
if (data.copytodok == "1") {
$('#copyexchangetodok').prop('checked', true); $('#copyexchangetodok').prop('checked', true);
} }
var contestname = localStorage.getItem("contestid"); if (data.contestid != "") {
if (contestname != null) { $("#contestname").val(data.contestid);
$("#contestname").val(contestname);
} }
var exchangetype = localStorage.getItem("exchangetype"); if (data.exchangetype != "") {
if (exchangetype != null) { $("#exchangetype").val(data.exchangetype);
$("#exchangetype").val(exchangetype); setExchangetype(data.exchangetype);
setExchangetype(exchangetype);
} }
var exchangereceived = localStorage.getItem("exchangereceived"); if (data.exchangesent != "") {
if (exchangereceived != null) { $("#exch_sent").val(data.exchangesent);
$("#exch_rcvd").val(exchangereceived);
} }
var exchangesent = localStorage.getItem("exchangesent"); if (data.serialsent != "") {
if (exchangesent != null) { $("#exch_serial_s").val(data.serialsent);
$("#exch_sent").val(exchangesent);
} }
var serialreceived = localStorage.getItem("serialreceived"); if (data.qso != "") {
if (serialreceived != null) {
$("#exch_serial_r").val(serialreceived);
}
var serialsent = localStorage.getItem("serialsent");
if (serialsent != null) {
$("#exch_serial_s").val(serialsent);
}
var gridsquarereceived = localStorage.getItem("gridsquarereceived");
if (gridsquarereceived != null) {
$("#exch_gridsquare_r").val(gridsquarereceived);
}
var gridsquaresent = localStorage.getItem("gridsquaresent");
if (gridsquaresent != null) {
$("#exch_gridsquare_s").val(gridsquaresent);
}
if (localStorage.getItem("qso") != null) {
var qsodata = localStorage.getItem("qso");
$.ajax({ $.ajax({
url: base_url + 'index.php/contesting/getSessionQsos', url: base_url + 'index.php/contesting/getSessionQsos',
type: 'post', type: 'post',
data: { 'qso': qsodata, }, data: { 'qso': data.qso, },
success: function (html) { success: function (html) {
var mode = ''; var mode = '';
@ -557,4 +535,5 @@ function restoreContestSession() {
} }
}); });
} }
}
} }