diff --git a/app/routes/api.py b/app/routes/api.py index e2ca584..7b64636 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -2313,15 +2313,9 @@ def reorder_contact_paths(pubkey): @api_bp.route('/contacts//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//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//no_auto_flood', methods=['GET']) def get_no_auto_flood(pubkey): """Get the no_auto_flood flag for a contact.""" diff --git a/app/static/js/dm.js b/app/static/js/dm.js index 61930af..469d855 100644 --- a/app/static/js/dm.js +++ b/app/static/js/dm.js @@ -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'); + } + }); + } } /** diff --git a/app/templates/dm.html b/app/templates/dm.html index 229a2ab..a23ba4a 100644 --- a/app/templates/dm.html +++ b/app/templates/dm.html @@ -327,10 +327,14 @@
- -
+ +
+