From e13198e3c09e899240cb3c163ca0571c77228ece Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 7 Nov 2024 15:28:03 +0100 Subject: [PATCH 1/6] Add unit to table (and keep sorting functionalities) --- application/views/distancerecords/index.php | 4 ++-- application/views/interface_assets/footer.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/application/views/distancerecords/index.php b/application/views/distancerecords/index.php index 4df552d0a..27126ec58 100644 --- a/application/views/distancerecords/index.php +++ b/application/views/distancerecords/index.php @@ -12,7 +12,7 @@ - + @@ -31,7 +31,7 @@ sat; ?> - distance)); ?> + distance)); ?> km time ?? ''); echo date($custom_date_format, $timestamp); ?> time ?? ''); echo date('H:i', $timestamp); ?> callsign; ?> diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 82f41c116..f417bf8f2 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2633,7 +2633,15 @@ function viewEqsl(picture, callsign) { "pageLength": 25, responsive: false, ordering: true, - "columnDefs": [ 2, 'num' ], + "columnDefs": [ + { + 2: 'num' + }, + { + "targets": $(".distance-column-sort").index(), + "type": "distance", + } + ], "scrollCollapse": true, "paging": false, "scrollX": true, @@ -2652,6 +2660,10 @@ function viewEqsl(picture, callsign) { } ] }); + $.fn.dataTable.ext.type.order['distance-pre'] = function(data) { + var num = parseFloat(data); + return isNaN(num) ? 0 : num; + }; // change color of csv-button if dark mode is chosen if (isDarkModeTheme()) { $('[class*="buttons"]').css("color", "white"); From 864206392b2244832834e93c14f2aac3c281bc56 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 7 Nov 2024 17:25:04 +0100 Subject: [PATCH 2/6] Make sorting work ... (order of functions is important) --- application/views/interface_assets/footer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index f417bf8f2..a7cc6494f 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2629,6 +2629,10 @@ function viewEqsl(picture, callsign) { dt.search('').draw(); } }; + $.fn.dataTable.ext.type.order['distance-pre'] = function(data) { + var num = parseFloat(data); + return isNaN(num) ? 0 : num; + }; $('#distrectable').DataTable({ "pageLength": 25, responsive: false, @@ -2660,10 +2664,6 @@ function viewEqsl(picture, callsign) { } ] }); - $.fn.dataTable.ext.type.order['distance-pre'] = function(data) { - var num = parseFloat(data); - return isNaN(num) ? 0 : num; - }; // change color of csv-button if dark mode is chosen if (isDarkModeTheme()) { $('[class*="buttons"]').css("color", "white"); From af5c6eba97fb5c8d1382fa0abe46f44b8619c317 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 7 Nov 2024 18:17:16 +0100 Subject: [PATCH 3/6] Set measurement unit based on user prefs --- application/controllers/Distancerecords.php | 27 +++++++++++++++++++++ application/views/distancerecords/index.php | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/application/controllers/Distancerecords.php b/application/controllers/Distancerecords.php index 54711d2dc..fec4a228b 100644 --- a/application/controllers/Distancerecords.php +++ b/application/controllers/Distancerecords.php @@ -33,6 +33,31 @@ class Distancerecords extends CI_Controller { case 'M d, y': $usethisformat = 'MMM D, YY';break; } + if ($this->session->userdata('user_measurement_base') == NULL) { + $measurement_base = $this->config->item('measurement_base'); + } else { + $measurement_base = $this->session->userdata('user_measurement_base'); + } + + switch ($measurement_base) { + case 'M': + $unit = "mi"; + $factor = 0.621371; + break; + case 'K': + $unit = "km"; + $factor = 1; + break; + case 'N': + $unit = "nmi"; + $factor = 0.539957; + break; + default: + $unit = "km"; + $factor = 1; + break; + } + $data['scripts'] = [ 'assets/js/sections/distancerecords.js', ]; @@ -41,6 +66,8 @@ class Distancerecords extends CI_Controller { $data['custom_date_format'] = $custom_date_format; $data['page_title'] = __("Satellite Distance Records"); $data['distances'] = $this->distancerecords_model->get_records(); + $data['factor'] = $factor; + $data['unit'] = $unit; $footerData['usethisformat'] = $usethisformat; diff --git a/application/views/distancerecords/index.php b/application/views/distancerecords/index.php index 27126ec58..4cc966511 100644 --- a/application/views/distancerecords/index.php +++ b/application/views/distancerecords/index.php @@ -31,7 +31,7 @@ sat; ?> - distance)); ?> km + distance) * $factor)); echo ' '.$unit; ?> time ?? ''); echo date($custom_date_format, $timestamp); ?> time ?? ''); echo date('H:i', $timestamp); ?> callsign; ?> From 14f651d48f4ac503396d39c02e8cca30ad4e32c9 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 7 Nov 2024 20:09:22 +0100 Subject: [PATCH 4/6] Keep row number on (re-)sorting --- application/views/interface_assets/footer.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index a7cc6494f..48b1187c4 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2633,6 +2633,15 @@ function viewEqsl(picture, callsign) { var num = parseFloat(data); return isNaN(num) ? 0 : num; }; + $('#distrectable').on('order.dt search.dt', function() { + var disttable = $('#distrectable').DataTable(); + let i = 1; + disttable + .cells(null, 0, { search: 'applied', order: 'applied' }) + .every(function (cell) { + this.data(i++); + }); + }); $('#distrectable').DataTable({ "pageLength": 25, responsive: false, From 0d0af4655c788ab259d69b4d35001359ed4c0cfb Mon Sep 17 00:00:00 2001 From: phl0 Date: Fri, 8 Nov 2024 08:40:58 +0100 Subject: [PATCH 5/6] Also show my gridsquare --- application/models/Distancerecords_model.php | 14 ++++++++------ application/views/distancerecords/index.php | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/application/models/Distancerecords_model.php b/application/models/Distancerecords_model.php index 4947450a4..cb96bdb3e 100644 --- a/application/models/Distancerecords_model.php +++ b/application/models/Distancerecords_model.php @@ -20,7 +20,7 @@ class Distancerecords_model extends CI_Model { if (!$logbooks_locations_array) { return null; } - $sql = 'SELECT t1.sat, t1.distance, t2.COL_TIME_ON AS time, t2.COL_CALL AS callsign, t2.COL_GRIDSQUARE AS grid, t2.COL_MODE AS mode, t2.COL_PRIMARY_KEY AS primarykey + $sql = 'SELECT t1.sat, t1.distance, t2.COL_TIME_ON AS time, t2.COL_CALL AS callsign, t2.COL_GRIDSQUARE AS grid, t2.COL_MODE AS mode, t2.COL_PRIMARY_KEY AS primarykey, t2.station_gridsquare AS mygrid FROM ( SELECT MAX(col_distance) AS distance, COL_SAT_NAME AS sat FROM '.$this->config->item('table_name').' @@ -29,9 +29,10 @@ class Distancerecords_model extends CI_Model { GROUP BY col_sat_name ) t1 LEFT JOIN ( - SELECT *, ROW_NUMBER() OVER (PARTITION BY COL_SAT_NAME, COL_DISTANCE ORDER BY COL_TIME_ON asc) AS rn + SELECT COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_GRIDSQUARE, COL_MODE, COL_SAT_NAME, COL_DISTANCE, station_gridsquare, ROW_NUMBER() OVER (PARTITION BY COL_SAT_NAME, COL_DISTANCE ORDER BY COL_TIME_ON asc) AS rn FROM '.$this->config->item('table_name').' - WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') + LEFT JOIN station_profile ON station_profile.station_id = '.$this->config->item('table_name').'.station_id + WHERE '.$this->config->item('table_name').'.station_id IN ('.implode(', ', $logbooks_locations_array).') ) t2 ON t1.sat = t2.COL_SAT_NAME AND t1.distance = t2.COL_DISTANCE @@ -64,9 +65,10 @@ class Distancerecords_model extends CI_Model { // With that query for oldest QSO per sat and distance foreach ($query->result() as $row) { $bindings=[]; - $subsql = 'SELECT COL_SAT_NAME AS sat, COL_TIME_ON as time, COL_CALL as callsign, COL_GRIDSQUARE as grid, COL_MODE AS mode, COL_PRIMARY_KEY as primarykey + $subsql = 'SELECT COL_SAT_NAME AS sat, COL_TIME_ON as time, COL_CALL as callsign, COL_GRIDSQUARE as grid, station_profile.station_gridsquare AS mygrid, COL_MODE AS mode, COL_PRIMARY_KEY as primarykey FROM '.$this->config->item('table_name').' - WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') + LEFT JOIN station_profile ON station_profile.station_id = '.$this->config->item('table_name').'.station_id + WHERE '.$this->config->item('table_name').'.station_id IN ('.implode(', ', $logbooks_locations_array).') AND COL_SAT_NAME = ? AND COL_DISTANCE = ? ORDER BY COL_TIME_ON ASC LIMIT 1;'; @@ -74,7 +76,7 @@ class Distancerecords_model extends CI_Model { $bindings[]=$row->distance; $subquery = $this->db->query($subsql, $bindings); $subrow = $subquery->row(); - array_push($result, (object) ["sat" => $row->sat, "distance" => $row->distance, "time" => $subrow->time, "primarykey" => $subrow->primarykey, "callsign" => $subrow->callsign, "mode" => $subrow->mode, "grid" => $subrow->grid]); + array_push($result, (object) ["sat" => $row->sat, "distance" => $row->distance, "time" => $subrow->time, "primarykey" => $subrow->primarykey, "callsign" => $subrow->callsign, "mode" => $subrow->mode, "grid" => $subrow->grid, "mygrid" => $subrow->mygrid]); } return($result); } diff --git a/application/views/distancerecords/index.php b/application/views/distancerecords/index.php index 4cc966511..6645e1c3a 100644 --- a/application/views/distancerecords/index.php +++ b/application/views/distancerecords/index.php @@ -17,7 +17,8 @@ - + + @@ -36,6 +37,7 @@ time ?? ''); echo date('H:i', $timestamp); ?> callsign; ?> mode; ?> + mygrid; ?> grid; ?> Date: Fri, 8 Nov 2024 09:01:27 +0100 Subject: [PATCH 6/6] Exclude bogus QSO data --- application/models/Distancerecords_model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/application/models/Distancerecords_model.php b/application/models/Distancerecords_model.php index cb96bdb3e..e614591be 100644 --- a/application/models/Distancerecords_model.php +++ b/application/models/Distancerecords_model.php @@ -26,6 +26,8 @@ class Distancerecords_model extends CI_Model { FROM '.$this->config->item('table_name').' WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') AND COALESCE(COL_SAT_NAME, "") <> "" + AND COL_DISTANCE IS NOT NULL + AND COL_GRIDSQUARE IS NOT NULL GROUP BY col_sat_name ) t1 LEFT JOIN ( @@ -56,6 +58,8 @@ class Distancerecords_model extends CI_Model { FROM '.$this->config->item('table_name').' WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') AND COALESCE(COL_SAT_NAME, "") <> "" + AND COL_DISTANCE IS NOT NULL + AND COL_GRIDSQUARE IS NOT NULL GROUP BY col_sat_name ORDER BY distance DESC;'; $query = $this->db->query($sql);