feat: add Import/Export for DWM rules in Homebridge UI

Export:
- '⬇ Export' button downloads all rules as dwm-rules-YYYY-MM-DD.json
- Compatible with desktop app rule format

Import:
- '⬆ Import' button opens file picker (accepts .json)
- Preview panel shows rule names + types before committing
- Merge mode: adds rules, skips any whose name already exists
- Replace mode: deletes all current rules then imports
- Server strips imported IDs/timestamps — fresh ones are assigned
- Reports imported/skipped count on completion

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
SRS IT
2026-03-28 20:25:12 -04:00
parent 951d4c4eaa
commit 3bcc427683
3 changed files with 143 additions and 0 deletions
@@ -220,9 +220,32 @@
<div class="flex-row" style="margin-bottom:12px">
<h2 style="margin:0">DWM Automation Rules</h2>
<div class="spacer"></div>
<button class="btn btn-ghost btn-sm" id="btn-export-dwm" title="Export all rules to JSON file">⬇ Export</button>
<button class="btn btn-ghost btn-sm" id="btn-import-dwm" title="Import rules from JSON file">⬆ Import</button>
<input type="file" id="dwm-import-file" accept=".json" style="display:none" />
<button class="btn btn-primary" id="btn-add-dwm">+ Add Rule</button>
</div>
<!-- Import preview panel (hidden until file chosen) -->
<div id="dwm-import-panel" style="display:none;margin-bottom:16px;padding:14px 16px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.18);border-radius:8px">
<div class="flex-row" style="margin-bottom:10px">
<strong id="dwm-import-title" style="font-size:0.92rem">Import Rules</strong>
<div class="spacer"></div>
<button class="btn btn-ghost btn-sm" id="btn-import-cancel">✕ Cancel</button>
</div>
<div id="dwm-import-list" style="max-height:180px;overflow-y:auto;margin-bottom:12px;font-size:0.82rem;color:#9ca3af"></div>
<div style="display:flex;align-items:center;gap:16px;margin-bottom:12px;font-size:0.85rem">
<label style="display:flex;align-items:center;gap:6px;cursor:pointer">
<input type="radio" name="dwm-import-mode" value="merge" checked /> Merge <span style="color:#9ca3af;font-size:0.78rem">(skip existing names)</span>
</label>
<label style="display:flex;align-items:center;gap:6px;cursor:pointer">
<input type="radio" name="dwm-import-mode" value="replace" /> Replace <span style="color:#fca5a5;font-size:0.78rem">(delete all current rules first)</span>
</label>
</div>
<div id="dwm-import-status" style="font-size:0.82rem;margin-bottom:8px;min-height:18px"></div>
<button class="btn btn-primary" id="btn-import-confirm">⬆ Import Rules</button>
</div>
<!-- Scheduler heartbeat bar -->
<div id="dwm-heartbeat" style="display:flex;align-items:center;gap:8px;padding:8px 12px;border-radius:6px;margin-bottom:14px;font-size:0.8rem;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.18)">
<span id="hb-dot" style="width:10px;height:10px;border-radius:50%;background:#6b7280;flex-shrink:0"></span>