Files
rtu_v5/src_v1/templates/settings.html
admin 65e8907307 feat(quick-2): archive Flask v1 interface to src_v1/
- Copy app.py, templates, static, data, routes, services
- Copy requirements.txt for v1 dependencies
2026-03-12 12:29:42 +08:00

579 lines
23 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TCKRTUIYO - Settings</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<style>
:root {
--touch-target-min: 48px;
--touch-target-primary: 64px;
--primary-color: #0d6efd;
--bg-color: #f8f9fa;
--card-bg: #ffffff;
}
body {
font-size: 18px;
background-color: var(--bg-color);
}
/* Touch-optimized navigation */
.nav-menu {
display: flex;
gap: 10px;
padding: 15px;
background: var(--card-bg);
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
position: sticky;
top: 0;
z-index: 100;
}
.nav-btn {
flex: 1;
min-height: var(--touch-target-primary);
font-size: 1.2rem;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
border-radius: 12px;
transition: transform 0.1s, box-shadow 0.1s;
cursor: pointer;
}
.nav-btn:active {
transform: scale(0.98);
}
.nav-btn.active {
background-color: var(--primary-color);
color: white;
border: none;
}
.nav-btn:not(.active) {
background-color: #e9ecef;
color: #495057;
border: 1px solid #dee2e6;
}
/* Logo in navigation */
.nav-logo {
display: flex;
align-items: center;
justify-content: center;
padding: 0 10px;
}
.nav-logo img {
max-height: 40px;
width: auto;
}
/* Settings sections */
.settings-section {
background: var(--card-bg);
border-radius: 16px;
padding: 20px;
margin: 15px;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.settings-section h4 {
font-size: 1.3rem;
color: #212529;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid #e9ecef;
display: flex;
align-items: center;
gap: 10px;
}
/* Form controls */
.form-label {
font-weight: 500;
margin-bottom: 8px;
}
.form-control, .form-select {
padding: 12px 15px;
font-size: 1rem;
border-radius: 10px;
min-height: var(--touch-target-min);
}
/* Touch-friendly buttons */
.btn-save {
min-height: var(--touch-target-primary);
font-size: 1.1rem;
font-weight: 600;
padding: 15px 30px;
border-radius: 12px;
}
/* ADC Channel cards */
.adc-channel {
background: #f8f9fa;
border-radius: 12px;
padding: 15px;
margin-bottom: 10px;
}
.adc-channel h6 {
margin-bottom: 10px;
font-weight: 600;
}
/* Tabs for sub-sections */
.settings-tabs {
display: flex;
gap: 5px;
padding: 10px 15px;
background: #e9ecef;
border-radius: 12px;
margin-bottom: 15px;
overflow-x: auto;
}
.settings-tab {
padding: 12px 20px;
border-radius: 10px;
font-weight: 500;
cursor: pointer;
white-space: nowrap;
transition: background 0.2s;
}
.settings-tab.active {
background: var(--primary-color);
color: white;
}
.settings-tab:not(.active) {
background: transparent;
color: #495057;
}
/* Tab content */
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
/* Alert messages */
.alert {
border-radius: 12px;
padding: 15px 20px;
}
</style>
</head>
<body>
<!-- Navigation Menu -->
<nav class="nav-menu">
<a href="/" class="nav-logo">
<img src="logo/[LOGO] TCK.svg" alt="TCK" height="40">
</a>
<a href="/" class="nav-btn">
<i class="bi bi-speedometer2"></i> Dashboard
</a>
<a href="/settings" class="nav-btn active">
<i class="bi bi-gear"></i> Settings
</a>
<a href="/calibration" class="nav-btn">
<i class="bi bi-sliders"></i> Calibration
</a>
<a href="/files" class="nav-btn">
<i class="bi bi-folder"></i> Files
</a>
</nav>
<div class="container-fluid p-0">
<!-- Alert for save status -->
<div id="alertMessage" class="alert alert-success m-3" style="display: none;">
Settings saved successfully!
</div>
<!-- Settings Tabs -->
<div class="settings-tabs">
<div class="settings-tab active" onclick="showTab('station')">
<i class="bi bi-building"></i> Station
</div>
<div class="settings-tab" onclick="showTab('datetime')">
<i class="bi bi-clock"></i> Date/Time
</div>
<div class="settings-tab" onclick="showTab('network')">
<i class="bi bi-wifi"></i> Network
</div>
<div class="settings-tab" onclick="showTab('adc')">
<i class="bi bi-gpu"></i> ADC
</div>
<div class="settings-tab" onclick="showTab('sensors')">
<i class="bi bi-thermometer"></i> Sensors
</div>
</div>
<!-- Station Settings -->
<div class="tab-content active" id="tab-station">
<div class="settings-section">
<h4><i class="bi bi-building"></i> Station Information</h4>
<div class="mb-3">
<label class="form-label">Station ID</label>
<input type="text" class="form-control" id="stationId" placeholder="TCKRTUIYO-001">
</div>
<div class="mb-3">
<label class="form-label">Station Name</label>
<input type="text" class="form-control" id="stationName" placeholder="Rainfall Station">
</div>
<div class="mb-3">
<label class="form-label">Location</label>
<input type="text" class="form-control" id="stationLocation" placeholder="Unknown">
</div>
</div>
</div>
<!-- Date/Time Settings -->
<div class="tab-content" id="tab-datetime">
<div class="settings-section">
<h4><i class="bi bi-clock"></i> Date & Time Settings</h4>
<div class="mb-3">
<label class="form-label">Timezone</label>
<select class="form-select" id="timezone">
<option value="UTC">UTC</option>
<option value="GMT">GMT</option>
<option value="EST">EST (UTC-5)</option>
<option value="CST">CST (UTC-6)</option>
<option value="MST">MST (UTC-7)</option>
<option value="PST">PST (UTC-8)</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">
<input type="checkbox" id="ntpEnabled" checked> Enable NTP Sync
</label>
</div>
<div class="mb-3">
<label class="form-label">NTP Server</label>
<input type="text" class="form-control" id="ntpServer" placeholder="pool.ntp.org">
</div>
</div>
</div>
<!-- Network Settings -->
<div class="tab-content" id="tab-network">
<div class="settings-section">
<h4><i class="bi bi-wifi"></i> Network Settings</h4>
<div class="mb-3">
<label class="form-label">IP Address</label>
<input type="text" class="form-control" id="ipAddress" placeholder="192.168.1.100">
</div>
<div class="mb-3">
<label class="form-label">Subnet Mask</label>
<input type="text" class="form-control" id="subnetMask" placeholder="255.255.255.0">
</div>
<div class="mb-3">
<label class="form-label">Gateway</label>
<input type="text" class="form-control" id="gateway" placeholder="192.168.1.1">
</div>
<div class="mb-3">
<label class="form-label">DNS Server</label>
<input type="text" class="form-control" id="dnsServer" placeholder="8.8.8.8">
</div>
<div class="mb-3">
<label class="form-label">MAC Address</label>
<input type="text" class="form-control" id="macAddress" placeholder="00:00:00:00:00:00" readonly>
</div>
</div>
<div class="settings-section">
<h4><i class="bi bi-phone"></i> Mobile Network (4G)</h4>
<div class="mb-3">
<label class="form-label">
<input type="checkbox" id="mobileEnabled"> Enable Mobile Network
</label>
</div>
<div class="mb-3">
<label class="form-label">APN</label>
<input type="text" class="form-control" id="apn" placeholder="internet">
</div>
<div class="mb-3">
<label class="form-label">PIN</label>
<input type="text" class="form-control" id="mobilePin" placeholder="">
</div>
</div>
</div>
<!-- ADC Settings -->
<div class="tab-content" id="tab-adc">
<div class="settings-section">
<h4><i class="bi bi-gpu"></i> ADC Channel Configuration</h4>
<div id="adcChannels">
<!-- ADC channels will be populated by JS -->
</div>
</div>
</div>
<!-- Sensor Settings -->
<div class="tab-content" id="tab-sensors">
<div class="settings-section">
<h4><i class="bi bi-cloud-rain"></i> Rainfall Sensors</h4>
<div class="mb-3">
<label class="form-label">RF1 Sensor ID</label>
<input type="text" class="form-control" id="rf1Id" placeholder="RF1">
</div>
<div class="mb-3">
<label class="form-label">RF2 Sensor ID</label>
<input type="text" class="form-control" id="rf2Id" placeholder="RF2">
</div>
<div class="mb-3">
<label class="form-label">Bucket Size (mm per tip)</label>
<input type="number" class="form-control" id="bucketSize" step="0.01" value="0.2">
</div>
</div>
<div class="settings-section">
<h4><i class="bi bi-water"></i> Water Level Thresholds</h4>
<div class="mb-3">
<label class="form-label">Warning Threshold (%)</label>
<input type="number" class="form-control" id="waterWarning" value="80">
</div>
<div class="mb-3">
<label class="form-label">Danger Threshold (%)</label>
<input type="number" class="form-control" id="waterDanger" value="95">
</div>
</div>
<div class="settings-section">
<h4><i class="bi bi-battery-charging"></i> Voltage Thresholds</h4>
<div class="mb-3">
<label class="form-label">Battery HIGH (V)</label>
<input type="number" class="form-control" id="batteryHigh" step="0.1" value="14.0">
</div>
<div class="mb-3">
<label class="form-label">Battery NORMAL (V)</label>
<input type="number" class="form-control" id="batteryNormal" step="0.1" value="12.0">
</div>
<div class="mb-3">
<label class="form-label">Battery LOW (V)</label>
<input type="number" class="form-control" id="batteryLow" step="0.1" value="11.0">
</div>
</div>
<div class="settings-section">
<h4><i class="bi bi-thermometer-half"></i> EVAP Settings</h4>
<div class="mb-3">
<label class="form-label">
<input type="checkbox" id="evapEnabled"> Enable EVAP
</label>
</div>
<div class="mb-3">
<label class="form-label">Coefficient</label>
<input type="number" class="form-control" id="evapCoefficient" step="0.01" value="0.0">
</div>
</div>
</div>
<!-- Save Button -->
<div class="settings-section">
<button class="btn btn-primary btn-save w-100" onclick="saveSettings()">
<i class="bi bi-check-circle"></i> Save Settings
</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
let currentSettings = {};
// Tab navigation
function showTab(tabName) {
// Update tab buttons
document.querySelectorAll('.settings-tab').forEach(tab => {
tab.classList.remove('active');
});
event.target.closest('.settings-tab').classList.add('active');
// Update tab content
document.querySelectorAll('.tab-content').forEach(content => {
content.classList.remove('active');
});
document.getElementById('tab-' + tabName).classList.add('active');
}
// Load settings
async function loadSettings() {
try {
const response = await fetch('/api/settings');
currentSettings = await response.json();
// Station
document.getElementById('stationId').value = currentSettings.station.id;
document.getElementById('stationName').value = currentSettings.station.name;
document.getElementById('stationLocation').value = currentSettings.station.location;
// Date/Time
document.getElementById('timezone').value = currentSettings.datetime.timezone;
document.getElementById('ntpEnabled').checked = currentSettings.datetime.ntp_enabled;
document.getElementById('ntpServer').value = currentSettings.datetime.ntp_server;
// Network
document.getElementById('ipAddress').value = currentSettings.network.ip;
document.getElementById('subnetMask').value = currentSettings.network.subnet;
document.getElementById('gateway').value = currentSettings.network.gateway;
document.getElementById('dnsServer').value = currentSettings.network.dns;
document.getElementById('macAddress').value = currentSettings.network.mac;
// Mobile
document.getElementById('mobileEnabled').checked = currentSettings.mobile.enabled;
document.getElementById('apn').value = currentSettings.mobile.apn;
document.getElementById('mobilePin').value = currentSettings.mobile.pin;
// ADC Channels
renderAdcChannels();
// Sensors
document.getElementById('rf1Id').value = currentSettings.sensors.rainfall.rf1_id;
document.getElementById('rf2Id').value = currentSettings.sensors.rainfall.rf2_id;
document.getElementById('bucketSize').value = currentSettings.sensors.rainfall.bucket_size;
document.getElementById('waterWarning').value = currentSettings.sensors.water_level.threshold_warning;
document.getElementById('waterDanger').value = currentSettings.sensors.water_level.threshold_danger;
document.getElementById('batteryHigh').value = currentSettings.sensors.voltage.battery_high;
document.getElementById('batteryNormal').value = currentSettings.sensors.voltage.battery_normal;
document.getElementById('batteryLow').value = currentSettings.sensors.voltage.battery_low;
// EVAP
document.getElementById('evapEnabled').checked = currentSettings.evap.enabled;
document.getElementById('evapCoefficient').value = currentSettings.evap.coefficient;
} catch (error) {
console.error('Error loading settings:', error);
}
}
// Render ADC channel configuration
function renderAdcChannels() {
const container = document.getElementById('adcChannels');
container.innerHTML = '';
currentSettings.adc.channels.forEach((channel, index) => {
const div = document.createElement('div');
div.className = 'adc-channel';
div.innerHTML = `
<h6>Channel ${channel.id}: ${channel.name}</h6>
<div class="mb-2">
<label class="form-label">Type</label>
<select class="form-select" id="adcType${channel.id}">
<option value="4-20mA" ${channel.type === '4-20mA' ? 'selected' : ''}>4-20mA</option>
<option value="0-10vDC" ${channel.type === '0-10vDC' ? 'selected' : ''}>0-10vDC</option>
</select>
</div>
<div class="mb-2">
<label class="form-label">Name</label>
<input type="text" class="form-control" id="adcName${channel.id}" value="${channel.name}">
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="adcEnabled${channel.id}" ${channel.enabled ? 'checked' : ''}>
<label class="form-check-label" for="adcEnabled${channel.id}">Enabled</label>
</div>
`;
container.appendChild(div);
});
}
// Save settings
async function saveSettings() {
const settings = {
station: {
id: document.getElementById('stationId').value,
name: document.getElementById('stationName').value,
location: document.getElementById('stationLocation').value
},
datetime: {
timezone: document.getElementById('timezone').value,
ntp_enabled: document.getElementById('ntpEnabled').checked,
ntp_server: document.getElementById('ntpServer').value
},
network: {
ip: document.getElementById('ipAddress').value,
subnet: document.getElementById('subnetMask').value,
gateway: document.getElementById('gateway').value,
dns: document.getElementById('dnsServer').value,
mac: document.getElementById('macAddress').value
},
mobile: {
enabled: document.getElementById('mobileEnabled').checked,
apn: document.getElementById('apn').value,
pin: document.getElementById('mobilePin').value
},
adc: {
channels: currentSettings.adc.channels.map((ch, i) => ({
id: ch.id,
type: document.getElementById('adcType' + ch.id).value,
name: document.getElementById('adcName' + ch.id).value,
enabled: document.getElementById('adcEnabled' + ch.id).checked
}))
},
sensors: {
rainfall: {
rf1_id: document.getElementById('rf1Id').value,
rf2_id: document.getElementById('rf2Id').value,
bucket_size: parseFloat(document.getElementById('bucketSize').value)
},
water_level: {
threshold_warning: parseInt(document.getElementById('waterWarning').value),
threshold_danger: parseInt(document.getElementById('waterDanger').value)
},
voltage: {
battery_high: parseFloat(document.getElementById('batteryHigh').value),
battery_normal: parseFloat(document.getElementById('batteryNormal').value),
battery_low: parseFloat(document.getElementById('batteryLow').value),
solar_high: 15.0,
solar_normal: 12.0
}
},
evap: {
enabled: document.getElementById('evapEnabled').checked,
coefficient: parseFloat(document.getElementById('evapCoefficient').value)
}
};
try {
const response = await fetch('/api/settings', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(settings)
});
const result = await response.json();
if (result.success) {
showAlert('Settings saved successfully!');
}
} catch (error) {
console.error('Error saving settings:', error);
showAlert('Error saving settings', 'danger');
}
}
function showAlert(message, type = 'success') {
const alert = document.getElementById('alertMessage');
alert.className = 'alert alert-' + type;
alert.textContent = message;
alert.style.display = 'block';
setTimeout(() => {
alert.style.display = 'none';
}, 3000);
}
// Load settings on page load
loadSettings();
</script>
</body>
</html>