- 모바일: 카드 클릭 시 detail 페이지로 이동 (뷰어 패널 미표시) - 스마트 그룹: 사이드바에 최근 7일/법령 알림/이메일 프리셋 필터 - 메모: user_note 컬럼 추가 (migration 004), PATCH API, PreviewPanel 인라인 편집 - 태그 편집: PreviewPanel에서 태그 추가(+)/삭제(×) 기능 - DB 모델 + API 스키마 user_note 필드 추가 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
232 lines
8.1 KiB
Svelte
232 lines
8.1 KiB
Svelte
<script>
|
||
import { X, ExternalLink, Plus, Save } from 'lucide-svelte';
|
||
import { api } from '$lib/api';
|
||
import { addToast } from '$lib/stores/ui';
|
||
import FormatIcon from './FormatIcon.svelte';
|
||
import TagPill from './TagPill.svelte';
|
||
|
||
let { doc, onclose } = $props();
|
||
|
||
// 메모 상태
|
||
let noteText = $state('');
|
||
let noteEditing = $state(false);
|
||
let noteSaving = $state(false);
|
||
|
||
// 태그 편집
|
||
let newTag = $state('');
|
||
let tagEditing = $state(false);
|
||
|
||
// doc 변경 시 메모 초기화
|
||
$effect(() => {
|
||
if (doc) {
|
||
noteText = doc.user_note || '';
|
||
noteEditing = false;
|
||
tagEditing = false;
|
||
newTag = '';
|
||
}
|
||
});
|
||
|
||
async function saveNote() {
|
||
noteSaving = true;
|
||
try {
|
||
await api(`/documents/${doc.id}`, {
|
||
method: 'PATCH',
|
||
body: JSON.stringify({ user_note: noteText }),
|
||
});
|
||
doc.user_note = noteText;
|
||
noteEditing = false;
|
||
addToast('success', '메모 저장됨');
|
||
} catch (err) {
|
||
addToast('error', '메모 저장 실패');
|
||
} finally {
|
||
noteSaving = false;
|
||
}
|
||
}
|
||
|
||
async function addTag() {
|
||
const tag = newTag.trim();
|
||
if (!tag) return;
|
||
const updatedTags = [...(doc.ai_tags || []), tag];
|
||
try {
|
||
await api(`/documents/${doc.id}`, {
|
||
method: 'PATCH',
|
||
body: JSON.stringify({ ai_tags: updatedTags }),
|
||
});
|
||
doc.ai_tags = updatedTags;
|
||
newTag = '';
|
||
addToast('success', '태그 추가됨');
|
||
} catch (err) {
|
||
addToast('error', '태그 추가 실패');
|
||
}
|
||
}
|
||
|
||
async function removeTag(tagToRemove) {
|
||
const updatedTags = (doc.ai_tags || []).filter(t => t !== tagToRemove);
|
||
try {
|
||
await api(`/documents/${doc.id}`, {
|
||
method: 'PATCH',
|
||
body: JSON.stringify({ ai_tags: updatedTags }),
|
||
});
|
||
doc.ai_tags = updatedTags;
|
||
addToast('success', '태그 삭제됨');
|
||
} catch (err) {
|
||
addToast('error', '태그 삭제 실패');
|
||
}
|
||
}
|
||
|
||
function formatDate(dateStr) {
|
||
if (!dateStr) return '-';
|
||
return new Date(dateStr).toLocaleDateString('ko-KR', { year: 'numeric', month: 'short', day: 'numeric' });
|
||
}
|
||
|
||
function formatSize(bytes) {
|
||
if (!bytes) return '-';
|
||
if (bytes < 1024) return `${bytes}B`;
|
||
if (bytes < 1048576) return `${(bytes / 1024).toFixed(0)}KB`;
|
||
return `${(bytes / 1048576).toFixed(1)}MB`;
|
||
}
|
||
</script>
|
||
|
||
<aside class="h-full flex flex-col bg-[var(--sidebar-bg)] border-l border-[var(--border)] overflow-y-auto">
|
||
<!-- 헤더 -->
|
||
<div class="flex items-center justify-between px-4 py-3 border-b border-[var(--border)] shrink-0">
|
||
<div class="flex items-center gap-2 min-w-0">
|
||
<FormatIcon format={doc.file_format} size={16} />
|
||
<span class="text-sm font-medium truncate">{doc.title || '제목 없음'}</span>
|
||
</div>
|
||
<div class="flex items-center gap-1">
|
||
<a href="/documents/{doc.id}" class="p-1 rounded hover:bg-[var(--surface)] text-[var(--text-dim)]" title="전체 보기">
|
||
<ExternalLink size={14} />
|
||
</a>
|
||
<button onclick={onclose} class="p-1 rounded hover:bg-[var(--surface)] text-[var(--text-dim)]" aria-label="닫기">
|
||
<X size={16} />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex-1 p-4 space-y-4">
|
||
<!-- 메모 -->
|
||
<div>
|
||
<h4 class="text-xs font-semibold text-[var(--text-dim)] uppercase mb-1.5">메모</h4>
|
||
{#if noteEditing}
|
||
<textarea
|
||
bind:value={noteText}
|
||
class="w-full h-24 px-3 py-2 bg-[var(--bg)] border border-[var(--border)] rounded-lg text-sm text-[var(--text)] resize-none outline-none focus:border-[var(--accent)]"
|
||
placeholder="메모 입력..."
|
||
></textarea>
|
||
<div class="flex gap-2 mt-1.5">
|
||
<button
|
||
onclick={saveNote}
|
||
disabled={noteSaving}
|
||
class="flex items-center gap-1 px-2 py-1 text-xs bg-[var(--accent)] text-white rounded hover:bg-[var(--accent-hover)] disabled:opacity-50"
|
||
>
|
||
<Save size={12} /> 저장
|
||
</button>
|
||
<button
|
||
onclick={() => { noteEditing = false; noteText = doc.user_note || ''; }}
|
||
class="px-2 py-1 text-xs text-[var(--text-dim)] hover:text-[var(--text)]"
|
||
>취소</button>
|
||
</div>
|
||
{:else}
|
||
<button
|
||
onclick={() => noteEditing = true}
|
||
class="w-full text-left px-3 py-2 bg-[var(--bg)] border border-[var(--border)] rounded-lg text-sm min-h-[40px]
|
||
{noteText ? 'text-[var(--text)]' : 'text-[var(--text-dim)]'}"
|
||
>
|
||
{noteText || '메모 추가...'}
|
||
</button>
|
||
{/if}
|
||
</div>
|
||
|
||
<!-- 태그 -->
|
||
<div>
|
||
<h4 class="text-xs font-semibold text-[var(--text-dim)] uppercase mb-1.5">태그</h4>
|
||
<div class="flex flex-wrap gap-1 mb-2">
|
||
{#each doc.ai_tags || [] as tag}
|
||
<span class="inline-flex items-center gap-0.5">
|
||
<TagPill {tag} clickable={false} />
|
||
<button
|
||
onclick={() => removeTag(tag)}
|
||
class="text-[var(--text-dim)] hover:text-[var(--error)] text-[10px]"
|
||
title="삭제"
|
||
>×</button>
|
||
</span>
|
||
{/each}
|
||
</div>
|
||
{#if tagEditing}
|
||
<form onsubmit={(e) => { e.preventDefault(); addTag(); }} class="flex gap-1">
|
||
<input
|
||
bind:value={newTag}
|
||
placeholder="태그 입력..."
|
||
class="flex-1 px-2 py-1 bg-[var(--bg)] border border-[var(--border)] rounded text-xs text-[var(--text)] outline-none focus:border-[var(--accent)]"
|
||
/>
|
||
<button type="submit" class="px-2 py-1 text-xs bg-[var(--accent)] text-white rounded">추가</button>
|
||
</form>
|
||
{:else}
|
||
<button
|
||
onclick={() => tagEditing = true}
|
||
class="flex items-center gap-1 text-xs text-[var(--text-dim)] hover:text-[var(--accent)]"
|
||
>
|
||
<Plus size={12} /> 태그 추가
|
||
</button>
|
||
{/if}
|
||
</div>
|
||
|
||
<!-- 메타 정보 -->
|
||
<div>
|
||
<h4 class="text-xs font-semibold text-[var(--text-dim)] uppercase mb-1.5">정보</h4>
|
||
<dl class="space-y-1.5 text-xs">
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">포맷</dt>
|
||
<dd class="uppercase">{doc.file_format}</dd>
|
||
</div>
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">크기</dt>
|
||
<dd>{formatSize(doc.file_size)}</dd>
|
||
</div>
|
||
{#if doc.ai_domain}
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">분류</dt>
|
||
<dd class="text-right">{doc.ai_domain.replace('Knowledge/', '')}{doc.ai_sub_group ? ` / ${doc.ai_sub_group}` : ''}</dd>
|
||
</div>
|
||
{/if}
|
||
{#if doc.source_channel}
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">출처</dt>
|
||
<dd>{doc.source_channel}</dd>
|
||
</div>
|
||
{/if}
|
||
{#if doc.data_origin}
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">구분</dt>
|
||
<dd>{doc.data_origin}</dd>
|
||
</div>
|
||
{/if}
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">등록일</dt>
|
||
<dd>{formatDate(doc.created_at)}</dd>
|
||
</div>
|
||
</dl>
|
||
</div>
|
||
|
||
<!-- 처리 상태 -->
|
||
<div>
|
||
<h4 class="text-xs font-semibold text-[var(--text-dim)] uppercase mb-1.5">처리</h4>
|
||
<dl class="space-y-1 text-xs">
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">추출</dt>
|
||
<dd class={doc.extracted_at ? 'text-[var(--success)]' : 'text-[var(--text-dim)]'}>{doc.extracted_at ? '완료' : '대기'}</dd>
|
||
</div>
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">분류</dt>
|
||
<dd class={doc.ai_processed_at ? 'text-[var(--success)]' : 'text-[var(--text-dim)]'}>{doc.ai_processed_at ? '완료' : '대기'}</dd>
|
||
</div>
|
||
<div class="flex justify-between">
|
||
<dt class="text-[var(--text-dim)]">임베딩</dt>
|
||
<dd class={doc.embedded_at ? 'text-[var(--success)]' : 'text-[var(--text-dim)]'}>{doc.embedded_at ? '완료' : '대기'}</dd>
|
||
</div>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</aside>
|