mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
refac: notes
This commit is contained in:
parent
2fbff741da
commit
9b8d6ed6d2
3 changed files with 47 additions and 12 deletions
|
|
@ -125,11 +125,10 @@ class NoteTable:
|
||||||
if not note:
|
if not note:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
form_data = form_data.model_dump(exclude_none=True)
|
form_data = form_data.model_dump(exclude_unset=True)
|
||||||
|
|
||||||
if "title" in form_data:
|
if "title" in form_data:
|
||||||
note.title = form_data["title"]
|
note.title = form_data["title"]
|
||||||
|
|
||||||
if "data" in form_data:
|
if "data" in form_data:
|
||||||
note.data = form_data["data"]
|
note.data = form_data["data"]
|
||||||
if "meta" in form_data:
|
if "meta" in form_data:
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
import ChatBubbleOval from '../icons/ChatBubbleOval.svelte';
|
import ChatBubbleOval from '../icons/ChatBubbleOval.svelte';
|
||||||
import Settings from './NoteEditor/Settings.svelte';
|
import Settings from './NoteEditor/Settings.svelte';
|
||||||
import Chat from './NoteEditor/Chat.svelte';
|
import Chat from './NoteEditor/Chat.svelte';
|
||||||
|
import AccessControlModal from '$lib/components/workspace/common/AccessControlModal.svelte';
|
||||||
|
|
||||||
async function loadLocale(locales) {
|
async function loadLocale(locales) {
|
||||||
for (const locale of locales) {
|
for (const locale of locales) {
|
||||||
|
|
@ -117,6 +118,7 @@
|
||||||
let selectedPanel = 'chat';
|
let selectedPanel = 'chat';
|
||||||
|
|
||||||
let showDeleteConfirm = false;
|
let showDeleteConfirm = false;
|
||||||
|
let showAccessControlModal = false;
|
||||||
|
|
||||||
let dragged = false;
|
let dragged = false;
|
||||||
let loading = false;
|
let loading = false;
|
||||||
|
|
@ -156,15 +158,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
debounceTimeout = setTimeout(async () => {
|
debounceTimeout = setTimeout(async () => {
|
||||||
if (!note || enhancing || versionIdx !== null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Saving note:', note);
|
|
||||||
|
|
||||||
const res = await updateNoteById(localStorage.token, id, {
|
const res = await updateNoteById(localStorage.token, id, {
|
||||||
...note,
|
title: note?.title === '' ? $i18n.t('Untitled') : note.title,
|
||||||
title: note.title === '' ? $i18n.t('Untitled') : note.title
|
access_control: note?.access_control
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
toast.error(`${e}`);
|
toast.error(`${e}`);
|
||||||
});
|
});
|
||||||
|
|
@ -712,6 +708,17 @@ Provide the enhanced notes in markdown format. Use markdown syntax for headings,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if note}
|
||||||
|
<AccessControlModal
|
||||||
|
bind:show={showAccessControlModal}
|
||||||
|
bind:accessControl={note.access_control}
|
||||||
|
accessRoles={['read', 'write']}
|
||||||
|
onChange={() => {
|
||||||
|
changeDebounceHandler();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<FilesOverlay show={dragged} />
|
<FilesOverlay show={dragged} />
|
||||||
|
|
||||||
<DeleteConfirmDialog
|
<DeleteConfirmDialog
|
||||||
|
|
@ -765,6 +772,7 @@ Provide the enhanced notes in markdown format. Use markdown syntax for headings,
|
||||||
bind:value={note.title}
|
bind:value={note.title}
|
||||||
placeholder={$i18n.t('Title')}
|
placeholder={$i18n.t('Title')}
|
||||||
required
|
required
|
||||||
|
on:input={changeDebounceHandler}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="flex items-center gap-0.5 translate-x-1">
|
<div class="flex items-center gap-0.5 translate-x-1">
|
||||||
|
|
@ -800,6 +808,16 @@ Provide the enhanced notes in markdown format. Use markdown syntax for headings,
|
||||||
onDownload={(type) => {
|
onDownload={(type) => {
|
||||||
downloadHandler(type);
|
downloadHandler(type);
|
||||||
}}
|
}}
|
||||||
|
onCopyLink={async () => {
|
||||||
|
const baseUrl = window.location.origin;
|
||||||
|
const res = await copyToClipboard(`${baseUrl}/notes/${note.id}`);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
toast.success($i18n.t('Copied link to clipboard'));
|
||||||
|
} else {
|
||||||
|
toast.error($i18n.t('Failed to copy link'));
|
||||||
|
}
|
||||||
|
}}
|
||||||
onCopyToClipboard={async () => {
|
onCopyToClipboard={async () => {
|
||||||
const res = await copyToClipboard(note.data.content.md).catch((error) => {
|
const res = await copyToClipboard(note.data.content.md).catch((error) => {
|
||||||
toast.error(`${error}`);
|
toast.error(`${error}`);
|
||||||
|
|
@ -877,10 +895,15 @@ Provide the enhanced notes in markdown format. Use markdown syntax for headings,
|
||||||
<span>{dayjs(note.created_at / 1000000).calendar()}</span>
|
<span>{dayjs(note.created_at / 1000000).calendar()}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button class=" flex items-center gap-1 w-fit py-1 px-1.5 rounded-lg min-w-fit">
|
<button
|
||||||
|
class=" flex items-center gap-1 w-fit py-1 px-1.5 rounded-lg min-w-fit"
|
||||||
|
on:click={() => {
|
||||||
|
showAccessControlModal = true;
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Users className="size-3.5" strokeWidth="2" />
|
<Users className="size-3.5" strokeWidth="2" />
|
||||||
|
|
||||||
<span> You </span>
|
<span> {note?.access_control ? $i18n.t('Private') : $i18n.t('Everyone')} </span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{#if editor}
|
{#if editor}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
||||||
import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
|
import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
|
||||||
import Share from '$lib/components/icons/Share.svelte';
|
import Share from '$lib/components/icons/Share.svelte';
|
||||||
|
import Link from '$lib/components/icons/Link.svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
|
@ -21,6 +22,8 @@
|
||||||
|
|
||||||
export let onDownload = (type) => {};
|
export let onDownload = (type) => {};
|
||||||
export let onDelete = () => {};
|
export let onDelete = () => {};
|
||||||
|
|
||||||
|
export let onCopyLink = () => {};
|
||||||
export let onCopyToClipboard = () => {};
|
export let onCopyToClipboard = () => {};
|
||||||
|
|
||||||
export let onChange = () => {};
|
export let onChange = () => {};
|
||||||
|
|
@ -99,6 +102,16 @@
|
||||||
transition={flyAndScale}
|
transition={flyAndScale}
|
||||||
sideOffset={8}
|
sideOffset={8}
|
||||||
>
|
>
|
||||||
|
<DropdownMenu.Item
|
||||||
|
class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
||||||
|
on:click={() => {
|
||||||
|
onCopyLink();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Link />
|
||||||
|
<div class="flex items-center">{$i18n.t('Copy link')}</div>
|
||||||
|
</DropdownMenu.Item>
|
||||||
|
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue