From 1f856546532aa2711f08a6e3ecdd5db80d404fa7 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Wed, 8 Apr 2026 19:33:09 +0700 Subject: [PATCH] refactor: consolidate module interval display logic and improve edit form handling Introduced a new utility function, moduleIntervalLabel, to streamline the display of module interval information across different components. Enhanced the edit form functionality by ensuring proper handling of nullable values for community and DoH profile selections, improving data integrity and user experience during module updates. --- web/src/routes/modules/+page.svelte | 14 +++++--- .../routes/modules/[moduleId]/+page.svelte | 35 ++++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/web/src/routes/modules/+page.svelte b/web/src/routes/modules/+page.svelte index 5422751..2037a70 100644 --- a/web/src/routes/modules/+page.svelte +++ b/web/src/routes/modules/+page.svelte @@ -120,6 +120,14 @@ } } + function moduleIntervalLabel(moduleRow: ModuleRow): string { + const cron = typeof moduleRow.cron_expr === 'string' ? moduleRow.cron_expr.trim() : moduleRow.cron_expr; + if (cron) return cron; + return moduleRow.refresh_interval_sec !== null && moduleRow.refresh_interval_sec !== undefined + ? `${moduleRow.refresh_interval_sec}с` + : '—'; + } + function toggleModuleSelection(id: string) { const next = new Set(selectedModuleIds); if (next.has(id)) next.delete(id); @@ -237,9 +245,7 @@ {m.priority} - {m.cron_expr ?? (m.refresh_interval_sec !== null && m.refresh_interval_sec !== undefined - ? `${m.refresh_interval_sec}с` - : '—')} + {moduleIntervalLabel(m)} {#if m.enabled} @@ -286,7 +292,7 @@ {moduleTypes.find((t) => t.value === form.type)?.label ?? 'Выберите тип'} - {#each moduleTypes as t} + {#each moduleTypes as t (t.value)} {t.label} {/each} diff --git a/web/src/routes/modules/[moduleId]/+page.svelte b/web/src/routes/modules/[moduleId]/+page.svelte index 4bdffb4..e30b640 100644 --- a/web/src/routes/modules/[moduleId]/+page.svelte +++ b/web/src/routes/modules/[moduleId]/+page.svelte @@ -146,6 +146,8 @@ // Module edit let editDialog = $state(false); let editForm = $state({}); + let editDefaultCommunitySelect = $state('__none__'); + let editDohProfileSelect = $state('__none__'); let editSaving = $state(false); let deleteModDialog = $state(false); let deletingMod = $state(false); @@ -265,13 +267,28 @@ default_community_id: mod.default_community_id, doh_profile_id: mod.doh_profile_id }; + editDefaultCommunitySelect = nullableSelectValue(mod.default_community_id); + editDohProfileSelect = nullableSelectValue(mod.doh_profile_id); editDialog = true; } async function saveMod() { editSaving = true; try { - await apiMutate(`/v1/modules/${moduleId}`, 'PATCH', editForm); + const cron = typeof editForm.cron_expr === 'string' ? editForm.cron_expr.trim() : editForm.cron_expr; + const intervalRaw = editForm.refresh_interval_sec; + const interval = + intervalRaw === null || intervalRaw === undefined + ? null + : Number(intervalRaw); + const payload: ModulePatch = { + ...editForm, + cron_expr: cron ? cron : null, + refresh_interval_sec: Number.isFinite(interval) ? interval : null, + default_community_id: fromNullableSelect(editDefaultCommunitySelect), + doh_profile_id: fromNullableSelect(editDohProfileSelect) + }; + await apiMutate(`/v1/modules/${moduleId}`, 'PATCH', payload); await loadMod(); toast.success('Модуль обновлён'); editDialog = false; @@ -733,6 +750,14 @@ return value; } + function moduleIntervalLabel(moduleRow: ModuleRow): string { + const cron = typeof moduleRow.cron_expr === 'string' ? moduleRow.cron_expr.trim() : moduleRow.cron_expr; + if (cron) return cron; + return moduleRow.refresh_interval_sec !== null && moduleRow.refresh_interval_sec !== undefined + ? `${moduleRow.refresh_interval_sec}с` + : '—'; + } + const activeTab = $derived.by(() => { if (!mod) return 'entries'; switch (mod.type) { @@ -810,7 +835,7 @@

Интервал

- {mod.cron_expr ?? (mod.refresh_interval_sec !== null && mod.refresh_interval_sec !== undefined ? `${mod.refresh_interval_sec}с` : '—')} + {moduleIntervalLabel(mod)}

@@ -1281,8 +1306,9 @@ { + editDohProfileSelect = nullableSelectValue(v); editForm.doh_profile_id = fromNullableSelect(v); }} >