mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-02 01:42:53 -05:00
refac
This commit is contained in:
1 parent
858ab727d2
commit
67ac1a4e93
12 files changed
+382
-22
No files matched your search
@@ -23,6 +23,9 @@
|
||||
import AdminSettingRow from './AdminSettingRow.svelte';
|
||||
import AdminSettingSection from './AdminSettingSection.svelte';
|
||||
import Plus from '$lib/components/icons/Plus.svelte';
|
||||
import I18nSettings from './I18nSettings.svelte';
|
||||
import { updateI18n } from '$lib/i18n';
|
||||
import { entriesToI18n, i18nToEntries, type I18nEntry } from '$lib/utils/translationDictionary';
|
||||
|
||||
const i18n: any = getContext('i18n');
|
||||
|
||||
@@ -37,6 +40,8 @@
|
||||
let adminConfig: any = null;
|
||||
let defaultInterfaceSettings: Record<string, any> = {};
|
||||
let showUserUiDefaults = false;
|
||||
let uiI18nEntries: I18nEntry[] = [];
|
||||
let saving = false;
|
||||
|
||||
let banners: Banner[] = [];
|
||||
let bannerLocale = '';
|
||||
@@ -73,24 +78,37 @@
|
||||
};
|
||||
|
||||
const updateHandler = async () => {
|
||||
adminConfig.DEFAULT_INTERFACE_SETTINGS = defaultInterfaceSettings;
|
||||
|
||||
const res = await updateAdminConfig(localStorage.token, adminConfig);
|
||||
|
||||
await updateBanners();
|
||||
|
||||
await config.set(await getBackendConfig());
|
||||
|
||||
if (res) {
|
||||
if (saving) return;
|
||||
saving = true;
|
||||
try {
|
||||
const cleaned = entriesToI18n(uiI18nEntries);
|
||||
const res = await updateAdminConfig(localStorage.token, {
|
||||
...adminConfig,
|
||||
DEFAULT_INTERFACE_SETTINGS: defaultInterfaceSettings,
|
||||
I18N: cleaned
|
||||
});
|
||||
if (!res) throw new Error($i18n.t('Failed to update settings'));
|
||||
await updateI18n(res.I18N ?? cleaned);
|
||||
await updateBanners();
|
||||
await config.set(await getBackendConfig());
|
||||
saveHandler();
|
||||
} else {
|
||||
toast.error($i18n.t('Failed to update settings'));
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: Array.isArray(error)
|
||||
? error.map((entry) => entry.msg).join('\n')
|
||||
: String(error)
|
||||
);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
adminConfig = await getAdminConfig(localStorage.token);
|
||||
defaultInterfaceSettings = getDefaultInterfaceSettings();
|
||||
uiI18nEntries = i18nToEntries(adminConfig.I18N ?? {});
|
||||
|
||||
banners = [...$_banners];
|
||||
|
||||
@@ -396,6 +414,9 @@
|
||||
<Events />
|
||||
|
||||
<AdminSettingSection title={$i18n.t('UI')}>
|
||||
<fieldset id="ui-i18n-settings" disabled={saving} class="min-w-0">
|
||||
<I18nSettings bind:entries={uiI18nEntries} />
|
||||
</fieldset>
|
||||
<div class="shrink-0">
|
||||
<div class="flex items-center justify-between gap-4 py-0.5">
|
||||
<button
|
||||
@@ -463,7 +484,7 @@
|
||||
<LanguageModeSelect bind:value={bannerLocale} className="w-fit" />
|
||||
{/if}
|
||||
<button
|
||||
class="flex size-6 items-center justify-center rounded-lg text-gray-400 transition-colors hover:bg-black/5 hover:text-gray-900 dark:text-gray-600 dark:hover:bg-white/5 dark:hover:text-white"
|
||||
class="flex size-6 items-center justify-center text-gray-400 dark:text-gray-600"
|
||||
type="button"
|
||||
aria-label={$i18n.t('Add banner')}
|
||||
on:click={() => {
|
||||
@@ -499,6 +520,7 @@
|
||||
<button
|
||||
class="px-3.5 py-1.5 text-sm font-normal bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
>
|
||||
{$i18n.t('Save')}
|
||||
</button>
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<script lang="ts">
|
||||
import { getContext, tick } from 'svelte';
|
||||
import LanguageModeSelect from '$lib/components/common/LanguageModeSelect.svelte';
|
||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||
import Plus from '$lib/components/icons/Plus.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
import type { I18nEntry } from '$lib/utils/translationDictionary';
|
||||
import languages from '$lib/i18n/locales/languages.json';
|
||||
|
||||
const i18n = getContext<any>('i18n');
|
||||
export let entries: I18nEntry[] = [];
|
||||
let locale =
|
||||
languages.find((language) => language.code === $i18n.language)?.code ??
|
||||
languages.find((language) => language.code === $i18n.resolvedLanguage)?.code ??
|
||||
'en-US';
|
||||
let list: HTMLDivElement;
|
||||
const fieldClass =
|
||||
'block min-h-5 max-h-40 min-w-0 w-full resize-none bg-transparent text-[0.8125rem] leading-5 outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700 [field-sizing:content]';
|
||||
const add = async () => {
|
||||
if (!entries.length || entries.at(-1)?.content.trim()) {
|
||||
entries = [...entries, { content: '', i18n: {} }];
|
||||
}
|
||||
await tick();
|
||||
list.lastElementChild?.querySelector('textarea')?.focus();
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<div class="flex min-h-7 flex-wrap items-center justify-between gap-x-2 gap-y-1">
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400">{$i18n.t('UI Translations')}</div>
|
||||
<div class="ms-auto flex shrink-0 items-center gap-1">
|
||||
{#if entries.length}<LanguageModeSelect
|
||||
bind:value={locale}
|
||||
includeDefault={false}
|
||||
className="w-fit"
|
||||
/>{/if}
|
||||
<Tooltip content={$i18n.t('Add translation')}>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Add translation')}
|
||||
on:click={add}
|
||||
class="flex size-6 items-center justify-center text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
<Plus className="size-3.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<div bind:this={list} class="flex flex-col gap-1.5">
|
||||
{#each entries as entry, index (entry)}
|
||||
<div
|
||||
class="grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_1.5rem] items-center gap-2 rounded-lg border border-gray-100/40 px-2 py-1 transition focus-within:border-blue-400 dark:border-gray-850/50 dark:focus-within:border-blue-500"
|
||||
>
|
||||
<textarea
|
||||
rows="1"
|
||||
bind:value={entry.content}
|
||||
aria-label={$i18n.t('Key')}
|
||||
placeholder={$i18n.t('Key')}
|
||||
class="{fieldClass} text-gray-500 dark:text-gray-400"
|
||||
></textarea>
|
||||
<textarea
|
||||
rows="1"
|
||||
value={entry.i18n[locale]?.content ?? ''}
|
||||
aria-label={$i18n.t('Value')}
|
||||
placeholder={$i18n.t('Value')}
|
||||
class="{fieldClass} text-gray-700 dark:text-gray-200"
|
||||
on:input={(event) => {
|
||||
entry.i18n = { ...entry.i18n, [locale]: { content: event.currentTarget.value } };
|
||||
}}
|
||||
></textarea>
|
||||
<Tooltip content={$i18n.t('Delete')}>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Delete')}
|
||||
on:click={() => (entries = entries.filter((_, i) => i !== index))}
|
||||
class="flex size-6 shrink-0 items-center justify-center text-gray-400 hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300"
|
||||
>
|
||||
<XMark className="size-3.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -37,7 +37,7 @@
|
||||
<div class="flex flex-col gap-1.5" use:init>
|
||||
{#each banners as banner, bannerIdx (banner.id)}
|
||||
<div
|
||||
class="flex items-start gap-1 rounded-lg border border-gray-100/40 bg-transparent px-2 py-1 transition focus-within:border-gray-300 dark:border-gray-850/50 dark:focus-within:border-gray-600"
|
||||
class="flex items-start gap-1 rounded-lg border border-gray-100/40 bg-transparent px-2 py-1 transition focus-within:border-blue-400 dark:border-gray-850/50 dark:focus-within:border-blue-500"
|
||||
id="banner-item-{banner.id}"
|
||||
>
|
||||
<Tooltip content={$i18n.t('Reorder')}>
|
||||
|
||||
Reference in new issue
Block a user