mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Merged two API calls into one
This commit is contained in:
@@ -79,59 +79,4 @@ class Bandmap extends CI_Controller {
|
||||
}
|
||||
|
||||
// Get user's active bands and modes/submodes
|
||||
function get_user_bands_and_modes() {
|
||||
session_write_close();
|
||||
|
||||
$this->load->model('bands');
|
||||
$this->load->model('usermodes');
|
||||
|
||||
// Get active bands
|
||||
$activeBands = $this->bands->get_user_bands_for_qso_entry(false); // false = only active
|
||||
$bandList = [];
|
||||
|
||||
if (is_array($activeBands)) {
|
||||
foreach ($activeBands as $group => $bands) {
|
||||
if (is_array($bands)) {
|
||||
foreach ($bands as $band) {
|
||||
$bandList[] = $band;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get active modes (user-specific) and categorize them
|
||||
$activeModes = $this->usermodes->active();
|
||||
$modeCategories = [
|
||||
'cw' => false,
|
||||
'phone' => false,
|
||||
'digi' => false
|
||||
];
|
||||
$submodes = []; // List of all enabled submodes
|
||||
|
||||
if ($activeModes) {
|
||||
foreach ($activeModes as $mode) {
|
||||
$qrgmode = strtoupper($mode->qrgmode ?? '');
|
||||
if ($qrgmode === 'CW') {
|
||||
$modeCategories['cw'] = true;
|
||||
} elseif ($qrgmode === 'SSB') {
|
||||
$modeCategories['phone'] = true;
|
||||
} elseif ($qrgmode === 'DATA') {
|
||||
$modeCategories['digi'] = true;
|
||||
}
|
||||
|
||||
// Build submode identifier - use submode if available, otherwise just mode
|
||||
$submode = !empty($mode->submode) ? $mode->submode : $mode->mode;
|
||||
if (!empty($submode) && !in_array($submode, $submodes)) {
|
||||
$submodes[] = $submode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'bands' => $bandList,
|
||||
'modes' => $modeCategories,
|
||||
'submodes' => $submodes
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,24 +87,6 @@ class User_Options extends CI_Controller {
|
||||
echo json_encode($jsonout);
|
||||
}
|
||||
|
||||
public function get_dxcluster_fav() {
|
||||
$result = $this->user_options_model->get_options('DXClusterFavourite');
|
||||
$jsonout = [];
|
||||
foreach($result->result() as $options) {
|
||||
$value = $options->option_value;
|
||||
// Try to decode JSON arrays - check if it looks like JSON first
|
||||
if (is_string($value) && (strpos($value, '[') === 0 || strpos($value, '{') === 0)) {
|
||||
$decoded = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$value = $decoded;
|
||||
}
|
||||
}
|
||||
$jsonout[$options->option_name][$options->option_key] = $value;
|
||||
}
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($jsonout);
|
||||
}
|
||||
|
||||
public function del_dxcluster_fav() {
|
||||
$obj = json_decode(file_get_contents("php://input"), true);
|
||||
if ($obj['option_name'] ?? '' != '') {
|
||||
@@ -130,7 +112,75 @@ class User_Options extends CI_Controller {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($qrg_units);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combined endpoint: DX Cluster favorites + user bands/modes settings
|
||||
* Returns both favorites and user configuration in a single request
|
||||
*/
|
||||
public function get_dxcluster_user_favs_and_settings() {
|
||||
session_write_close();
|
||||
|
||||
// Get DX Cluster favorites
|
||||
$result = $this->user_options_model->get_options('DXClusterFavourite');
|
||||
$favorites = [];
|
||||
foreach($result->result() as $options) {
|
||||
$value = $options->option_value;
|
||||
if (is_string($value) && (strpos($value, '[') === 0 || strpos($value, '{') === 0)) {
|
||||
$decoded = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$value = $decoded;
|
||||
}
|
||||
}
|
||||
$favorites[$options->option_name][$options->option_key] = $value;
|
||||
}
|
||||
|
||||
// Get user bands and modes
|
||||
$this->load->model('bands');
|
||||
$this->load->model('usermodes');
|
||||
|
||||
$activeBands = $this->bands->get_user_bands_for_qso_entry(false);
|
||||
$bandList = [];
|
||||
if (is_array($activeBands)) {
|
||||
foreach ($activeBands as $group => $bands) {
|
||||
if (is_array($bands)) {
|
||||
foreach ($bands as $band) {
|
||||
$bandList[] = $band;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$activeModes = $this->usermodes->active();
|
||||
$modeCategories = ['cw' => false, 'phone' => false, 'digi' => false];
|
||||
$submodes = [];
|
||||
|
||||
if ($activeModes) {
|
||||
foreach ($activeModes as $mode) {
|
||||
$qrgmode = strtoupper($mode->qrgmode ?? '');
|
||||
if ($qrgmode === 'CW') {
|
||||
$modeCategories['cw'] = true;
|
||||
} elseif ($qrgmode === 'SSB') {
|
||||
$modeCategories['phone'] = true;
|
||||
} elseif ($qrgmode === 'DATA') {
|
||||
$modeCategories['digi'] = true;
|
||||
}
|
||||
$submode = !empty($mode->submode) ? $mode->submode : $mode->mode;
|
||||
if (!empty($submode) && !in_array($submode, $submodes)) {
|
||||
$submodes[] = $submode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'favorites' => $favorites,
|
||||
'userConfig' => [
|
||||
'bands' => $bandList,
|
||||
'modes' => $modeCategories,
|
||||
'submodes' => $submodes
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -2106,12 +2106,18 @@ $(function() {
|
||||
|
||||
function getDxClusterFavs() {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/user_options/get_dxcluster_fav',
|
||||
url: base_url + 'index.php/user_options/get_dxcluster_user_favs_and_settings',
|
||||
method: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(result) {
|
||||
dxclusterFavs = result;
|
||||
// Handle combined response with favorites and userConfig
|
||||
dxclusterFavs = result.favorites || {};
|
||||
renderDxClusterFavMenu();
|
||||
|
||||
// Process user config (bands/modes/submodes)
|
||||
if (result.userConfig) {
|
||||
processUserConfig(result.userConfig);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3812,20 +3818,17 @@ $(function() {
|
||||
enableBandFilterControls();
|
||||
|
||||
// ========================================
|
||||
// CACHE USER FAVORITES ON PAGE LOAD
|
||||
// PROCESS USER CONFIG (called from getDxClusterFavs)
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* Fetch and cache user bands/modes on page load
|
||||
* Initializes My Submodes filter with user's enabled submodes
|
||||
* Process user bands/modes configuration
|
||||
* Called from getDxClusterFavs() when userConfig is included in response
|
||||
* @param {Object} data - User configuration object with bands, modes, submodes
|
||||
*/
|
||||
function fetchUserBandsAndModes() {
|
||||
let base_url = dxcluster_provider.replace('/dxcluster', '');
|
||||
$.ajax({
|
||||
url: base_url + '/bandmap/get_user_bands_and_modes',
|
||||
method: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
function processUserConfig(data) {
|
||||
if (!data) return;
|
||||
|
||||
cachedUserFavorites = data;
|
||||
|
||||
// Store mode categories for button enabling/disabling
|
||||
@@ -3864,20 +3867,9 @@ $(function() {
|
||||
5000
|
||||
);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
console.warn('Failed to fetch user bands and modes');
|
||||
cachedUserFavorites = null;
|
||||
userEnabledSubmodes = [];
|
||||
$('#toggleMySubmodesFilter').prop('disabled', true).addClass('disabled');
|
||||
$('#requiredFlags option[value="mysubmodes"]').prop('disabled', true);
|
||||
updateMySubmodesTooltip();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch user bands/modes on page load
|
||||
fetchUserBandsAndModes();
|
||||
// Note: User config is now loaded via combined getDxClusterFavs() API response
|
||||
|
||||
// ========================================
|
||||
// AGE AUTO-UPDATE
|
||||
|
||||
Reference in New Issue
Block a user