From 25374a691904aa6954d14302b18e97f0de68e221 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Wed, 8 Apr 2026 16:38:22 +0700 Subject: [PATCH] refactor: enhance module display and input handling in module pages Updated the module display logic to improve the handling of nullable values for refresh intervals and community selections. Introduced new utility functions for managing nullable select values, ensuring better user experience and data integrity. Additionally, enhanced the visual presentation of module metadata with updated icons and styling, improving overall clarity and usability in the module pages. --- web/src/routes/modules/+page.svelte | 4 +- .../routes/modules/[moduleId]/+page.svelte | 94 +++++++++++++++---- 2 files changed, 77 insertions(+), 21 deletions(-) diff --git a/web/src/routes/modules/+page.svelte b/web/src/routes/modules/+page.svelte index 243048f..5422751 100644 --- a/web/src/routes/modules/+page.svelte +++ b/web/src/routes/modules/+page.svelte @@ -237,7 +237,9 @@ {m.priority} - {m.cron_expr ?? (m.refresh_interval_sec ? `${m.refresh_interval_sec}с` : '—')} + {m.cron_expr ?? (m.refresh_interval_sec !== null && m.refresh_interval_sec !== undefined + ? `${m.refresh_interval_sec}с` + : '—')} {#if m.enabled} diff --git a/web/src/routes/modules/[moduleId]/+page.svelte b/web/src/routes/modules/[moduleId]/+page.svelte index c76deff..9fc5722 100644 --- a/web/src/routes/modules/[moduleId]/+page.svelte +++ b/web/src/routes/modules/[moduleId]/+page.svelte @@ -74,6 +74,11 @@ import Save from '@lucide/svelte/icons/save'; import Upload from '@lucide/svelte/icons/upload'; import Download from '@lucide/svelte/icons/download'; + import Blocks from '@lucide/svelte/icons/blocks'; + import ArrowDownUp from '@lucide/svelte/icons/arrow-down-up'; + import Timer from '@lucide/svelte/icons/timer'; + import ShieldCheck from '@lucide/svelte/icons/shield-check'; + import Network from '@lucide/svelte/icons/network'; import { moduleTypeRu } from '$lib/ui-labels.js'; const moduleId = $derived(page.params.moduleId); @@ -150,6 +155,7 @@ let csvImporting = $state(false); let csvExporting = $state(false); let csvFileInput = $state(null); + const NONE_OPTION = '__none__'; const selectedAsCount = $derived(selectedAsIds.size); const selectedCdnCount = $derived(selectedCdnIds.size); const selectedDomainCount = $derived(selectedDomainIds.size); @@ -716,6 +722,14 @@ return t || c.community; } + function nullableSelectValue(value: string | null | undefined): string { + return value ?? NONE_OPTION; + } + + function fromNullableSelect(value: string): string | null { + return value === NONE_OPTION ? null : value; + } + const activeTab = $derived.by(() => { if (!mod) return 'entries'; switch (mod.type) { @@ -749,6 +763,12 @@ +

{mod.name}

@@ -780,22 +800,22 @@
- -

Приоритет

+ +

Приоритет

{mod.priority}

- -

Интервал

+ +

Интервал

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

- -

DoH профиль

+ +

DoH профиль

{mod.doh_profile_id ? mod.doh_profile_id.slice(0, 8) + '…' : '—'}

- -

Community по умолч.

+ +

Community по умолч.

{communityLabel(mod.default_community_id)}

@@ -1032,7 +1052,11 @@
{communityLabel(src.community_id)} - {src.refresh_interval_sec ? `${src.refresh_interval_sec}с` : '—'} + + {src.refresh_interval_sec !== null && src.refresh_interval_sec !== undefined + ? `${src.refresh_interval_sec}с` + : '—'} +
@@ -1252,12 +1276,18 @@
- { + editForm.default_community_id = fromNullableSelect(v); + }} + > {editForm.default_community_id ? communityLabel(editForm.default_community_id) : 'Не выбрано'} - Не выбрано + Не выбрано {#each communities as c (c.id)} {communityOptionLabel(c)} {/each} @@ -1266,12 +1296,18 @@
- { + editForm.doh_profile_id = fromNullableSelect(v); + }} + > {editForm.doh_profile_id ? (dohProfiles.find(d => d.id === editForm.doh_profile_id)?.url ?? editForm.doh_profile_id) : 'Не выбрано'} - Не выбрано + Не выбрано {#each dohProfiles as d (d.id)} {d.url} {/each} @@ -1334,12 +1370,18 @@
- { + asForm.community_id = fromNullableSelect(v); + }} + > {asForm.community_id ? communityLabel(asForm.community_id) : 'Не выбрано'} - Не выбрано + Не выбрано {#each communities as c (c.id)} {communityOptionLabel(c)} {/each} @@ -1431,12 +1473,18 @@
- { + cdnForm.community_id = fromNullableSelect(v); + }} + > {cdnForm.community_id ? communityLabel(cdnForm.community_id) : 'Не выбрано'} - Не выбрано + Не выбрано {#each communities as c (c.id)} {communityOptionLabel(c)} {/each} @@ -1518,12 +1566,18 @@
- { + domainForm.community_id = fromNullableSelect(v); + }} + > {domainForm.community_id ? communityLabel(domainForm.community_id) : 'Не выбрано'} - Не выбрано + Не выбрано {#each communities as c (c.id)} {communityOptionLabel(c)} {/each}