mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
fix(paths): separate Reset to FLOOD from Clear Paths
Reset to FLOOD now only resets the device path without deleting configured paths from the database. New Clear Paths button deletes all configured paths from DB without touching the device. This lets users reset to FLOOD to discover new paths while keeping their configured alternatives intact. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2313,15 +2313,9 @@ def reorder_contact_paths(pubkey):
|
||||
|
||||
@api_bp.route('/contacts/<pubkey>/paths/reset_flood', methods=['POST'])
|
||||
def reset_contact_to_flood(pubkey):
|
||||
"""Reset to FLOOD: clear all configured paths and reset device path."""
|
||||
db = _get_db()
|
||||
if not db:
|
||||
return jsonify({'success': False, 'error': 'Database not available'}), 503
|
||||
"""Reset device path to FLOOD mode (does not delete configured paths)."""
|
||||
try:
|
||||
# Clear all saved paths from DB
|
||||
deleted = db.delete_all_contact_paths(pubkey)
|
||||
# Reset path on device
|
||||
result = {'success': True, 'paths_deleted': deleted}
|
||||
result = {'success': True}
|
||||
try:
|
||||
dm = cli.get_device_manager()
|
||||
if dm and dm.is_connected:
|
||||
@@ -2338,6 +2332,19 @@ def reset_contact_to_flood(pubkey):
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@api_bp.route('/contacts/<pubkey>/paths/clear', methods=['POST'])
|
||||
def clear_contact_paths(pubkey):
|
||||
"""Delete all configured paths for a contact from the database."""
|
||||
db = _get_db()
|
||||
if not db:
|
||||
return jsonify({'success': False, 'error': 'Database not available'}), 503
|
||||
try:
|
||||
deleted = db.delete_all_contact_paths(pubkey)
|
||||
return jsonify({'success': True, 'paths_deleted': deleted}), 200
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@api_bp.route('/contacts/<pubkey>/no_auto_flood', methods=['GET'])
|
||||
def get_no_auto_flood(pubkey):
|
||||
"""Get the no_auto_flood flag for a contact."""
|
||||
|
||||
@@ -1811,6 +1811,7 @@ function setupPathFormHandlers(pubkey) {
|
||||
const pickBtn = document.getElementById('dmPickRepeaterBtn');
|
||||
const picker = document.getElementById('dmRepeaterPicker');
|
||||
const resetFloodBtn = document.getElementById('dmResetFloodBtn');
|
||||
const clearPathsBtn = document.getElementById('dmClearPathsBtn');
|
||||
const addPathModalEl = document.getElementById('addPathModal');
|
||||
|
||||
if (!addBtn || !addPathModalEl) return;
|
||||
@@ -1923,12 +1924,12 @@ function setupPathFormHandlers(pubkey) {
|
||||
});
|
||||
}
|
||||
|
||||
// Reset to FLOOD button
|
||||
// Reset to FLOOD button (device only, keeps configured paths)
|
||||
if (resetFloodBtn) {
|
||||
const newResetBtn = resetFloodBtn.cloneNode(true);
|
||||
resetFloodBtn.parentNode.replaceChild(newResetBtn, resetFloodBtn);
|
||||
newResetBtn.addEventListener('click', async () => {
|
||||
if (!confirm('Reset to FLOOD?\n\nThis will delete all configured paths and reset the device path to flood mode.')) {
|
||||
if (!confirm('Reset device path to FLOOD?\n\nThis resets the path on the device only. Your configured paths will be kept.')) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -1937,8 +1938,7 @@ function setupPathFormHandlers(pubkey) {
|
||||
});
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
await renderPathList(pubkey);
|
||||
showNotification('Reset to FLOOD mode', 'info');
|
||||
showNotification('Device path reset to FLOOD', 'info');
|
||||
} else {
|
||||
showNotification(data.error || 'Reset failed', 'danger');
|
||||
}
|
||||
@@ -1947,6 +1947,31 @@ function setupPathFormHandlers(pubkey) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Clear all configured paths button (DB only)
|
||||
if (clearPathsBtn) {
|
||||
const newClearBtn = clearPathsBtn.cloneNode(true);
|
||||
clearPathsBtn.parentNode.replaceChild(newClearBtn, clearPathsBtn);
|
||||
newClearBtn.addEventListener('click', async () => {
|
||||
if (!confirm('Clear all configured paths?\n\nThis will delete all paths from the database. The device path will not be changed.')) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(`/api/contacts/${encodeURIComponent(pubkey)}/paths/clear`, {
|
||||
method: 'POST'
|
||||
});
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
await renderPathList(pubkey);
|
||||
showNotification(`${data.paths_deleted || 0} path(s) cleared`, 'info');
|
||||
} else {
|
||||
showNotification(data.error || 'Clear failed', 'danger');
|
||||
}
|
||||
} catch (e) {
|
||||
showNotification('Clear failed', 'danger');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -327,10 +327,14 @@
|
||||
</button>
|
||||
</div>
|
||||
<div id="dmPathList"></div>
|
||||
<!-- Reset to FLOOD button -->
|
||||
<div class="text-end mt-1">
|
||||
<!-- Path action buttons -->
|
||||
<div class="d-flex justify-content-end gap-2 mt-1">
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" id="dmClearPathsBtn"
|
||||
title="Delete all configured paths from database">
|
||||
<i class="bi bi-trash"></i> Clear Paths
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" id="dmResetFloodBtn"
|
||||
title="Reset all paths and switch to FLOOD mode">
|
||||
title="Reset device path to FLOOD mode">
|
||||
<i class="bi bi-broadcast"></i> Reset to FLOOD
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user