From 545d858bc685c938423af7220b24d4a6646e9ab2 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 8 Nov 2025 21:08:51 +0100 Subject: [PATCH] Tweaked UI and distance update --- application/controllers/Logbookadvanced.php | 3 +- application/models/Logbookadvanced_model.php | 38 ++++++++++++-------- assets/js/sections/logbookadvanced.js | 34 ++++++++++++------ 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 5be2f26e5..238010819 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -818,6 +818,7 @@ class Logbookadvanced extends CI_Controller { $this->load->model('logbookadvanced_model'); $result = $this->logbookadvanced_model->update_distances_batch(); - return $result; + header("Content-Type: application/json"); + print json_encode($result); } } diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index e0c95be8c..62966b865 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -1260,30 +1260,40 @@ class Logbookadvanced_model extends CI_Model { public function update_distances_batch() { ini_set('memory_limit', '-1'); - $sql = "SELECT COL_PRIMARY_KEY, station_profile.station_gridsquare, COL_GRIDSQUARE, COL_VUCC_GRIDS FROM " . $this->config->item('table_name') . " + $sql = "SELECT COL_DISTANCE, COL_PRIMARY_KEY, station_profile.station_gridsquare, COL_GRIDSQUARE, COL_VUCC_GRIDS FROM " . $this->config->item('table_name') . " JOIN station_profile on " . $this->config->item('table_name') . ".station_id = station_profile.station_id WHERE COL_GRIDSQUARE is NOT NULL - AND (COL_GRIDSQUARE != '' OR COL_GRIDSQUARE is null) - AND station_profile.user_id = ?"; + AND COL_GRIDSQUARE != '' + AND station_profile.user_id = ? + AND (COL_DISTANCE = '' or COL_DISTANCE is NULL) + and COL_GRIDSQUARE != station_gridsquare"; $query = $this->db->query($sql, array($this->session->userdata('user_id'))); - if ($query->num_rows() > 0) { - if (!$this->load->is_loaded('Qra')) { - $this->load->library('Qra'); - } + $recordcount = $query->num_rows(); + + if ($recordcount > 0) { + $this->load->library('Qra'); + + $updates = []; foreach ($query->result() as $row) { - $ant_path = $row->COL_ANT_PATH ?? null; - $distance = $this->qra->distance($row->station_gridsquare, $row->COL_GRIDSQUARE, 'K', $ant_path); - $data = array( - 'COL_DISTANCE' => $distance, + $distance = $this->qra->distance( + $row->station_gridsquare, + $row->COL_GRIDSQUARE, + 'K' ); - $this->db->where(array('COL_PRIMARY_KEY' => $row->COL_PRIMARY_KEY)); - $this->db->update($this->config->item('table_name'), $data); + $updates[] = [ + 'COL_PRIMARY_KEY' => $row->COL_PRIMARY_KEY, + 'COL_DISTANCE' => $distance, + ]; + } + + if (!empty($updates)) { + $this->db->update_batch($this->config->item('table_name'), $updates, 'COL_PRIMARY_KEY'); } } - return true; + return $recordcount; } } diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index fe16fffe7..c0f37506b 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -1119,10 +1119,11 @@ $(document).ready(function () { message: html, buttons: [ { - label: lang_gen_advanced_logbook_update_now, - cssClass: 'btn btn-sm btn-primary', + label: lang_gen_advanced_logbook_update_now + '
', + cssClass: 'btn btn-sm btn-primary ld-ext-right', + id: 'updateContinentButton', action: function (dialogItself) { - runContinentFix(); + runContinentFix(dialogItself); } }, { @@ -1138,18 +1139,24 @@ $(document).ready(function () { }); }); - function runContinentFix() { + function runContinentFix(dialogItself) { + $('#updateContinentButton').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); $.ajax({ url: base_url + 'index.php/logbookadvanced/fixContinent', type: 'POST', success: function (response) { + $('#updateContinentButton').prop("disabled", false).removeClass("running"); + dialogItself.close(); BootstrapDialog.alert({ title: lang_gen_advanced_logbook_success, - message: lang_gen_advanced_logbook_continents_updated + ' ' + response.updated + ' ' + lang_gen_advanced_logbook_records_updated, + message: lang_gen_advanced_logbook_continents_updated + ' ' + response + ' ' + lang_gen_advanced_logbook_records_updated, type: BootstrapDialog.TYPE_SUCCESS }); }, error: function () { + $('#updateContinentButton').prop("disabled", false).removeClass("running"); + dialogItself.close(); BootstrapDialog.alert({ title: lang_gen_advanced_logbook_error, message: lang_gen_advanced_logbook_problem_fixing_continents, @@ -1172,10 +1179,11 @@ $(document).ready(function () { message: html, buttons: [ { - label: lang_gen_advanced_logbook_update_now, - cssClass: 'btn btn-sm btn-primary', + label: lang_gen_advanced_logbook_update_now + '
', + cssClass: 'btn btn-sm btn-primary ld-ext-right', + id: 'updateDistanceButton', action: function (dialogItself) { - runUpdateDistancesFix(); + runUpdateDistancesFix(dialogItself); } }, { @@ -1191,18 +1199,24 @@ $(document).ready(function () { }); }); - function runUpdateDistancesFix() { + function runUpdateDistancesFix(dialogItself) { + $('#updateDistanceButton').prop("disabled", true).addClass("running"); + $('#closeButton').prop("disabled", true); $.ajax({ url: base_url + 'index.php/logbookadvanced/updateDistances', type: 'POST', success: function (response) { + $('#updateDistanceButton').prop("disabled", false).removeClass("running"); + dialogItself.close(); BootstrapDialog.alert({ title: lang_gen_advanced_logbook_success, - message: lang_gen_advanced_logbook_distances_updated, + message: lang_gen_advanced_logbook_distances_updated + ' ' + response + ' ' + lang_gen_advanced_logbook_records_updated, type: BootstrapDialog.TYPE_SUCCESS }); }, error: function () { + $('#updateDistanceButton').prop("disabled", false).removeClass("running"); + dialogItself.close(); BootstrapDialog.alert({ title: lang_gen_advanced_logbook_error, message: lang_gen_advanced_logbook_problem_updating_distances,