redesign filter page: rule test, match stats, warnings, toggle

- Rule tester (POST /api/filters/test): evaluates an unsaved rule
  read-only against the newest matching mails in the source folder,
  using an IMAP SEARCH on the first text condition to narrow candidates.
  Shows matches, near misses with the failing condition, and whether
  any candidate had an attachment at all (would have caught the
  Klarmobil and it-moench misconfigurations immediately).
- Per-rule match_count / last_match_at (new migration), incremented by
  the scheduler on every match and shown in the list.
- PATCH /api/filters/{id}/enabled toggles a rule without resetting its
  processed state (a full PUT re-evaluates every mail for that rule).
- New filter list: cards with enable switch, priority, condition and
  action chips, match stats, and warnings (display name in from/to,
  "am (exakt)" date, duplicates, empty values, invalid regex, move
  without folder). Quick filters for active/inactive/warnings/never
  matched; copy-as-template; remembered account selection.
- Edit dialog: wider layout, live warnings, integrated test panel,
  sensible defaults for new rules (from + date after Jan 1 + move).
- Light global refresh: nav with active item, page background, cards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 09:48:12 +02:00
co-authored by Claude Opus 5.5
parent ce7caf5dfe
commit 1b4f6ed34e
9 changed files with 849 additions and 377 deletions
+37 -1
View File
@@ -14,7 +14,14 @@ from app.models.db_models import (
LogLevel,
ProcessedMail,
)
from app.schemas.schemas import FilterRuleCreate, FilterRuleResponse, FilterRuleUpdate
from app.schemas.schemas import (
FilterRuleCreate,
FilterRuleEnabled,
FilterRuleResponse,
FilterRuleTest,
FilterRuleUpdate,
)
from app.services.rule_tester import test_rule
logger = logging.getLogger(__name__)
@@ -33,6 +40,35 @@ def _reset_processed_for_rule(db: Session, rule_id: int) -> int:
router = APIRouter(prefix="/api/filters", tags=["filters"])
@router.post("/test")
def test_filter(data: FilterRuleTest, db: Session = Depends(get_db)):
"""Prüft eine Regel read-only gegen die neuesten passenden Mails im
Quellordner, ohne sie zu speichern oder Mails zu verändern."""
account = db.get(Account, data.account_id)
if not account:
raise HTTPException(404, "Konto nicht gefunden")
if not data.conditions:
raise HTTPException(400, "Keine Bedingungen angegeben")
try:
return test_rule(account, data.source_folder, data.conditions, data.limit)
except Exception as e:
logger.exception("Regeltest fehlgeschlagen")
raise HTTPException(500, f"Test fehlgeschlagen: {e}")
@router.patch("/{rule_id}/enabled", response_model=FilterRuleResponse)
def set_filter_enabled(rule_id: int, data: FilterRuleEnabled, db: Session = Depends(get_db)):
"""Regel ein-/ausschalten, ohne den Verarbeitungsstatus zurückzusetzen
(ein normales Update würde alle Mails für diese Regel neu prüfen lassen)."""
rule = db.get(FilterRule, rule_id)
if not rule:
raise HTTPException(404, "Filterregel nicht gefunden")
rule.enabled = data.enabled
db.commit()
db.refresh(rule)
return rule
@router.post("/reset-all-processed")
def reset_all_processed(db: Session = Depends(get_db)):
"""Setzt den 'verarbeitet'-Status ALLER Mails zurück — alle Regeln bewerten