fixed critical bug on bands table when viewing on mobile

This commit is contained in:
Russel Yasol
2024-10-03 13:30:14 +08:00
parent badfb5e182
commit a9f8ae753b
11 changed files with 617 additions and 438 deletions

View File

@@ -1,333 +1,426 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<!-- Logo -->
<link rel="simpleadmin-logo" href="favicon.ico" />
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="css/bulma/bulma.scss" />
<link rel="stylesheet" href="css/bulma/css/bulma.min.css" />
<link rel="stylesheet" href="css/bulma/css/bulma.css" />
<link rel="stylesheet" href="css/custom.css" />
<!-- Logo -->
<link rel="simpleadmin-logo" href="favicon.ico" />
<!-- Font awesome icons -->
<script
src="https://kit.fontawesome.com/b0caedfab3.js"
crossorigin="anonymous"
></script>
<link rel="stylesheet" href="css/bulma/bulma.scss" />
<link rel="stylesheet" href="css/bulma/css/bulma.min.css" />
<link rel="stylesheet" href="css/bulma/css/bulma.css" />
<link rel="stylesheet" href="css/custom.css" />
<script src="js/styles/toggle-theme.js"></script>
<script src="/js/styles/nav-burger.js"></script>
<script src="/js/styles/modal-trigger.js"></script>
<script src="/js/utils/reboot.js"></script>
<script defer src="/js/auth/auth.js"></script>
<!-- Font awesome icons -->
<script src="https://kit.fontawesome.com/b0caedfab3.js" crossorigin="anonymous"></script>
<script>
(function () {
const savedTheme = localStorage.getItem("theme") || "theme-dark";
document.documentElement.classList.add(savedTheme);
})();
</script>
<title>QuecManager</title>
</head>
<body class="body-margin">
<nav class="navbar is-transparent">
<div class="navbar-brand">
<a class="navbar-item" href="/">
<img src="/assets/logo.png" alt="Logo" />
<span class="title">QuecManager</span>
</a>
<a
role="button"
class="navbar-burger"
aria-label="menu"
aria-expanded="false"
data-target="navMenu"
>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navMenu" class="navbar-menu">
<div class="navbar-start ml-6">
<a class="navbar-item has-text-weight-bold" href="/"> Home </a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link"> Cellular </a>
<div class="navbar-dropdown is-boxed">
<a class="navbar-item" href="/bandlock.html"> Band Locking </a>
<a class="navbar-item" href="/cell-locking.html">Cell Locking</a>
<a class="navbar-item" href="/cell-scanner.html">Cell Scanner</a>
<a class="navbar-item" href="/cell-settings.html"
>Cell Settings</a
>
<a class="navbar-item" href="/cell-sms.html"> Cell SMS </a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link"> Advance </a>
<div class="navbar-dropdown is-boxed">
<a class="navbar-item" href="/advance-settings.html"> Advance Settings </a>
<a class="navbar-item" href="#">Experimental Features</a>
<a class="navbar-item" href="/cgi-bin/luci">OpenWRT Luci</a>
</div>
</div>
<a class="navbar-item" href="/about.html"> About </a>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons is-flex-direction-column-mobile">
<p class="control is-expanded-mobile">
<a
href="#"
class="button is-link is-outlined is-fullwidth-mobile"
>
<span class="icon">
<i class="fas fa-arrows-rotate"></i>
</span>
<span>Restart Connection</span>
</a>
</p>
<div class="is-flex is-mobile is-align-items-center">
<p class="control">
<div href="#" class="button is-warning is-outlined reboot-modal" data-target="reboot-modal" >
<span class="icon">
<i class="fas fa-power-off"></i>
</span>
</div>
</p>
<p class="control ml-2 is-mobile">
<a
href="#"
class="button is-warning is-outlined js-theme-toggle"
>
<span class="icon">
<i class="fas fa-sun"></i>
</span>
</a>
</p>
<p class="control ml-2 is-mobile">
<a
href="#"
class="button is-warning is-outlined js-theme-toggle"
id="logoutButton"
>
<span class="icon">
<i class="fas fa-right-from-bracket"></i>
</span>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</nav>
<div class="column-margin">
<div class="fixed-grid has-2-cols has-1-cols-mobile">
<div class="grid is-gap-5">
<div class="cell is-col-span-2 is-col-span-1-mobile">
<div class="card">
<div class="card-header">
<div class="card-header-title">4G LTE Band Locking</div>
</div>
<div class="card-content">
<div class="fixed-grid has-5-cols has-3-cols-mobile">
<div class="grid" id="lte_bands">
<!-- write each lte band cell here -->
</div>
</div>
</div>
<div class="card-footer">
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Lock LTE Bands
</a>
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Uncheck All
</a>
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Reset
</a>
</div>
</div>
</div>
<div class="cell">
<div class="card">
<div class="card-header">
<div class="card-header-title">5G-NR NSA Band Locking</div>
</div>
<div class="card-content">
<div class="fixed-grid has-5-cols has-3-cols-mobile">
<div class="grid" id="nsa_bands">
<!-- write each nsa band cell here -->
</div>
</div>
</div>
<div class="card-footer">
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Lock NSA Bands
</a>
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Uncheck All
</a>
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Reset
</a>
</div>
</div>
</div>
<div class="cell">
<div class="card">
<div class="card-header">
<div class="card-header-title">5G-NR SA Band Locking</div>
</div>
<div class="card-content">
<div class="fixed-grid has-5-cols has-3-cols-mobile">
<div class="grid" id="sa_bands">
<!-- write each SA band cell here -->
</div>
</div>
</div>
<div class="card-footer">
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Lock SA Bands
</a>
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Uncheck All
</a>
<a
href="#"
class="card-footer-item has-text-link has-text-weight-semibold has-text-white"
>
Reset
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="content">
<div class="fixed-grid has-2-cols has-1-cols-mobile">
<div class="grid">
<div class="cell">
<div class="icon-text">
<span class="icon has-text-info">
<i class="fas fa-info-circle"></i>
</span>
<span>Information</span>
</div>
<p class="block has-text-weight-semibold">
If problem persists after locking bands, please reboot the
modem.
</p>
</div>
<div class="cell">
<div class="icon-text">
<span class="icon has-text-info">
<i class="fas fa-info-circle"></i>
</span>
<span>Current Active Bands</span>
</div>
<p class="block has-text-weight-semibold">
Band 1 / Band 3 / NR Band 41
</p>
</div>
</div>
</div>
</div>
</footer>
<div id="reboot-modal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<section class="modal-card-body rounded-edge">
<p class="subtitle" id="modal-message">
Do you want to reboot the device?
</p>
<div id="loading-content" style="display: none">
<div class="custom-loader"></div>
<div class="countdown-text">
Rebooting... <span id="countdown">40</span>s
</div>
</div>
<div class="buttons" id="modal-buttons">
<button class="button is-warning" id="rebootModem">Reboot</button>
<button class="button cancel" aria-label="close">Cancel</button>
</div>
</section>
</div>
</div>
</body>
<script src="js/styles/toggle-theme.js"></script>
<script src="/js/styles/nav-burger.js"></script>
<script src="/js/styles/modal-trigger.js"></script>
<script src="/js/utils/reboot.js"></script>
<script defer src="/js/auth/auth.js"></script>
<script>
var lte_bands =
"1:2:3:4:5:7:8:12:13:14:18:19:20:25:26:28:29:30:32:34:38:39:40:41:42:43:46:48:66:71";
var nsa_bands = "1:2:3:5:7:8:12:20:25:28:38:40:41:48:66:71:77:78:79";
var sa_bands = "1:2:3:5:7:8:12:20:25:28:38:40:41:48:66:71:77:78:79";
(function () {
const savedTheme = localStorage.getItem("theme") || "theme-dark";
document.documentElement.classList.add(savedTheme);
})();
</script>
<title>QuecManager</title>
</head>
<body class="body-margin">
<nav class="navbar is-transparent">
<div class="navbar-brand">
<a class="navbar-item" href="/">
<img src="/assets/logo.png" alt="Logo" />
<span class="title">QuecManager</span>
</a>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navMenu">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navMenu" class="navbar-menu">
<div class="navbar-start ml-6">
<a class="navbar-item" href="/"> Home </a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link has-text-weight-bold"> Cellular </a>
<div class="navbar-dropdown is-boxed">
<a class="navbar-item" href="/bandlock.html"> Band Locking </a>
<a class="navbar-item" href="/cell-locking.html">Cell Locking</a>
<a class="navbar-item" href="/cell-scanner.html">Cell Scanner</a>
<a class="navbar-item" href="/cell-settings.html">Cell Settings</a>
<a class="navbar-item" href="/cell-sms.html"> Cell SMS </a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link"> Advance </a>
<div class="navbar-dropdown is-boxed">
<a class="navbar-item" href="/advance-settings.html"> Advance Settings </a>
<a class="navbar-item" href="#">Experimental Features</a>
<a class="navbar-item" href="/cgi-bin/luci">OpenWRT Luci</a>
</div>
</div>
<a class="navbar-item" href="/about.html"> About </a>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons is-flex-direction-column-mobile">
<p class="control is-expanded-mobile">
<a href="#" class="button is-link is-outlined is-fullwidth-mobile">
<span class="icon">
<i class="fas fa-arrows-rotate"></i>
</span>
<span>Restart Connection</span>
</a>
</p>
<div class="is-flex is-mobile is-align-items-center">
<p class="control">
<div href="#" class="button is-warning is-outlined reboot-modal" data-target="reboot-modal">
<span class="icon">
<i class="fas fa-power-off"></i>
</span>
</div>
</p>
<p class="control ml-2 is-mobile">
<a href="#" class="button is-warning is-outlined js-theme-toggle">
<span class="icon">
<i class="fas fa-sun"></i>
</span>
</a>
</p>
<p class="control ml-2 is-mobile">
<a href="#" class="button is-warning is-outlined js-theme-toggle" id="logoutButton">
<span class="icon">
<i class="fas fa-right-from-bracket"></i>
</span>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</nav>
<div class="column-margin">
<div class="fixed-grid has-2-cols has-1-cols-mobile">
<div class="grid is-gap-5">
<div class="cell is-col-span-2 is-col-span-1-mobile">
<div class="card">
<div class="card-header">
<div class="card-header-title">4G LTE Band Locking</div>
</div>
<div class="card-content">
<div class="fixed-grid has-5-cols has-3-cols-mobile">
<div class="grid" id="lte_bands">
<!-- LTE bands will be populated here -->
</div>
</div>
</div>
<div class="card-footer">
<div id="lockLte" class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Lock LTE Bands
</div>
<div id="uncheckLte"
class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Uncheck All
</div>
<div class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Reset
</div>
</div>
</div>
</div>
<div class="cell">
<div class="card">
<div class="card-header">
<div class="card-header-title">5G-NR NSA Band Locking</div>
</div>
<div class="card-content">
<div class="fixed-grid has-5-cols has-3-cols-mobile">
<div class="grid" id="nsa_bands">
<!-- NSA bands will be populated here -->
</div>
</div>
</div>
<div class="card-footer">
<div id="lockNsa" class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Lock NSA Bands
</div>
<div id="uncheckNsa"
class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Uncheck All
</div>
<div class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Reset
</div>
</div>
</div>
</div>
<div class="cell">
<div class="card">
<div class="card-header">
<div class="card-header-title">5G-NR SA Band Locking</div>
</div>
<div class="card-content">
<div class="fixed-grid has-5-cols has-3-cols-mobile">
<div class="grid" id="sa_bands">
<!-- SA bands will be populated here -->
</div>
</div>
</div>
<div class="card-footer">
<div id="lockSa" class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Lock SA Bands
</div>
<div id="uncheckSa" class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Uncheck All
</div>
<div class="button card-footer-item has-text-link has-text-weight-semibold has-text-white">
Reset
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="content">
<div class="fixed-grid has-2-cols has-1-cols-mobile">
<div class="grid">
<div class="cell">
<div class="icon-text">
<span class="icon has-text-info">
<i class="fas fa-info-circle"></i>
</span>
<span>Information</span>
</div>
<p class="block has-text-weight-semibold">
If problem persists after locking bands, please reboot the
modem.
</p>
</div>
<div class="cell">
<div class="icon-text">
<span class="icon has-text-info">
<i class="fas fa-info-circle"></i>
</span>
<span>Current Active Bands</span>
</div>
<p class="block has-text-weight-semibold">
Band 1 / Band 3 / NR Band 41
</p>
</div>
</div>
</div>
</div>
</footer>
<div id="reboot-modal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<section class="modal-card-body rounded-edge">
<p class="subtitle" id="modal-message">
Do you want to reboot the device?
</p>
<div id="loading-content" style="display: none">
<div class="custom-loader"></div>
<div class="countdown-text">
Rebooting... <span id="countdown">40</span>s
</div>
</div>
<div class="buttons" id="modal-buttons">
<button class="button is-warning" id="rebootModem">Reboot</button>
<button class="button cancel" aria-label="close">Cancel</button>
</div>
</section>
</div>
</div>
<script>
// Function to fetch supported bands via AT command and populate the checkboxes
async function fetchSupportedBands() {
try {
const response = await fetch('/cgi-bin/atinout_handler.sh', {
method: 'POST',
body: 'command=' + encodeURIComponent('AT+QNWPREFCFG="policy_band"')
});
const data = await response.json();
const lteBandsMatch = data.output.match(/"lte_band",([0-9:]+)/);
const nsaBandsMatch = data.output.match(/"nsa_nr5g_band",([0-9:]+)/);
const saBandsMatch = data.output.match(/"nrdc_nr5g_band",([0-9:]+)/);;
if (lteBandsMatch) populateBands(lteBandsMatch[1], "#lte_bands");
if (nsaBandsMatch) populateBands(nsaBandsMatch[1], "#nsa_bands");
if (saBandsMatch) populateBands(saBandsMatch[1], "#sa_bands");
fetchActiveBands();
} catch (error) {
console.error('Error fetching supported bands:', error);
}
}
// Function to fetch currently active bands and mark the checkboxes accordingly
async function fetchActiveBands() {
try {
const response = await fetch('/cgi-bin/atinout_handler.sh', {
method: 'POST',
body: 'command=' + encodeURIComponent('AT+QNWPREFCFG="lte_band";+QNWPREFCFG="nsa_nr5g_band";+QNWPREFCFG="nrdc_nr5g_band"')
});
const data = await response.json();
// Remove the first line of the output
data.output = data.output.split('\n').slice(1).join('\n');
// Extract active bands
const activeLteBands = data.output.match(/"lte_band",([0-9:]+)/)[1].split(':');
const activeNsaBands = data.output.match(/"nsa_nr5g_band",([0-9:]+)/)[1].split(':');
const activeSaBands = data.output.match(/"nr5g_band",([0-9:]+)/)[1].split(':');
// // Mark checkboxes as checked for active bands
markActiveBands(activeLteBands, '#lte_bands');
markActiveBands(activeNsaBands, '#nsa_bands');
markActiveBands(activeSaBands, '#sa_bands');
} catch (error) {
console.error('Error fetching active bands:', error);
}
}
// Function to populate bands in the target element
function populateBands(bandsString, targetId) {
var bandsArray = bandsString.split(":");
var html = "";
var bandsArray = bandsString.split(':');
var html = '';
for (var i = 0; i < bandsArray.length; i++) {
html +=
'<div class="cell"><label class="checkbox"><input type="checkbox" /> B' +
bandsArray[i] +
"</label></div>";
html += `<div class="cell">
<label class="checkbox">
<input type="checkbox" value="${bandsArray[i]}" /> B${bandsArray[i]}
</label>
</div>`;
}
// Inject the generated HTML into the target element
document.querySelector(targetId).innerHTML = html;
}
// Populate the bands in their respective grids
populateBands(lte_bands, "#lte_bands");
populateBands(nsa_bands, "#nsa_bands");
populateBands(sa_bands, "#sa_bands");
// Function to mark checkboxes as checked based on active bands
function markActiveBands(activeBands, targetId) {
const checkboxes = document.querySelectorAll(`${targetId} input[type="checkbox"]`);
checkboxes.forEach((checkbox) => {
if (activeBands.includes(checkbox.value)) {
checkbox.setAttribute('checked', 'checked');
}
});
}
// Function to uncheck all checkboxes in the target element
function uncheckAll(targetId) {
const checkboxes = document.querySelectorAll(`${targetId} input[type="checkbox"]`);
checkboxes.forEach((checkbox) => {
checkbox.removeAttribute('checked');
checkbox.checked = false; // Also update the state programmatically
});
}
// Event listeners for "Uncheck All" buttons
document.getElementById('uncheckLte').addEventListener('click', function (event) {
event.preventDefault();
uncheckAll('#lte_bands');
});
document.getElementById('uncheckNsa').addEventListener('click', function (event) {
event.preventDefault();
uncheckAll('#nsa_bands');
});
document.getElementById('uncheckSa').addEventListener('click', function (event) {
event.preventDefault();
uncheckAll('#sa_bands');
});
// Locking the Bands
// Function to get checked bands and generate AT command
function getCheckedBandsCommand(targetId, commandType) {
const checkboxes = document.querySelectorAll(`${targetId} input[type="checkbox"]:checked`);
const checkedBands = Array.from(checkboxes).map(cb => cb.value).sort((a, b) => a - b);
if (checkedBands.length === 0) {
return null; // Return null if no bands are selected
}
const bandString = checkedBands.join(':');
return `AT+QNWPREFCFG="${commandType}",${bandString}`;
}
// Function to send AT command via atinout
async function sendATCommand(command) {
try {
const response = await fetch('/cgi-bin/atinout_handler.sh', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `command=${encodeURIComponent(command)}`
});
const data = await response.json();
return data;
// refetch active bands after successful command
fetchActiveBands();
} catch (error) {
console.error('Error sending AT command:', error);
throw error;
}
}
// Function to handle band locking for a specific type
async function lockBands(targetId, commandType) {
const command = getCheckedBandsCommand(targetId, commandType);
if (!command) {
alert('Please select at least one band to lock.');
return;
}
try {
await sendATCommand(command);
alert(`Successfully locked ${commandType.split('_')[0].toUpperCase()} bands`);
} catch (error) {
alert(`Failed to lock bands: ${error.message}`);
}
}
// Event listeners for Lock buttons
document.getElementById('lockLte').addEventListener('click', () =>
lockBands('#lte_bands', 'lte_band')
);
document.getElementById('lockNsa').addEventListener('click', () =>
lockBands('#nsa_bands', 'nsa_nr5g_band')
);
document.getElementById('lockSa').addEventListener('click', () =>
lockBands('#sa_bands', 'nr5g_band')
);
// Initial call to fetch supported bands on page load
window.onload = fetchSupportedBands;
</script>
</html>
</body>
</html>