make sure web ui save buttons work

This commit is contained in:
Chuck
2025-09-15 10:50:55 -04:00
parent fcbc67464d
commit b96f1e3957
2 changed files with 55 additions and 1 deletions

View File

@@ -719,11 +719,12 @@
<button class="btn btn-danger" onclick="runAction('stop_display')"><i class="fas fa-stop"></i> Stop Display</button>
<button class="btn btn-primary" onclick="systemAction('restart_service')"><i class="fas fa-redo"></i> Restart Service</button>
<button class="btn btn-warning" onclick="systemAction('git_pull')"><i class="fas fa-download"></i> Update Code</button>
<button class="btn btn-info" onclick="systemAction('migrate_config')"><i class="fas fa-sync-alt"></i> Migrate Config</button>
<button class="btn btn-danger" onclick="systemAction('reboot_system')"><i class="fas fa-power-off"></i> Reboot</button>
<button class="btn btn-secondary" onclick="stopOnDemand()"><i class="fas fa-ban"></i> Stop On-Demand</button>
<span id="ondemand-status" style="margin-left:auto; font-size:12px; color:#333; background:#f3f3f3; padding:6px 10px; border-radius:8px;">On-Demand: None</span>
</div>
<div style="margin-top:12px; color:#666; font-size:12px;">Service actions may require sudo privileges on the Pi.</div>
<div style="margin-top:12px; color:#666; font-size:12px;">Service actions may require sudo privileges on the Pi. Migrate Config adds new options with defaults while preserving your settings.</div>
</div>
<!-- Editor Mode Banner -->
@@ -906,6 +907,9 @@
<button class="btn btn-warning" onclick="systemAction('git_pull')">
<i class="fas fa-download"></i> Update Code
</button>
<button class="btn btn-info" onclick="systemAction('migrate_config')">
<i class="fas fa-sync-alt"></i> Migrate Config
</button>
<button class="btn btn-danger" onclick="systemAction('reboot_system')">
<i class="fas fa-power-off"></i> Reboot System
</button>
@@ -2487,6 +2491,9 @@
if (action === 'reboot_system' && !confirm('Are you sure you want to reboot the system?')) {
return;
}
if (action === 'migrate_config' && !confirm('This will migrate your configuration to add any new options with default values. A backup will be created automatically. Continue?')) {
return;
}
try {
const response = await fetch('/api/system/action', {
@@ -3038,6 +3045,41 @@
});
})();
// Music form submit
(function augmentMusicForm(){
const form = document.getElementById('music-form');
form.addEventListener('submit', async function(e){
e.preventDefault();
const payload = {
music: {
enabled: document.getElementById('music_enabled').checked,
preferred_source: document.getElementById('music_preferred_source').value,
YTM_COMPANION_URL: document.getElementById('ytm_companion_url').value,
POLLING_INTERVAL_SECONDS: parseInt(document.getElementById('music_polling_interval').value)
}
};
await saveConfigJson(payload);
});
})();
// Calendar form submit
(function augmentCalendarForm(){
const form = document.getElementById('calendar-form');
form.addEventListener('submit', async function(e){
e.preventDefault();
const calendars = document.getElementById('calendar_calendars').value.split(',').map(s => s.trim()).filter(Boolean);
const payload = {
calendar: {
enabled: document.getElementById('calendar_enabled').checked,
max_events: parseInt(document.getElementById('calendar_max_events').value),
update_interval: parseInt(document.getElementById('calendar_update_interval').value),
calendars: calendars
}
};
await saveConfigJson(payload);
});
})();
// News advanced save
async function saveNewsAdvancedSettings(){
const payload = {

View File

@@ -735,6 +735,18 @@ def system_action():
}), 400
result = subprocess.run(['git', 'pull'],
capture_output=True, text=True, cwd=str(repo_dir), check=False)
elif action == 'migrate_config':
# Run config migration script
repo_dir = Path(__file__).resolve().parent
migrate_script = repo_dir / 'migrate_config.sh'
if not migrate_script.exists():
return jsonify({
'status': 'error',
'message': f'Migration script not found: {migrate_script}'
}), 400
result = subprocess.run(['bash', str(migrate_script)],
cwd=str(repo_dir), capture_output=True, text=True, check=False)
else:
return jsonify({
'status': 'error',