Files
faq_chatbot_frontend/src/app/pages/settings/settings.page.html
T
PeymanHonarjoo be17544f2d feat(voice): enhance streaming engine and improve system reliability
Improve the PCM playback worklet with robust resampling and buffer
management. Refactor the voice-stream service for better session
teardown and error handling. Fix authentication issues by enabling
credentials in HttpService and using relative URLs. Add Jalali date
support and an AI model configuration tab in settings. Enhance
diagnostics for voice transport and the audio engine.
2026-10-10 15:12:57 +03:30

1024 lines
49 KiB
HTML

<!-- prettier-ignore -->
<div class="settings-page max-w-6xl mx-auto px-4 py-8">
<header class="settings-header mb-8">
<h1 class="text-3xl font-semibold text-[var(--text-primary)] mb-1">تنظیمات</h1>
<p class="text-sm text-[var(--text-muted)]">مدیریت FAQ و ترجیحات برنامه</p>
</header>
<div
class="settings-card bg-[var(--card-bg)] rounded-2xl overflow-hidden shadow-[0_10px_40px_rgba(0,0,0,0.08),_0_2px_10px_rgba(0,0,0,0.04)]"
>
<nav class="settings-tabs flex bg-[var(--sidebar-hover)]" role="tablist">
<button
type="button"
class="tab-btn flex-1 flex items-center justify-center gap-2 px-4 py-3 text-sm font-medium text-[var(--text-muted)] transition-all duration-200 hover:text-[var(--text-primary)] relative"
[class.tab-active]="activeTab() === 'faq'"
(click)="selectTab('faq')"
role="tab"
[attr.aria-selected]="activeTab() === 'faq'"
>
<svg
class="w-4 h-4 transition-colors duration-200"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
<polyline points="17 8 12 3 7 8" />
<line x1="12" y1="3" x2="12" y2="15" />
</svg>
<span>آپلود FAQ</span>
@if (activeTab() === 'faq') {
<span
class="tab-indicator absolute bottom-0 left-1/2 -translate-x-1/2 w-6 h-0.5 bg-primary rounded-full"
></span>
}
</button>
<div class="tab-divider w-px h-6 bg-black/25"></div>
<button
type="button"
class="tab-btn flex-1 flex items-center justify-center gap-2 px-4 py-3 text-sm font-medium text-[var(--text-muted)] transition-all duration-200 hover:text-[var(--text-primary)] relative"
[class.tab-active]="activeTab() === 'app'"
(click)="selectTab('app')"
role="tab"
[attr.aria-selected]="activeTab() === 'app'"
>
<svg
class="w-4 h-4 transition-colors duration-200"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="3" />
<path
d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l-.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l-.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"
/>
</svg>
<span>تنظیمات برنامه</span>
@if (activeTab() === 'app') {
<span
class="tab-indicator absolute bottom-0 left-1/2 -translate-x-1/2 w-6 h-0.5 bg-primary rounded-full"
></span>
}
</button>
<div class="tab-divider w-px h-6 bg-black/25"></div>
<button
type="button"
class="tab-btn flex-1 flex items-center justify-center gap-2 px-4 py-3 text-sm font-medium text-[var(--text-muted)] transition-all duration-200 hover:text-[var(--text-primary)] relative"
[class.tab-active]="activeTab() === 'models'"
(click)="selectTab('models')"
role="tab"
[attr.aria-selected]="activeTab() === 'models'"
>
<svg
class="w-4 h-4 transition-colors duration-200"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" />
<path d="M19 10v2a7 7 0 0 1-14 0v-2" />
<line x1="12" x2="12" y1="19" y2="22" />
</svg>
<span>تنظیمات مدل‌های هوش مصنوعی</span>
@if (activeTab() === 'models') {
<span
class="tab-indicator absolute bottom-0 left-1/2 -translate-x-1/2 w-6 h-0.5 bg-primary rounded-full"
></span>
}
</button>
</nav>
<div class="settings-content p-6">
@if (activeTab() === 'faq') {
<section class="faq-section animate-fade-in">
<div class="section-header mb-6">
<h2
class="text-xl font-semibold text-[var(--text-primary)] mb-1 flex items-center gap-2"
>
<svg
class="w-5 h-5 text-primary"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
<polyline points="17 8 12 3 7 8" />
<line x1="12" y1="3" x2="12" y2="15" />
</svg>
آپلود سند FAQ
</h2>
<p class="text-sm text-[var(--text-muted)]">
فایل‌های {{ supportedFormatsLabel() }} خود را بکشید و رها کنید یا برای آپلود کلیک کنید.
</p>
@if (!capabilitiesLoaded() && !configLoading()) {
<p class="text-xs text-[var(--color-danger)] mt-1">
محدودیت‌های آپلود از سرور دریافت نشده‌اند؛ آپلود غیرفعال است.
</p>
}
@if (maxUploadBytes()) {
<p class="text-xs text-[var(--text-muted)] mt-1">
حداکثر حجم: {{ formatFileSize(maxUploadBytes()) }}
</p>
}
@if (pdfPageLimitLabel()) {
<p class="text-xs text-[var(--text-muted)] mt-1">
حداکثر تعداد صفحات PDF: {{ pdfPageLimitLabel() }}
</p>
}
@if (configError()) {
<p class="text-xs text-[var(--color-danger)] mt-1">{{ configError() }}</p>
}
</div>
<div
class="dropzone relative flex flex-col items-center justify-center gap-3 p-8 border-2 border-dashed border-[rgba(148,163,184,0.25)] rounded-xl bg-[var(--dropzone-bg)] cursor-pointer transition-all duration-300 hover:border-primary/50 hover:bg-primary/5 hover:shadow-[0_10px_30px_rgba(59,130,246,0.15)]"
[class.dropzone-active]="isDragging()"
[class.dropzone-disabled]="isUploading()"
(dragover)="onDragOver($event)"
(dragleave)="onDragLeave()"
(drop)="onDrop($event)"
(click)="fileInput.click()"
role="button"
tabindex="0"
(keydown.enter)="fileInput.click()"
(keydown.space)="$event.preventDefault(); fileInput.click()"
>
<input
#fileInput
id="faq-file-input"
type="file"
class="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
[accept]="supportedUploadAccept()"
multiple
[disabled]="isUploading()"
(change)="onFileSelected($event)"
/>
<div class="dropzone-icon-wrapper">
<svg
class="w-12 h-12 text-primary transition-transform duration-300"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
<polyline points="17 8 12 3 7 8" />
<line x1="12" y1="3" x2="12" y2="15" />
</svg>
</div>
<div class="dropzone-text text-center">
<p class="text-sm font-medium text-[var(--text-secondary)]">
فایل‌ها را اینجا رها کنید
</p>
<p class="text-xs text-[var(--text-muted)] mt-1">یا کلیک کنید برای انتخاب</p>
<p class="text-xs text-[var(--text-muted)] mt-2">پشتیبانی: {{ supportedFormatsLabel() }}</p>
</div>
</div>
@if (fileCount > 0 && !isUploading()) {
<div class="file-list mt-6 animate-slide-up">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-medium text-[var(--text-primary)] flex items-center gap-2">
<svg
class="w-5 h-5 text-primary"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
</svg>
فایل‌های انتخاب شده ({{ fileCount }})
</h3>
<button
type="button"
class="text-xs text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors duration-200"
(click)="clearAllFiles()"
>
پاک کردن همه
</button>
</div>
<ul class="space-y-2">
@for (file of uploadedFiles(); track $index) {
<li
class="file-item flex items-center justify-between gap-3 p-4 bg-[var(--card-bg)] rounded-xl shadow-[0_2px_8px_rgba(0,0,0,0.04)] transition-all duration-200 hover:shadow-[0_4px_16px_rgba(0,0,0,0.08)] hover:-translate-y-0.5"
>
<div class="flex items-center gap-3 min-w-0">
<div class="file-icon-wrapper p-2 bg-primary/10 rounded-lg shrink-0">
<svg
class="w-5 h-5 text-primary"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
</svg>
</div>
<div class="flex flex-col min-w-0">
<span class="text-sm font-medium text-[var(--text-secondary)] truncate">{{
file.name
}}</span>
<span class="text-xs text-[var(--text-muted)]">{{
formatFileSize(file.size)
}}</span>
</div>
</div>
<button
type="button"
class="file-remove-btn p-2 text-[var(--text-muted)] rounded-lg transition-all duration-200 hover:text-red-400 hover:bg-red-400/10 hover:scale-110 shrink-0"
(click)="removeFile($index)"
[attr.aria-label]="'حذف فایل ' + file.name"
>
<svg
class="w-4 h-4"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<line x1="18" y1="6" x2="6" y2="18" />
<line x1="6" y1="6" x2="18" y2="18" />
</svg>
</button>
</li>
}
</ul>
</div>
}
@if (fileCount > 0 && !isUploading()) {
<div class="upload-actions mt-4 flex items-center justify-between gap-3">
<button
type="button"
class="btn btn--primary"
(click)="uploadFiles()"
[disabled]="isUploading() || !capabilitiesLoaded() || !isAdmin()"
>
<span>آپلود فایل‌ها</span>
@if (!isAdmin()) {
<span class="text-xs">(مدیریت اسناد فقط برای ادمین‌ها)</span>
}
@if (!capabilitiesLoaded()) {
<span class="text-xs">(تنظیمات سرور بارگذاری نشد)</span>
}
</button>
</div>
}
@if (isUploading()) {
<div class="upload-queue mt-4 space-y-3" aria-live="polite" aria-label="وضعیت آپلود">
<h3 class="text-sm font-medium text-[var(--text-secondary)] mb-2">در حال آپلود...</h3>
@for (task of uploadQueue(); track $index) {
<div class="upload-task flex items-center gap-3">
<div class="flex-1 min-w-0">
<div class="flex items-center justify-between gap-2">
<span class="text-sm text-[var(--text-secondary)] truncate">{{ task.file.name }}</span>
<span class="text-xs text-[var(--text-muted)]">
@if (task.status === 'uploading') {
{{ task.progress }}%
} @else if (task.status === 'done') {
<span class="text-[var(--color-success)]">بارگذاری شد</span>
} @else {
<span class="text-[var(--color-danger)]">خطا</span>
}
</span>
</div>
<div class="upload-progress-bar mt-1 h-1.5 bg-[var(--surface-border)] rounded-full overflow-hidden">
<div
class="h-full bg-primary rounded-full transition-all duration-200"
[style.width]="(task.progress) + '%'"
></div>
</div>
@if (task.error) {
<p class="text-xs text-[var(--color-danger)] mt-1">{{ task.error }}</p>
}
</div>
@if (task.status === 'uploading') {
<button
type="button"
class="file-remove-btn p-1 text-[var(--text-muted)] rounded transition-colors hover:text-red-400"
(click)="cancelUpload($index)"
aria-label="لغو آپلود"
>
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18" />
<line x1="6" y1="6" x2="18" y2="18" />
</svg>
</button>
}
@if (task.status === 'error') {
<button
type="button"
class="file-remove-btn p-1 text-[var(--text-muted)] rounded transition-colors hover:text-[var(--color-primary)]"
(click)="retryUpload($index)"
aria-label="تلاش مجدد آپلود"
title="تلاش مجدد"
>
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<path d="M20 7v5h-5" />
<path d="M4 17v-5h5" />
<path d="M5.6 9a7 7 0 0 1 11.55-2.6L20 12" />
<path d="M4 12l2.85 5.6A7 7 0 0 0 18.4 15" />
</svg>
</button>
}
</div>
}
</div>
}
<!-- اسناد آپلود شده -->
<div class="documents-section mt-8">
@if (!isAdmin()) {
<div class="documents-locked flex flex-col items-center justify-center gap-3 py-10 text-center">
<svg
class="w-5 h-5 text-primary"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
<line x1="8" y1="13" x2="16" y2="13" />
<line x1="8" y1="17" x2="16" y2="17" />
</svg>
<p class="text-sm text-[var(--text-secondary)]">مدیریت و لیست اسناد فقط برای ادمین‌ها در دسترس است.</p>
</div>
}
@if (isAdmin()) {
<div class="section-header mb-4">
<h2 class="text-xl font-semibold text-[var(--text-primary)] mb-1 flex items-center gap-2">
<svg
class="w-5 h-5 text-primary"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
<line x1="8" y1="13" x2="16" y2="13" />
<line x1="8" y1="17" x2="16" y2="17" />
</svg>
اسناد آپلود شده
</h2>
<p class="text-sm text-[var(--text-muted)]">
فهرست اسناد ثبت‌شده و وضعیت پردازش آن‌ها. وضعیت در صف یا پردازش در حال پردازش به‌صورت خودکار به‌روز می‌شود.
</p>
</div>
@if (documentsLoading() && documents().length === 0) {
<div class="documents-loading flex items-center justify-center gap-2 py-10 text-[var(--text-muted)]">
<svg
class="w-5 h-5 animate-spin"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="9" stroke-opacity="0.2" />
<path d="M21 12a9 9 0 0 0-9-9" />
</svg>
<span>در حال بارگذاری اسناد...</span>
</div>
}
@if (documentsError() && documents().length === 0) {
<div class="documents-error flex flex-col items-center justify-center gap-3 py-10 text-center">
<p class="text-sm text-[var(--text-secondary)]">{{ documentsError() }}</p>
<button type="button" class="btn btn--outline" (click)="refreshDocuments()">
تلاش مجدد
</button>
</div>
}
@if (documents().length > 0) {
<div class="documents-filters mb-3 flex items-center justify-between gap-2">
<div class="flex items-center gap-2">
<select
class="form-select bg-[var(--color-input-bg)] text-[var(--text-secondary)] border border-[var(--color-input-border)] rounded-lg px-3 py-1.5 text-xs min-w-[130px] cursor-pointer"
[value]="activeFilter()"
(change)="activeFilter.set($any($event.target).value); applyDocumentFilters()"
>
<option value="all">همه وضعیت‌ها</option>
<option value="queued">در صف</option>
<option value="processing">در حال پردازش</option>
<option value="ready">آماده</option>
<option value="failed">ناموفق</option>
</select>
<label class="toggle-switch" [class.toggle-active]="activeOnly()">
<input type="checkbox" [checked]="activeOnly()" (change)="activeOnly.set($any($event.target).checked); applyDocumentFilters()" />
<span class="toggle-slider"></span>
</label>
<span class="text-xs text-[var(--text-muted)]">فقط فعال</span>
</div>
<button type="button" class="btn btn--outline" (click)="refreshDocuments()" [disabled]="documentsLoading()">
<svg
class="w-4 h-4"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M20 7v5h-5" />
<path d="M4 17v-5h5" />
<path d="M5.6 9a7 7 0 0 1 11.55-2.6L20 12" />
<path d="M4 12l2.85 5.6A7 7 0 0 0 18.4 15" />
</svg>
<span>به‌روزرسانی</span>
</button>
</div>
<div class="documents-table-wrapper overflow-x-auto rounded-xl border border-[var(--color-card-border)] bg-[var(--card-bg)]">
<table class="documents-table min-w-full text-sm text-right">
<thead class="bg-[var(--sidebar-hover)]">
<tr>
<th class="px-3 py-2 text-xs font-medium text-[var(--text-muted)]">نام فایل</th>
<th class="px-3 py-2 text-xs font-medium text-[var(--text-muted)]">عنوان سند</th>
<th class="px-3 py-2 text-xs font-medium text-[var(--text-muted)]">وضعیت پردازش</th>
<th class="px-3 py-2 text-xs font-medium text-[var(--text-muted)]">تعداد بخش‌ها</th>
<th class="px-3 py-2 text-xs font-medium text-[var(--text-muted)]">تاریخ آپلود</th>
<th class="px-3 py-2 text-xs font-medium text-[var(--text-muted)]">فعال‌سازی</th>
<th class="px-3 py-2 text-xs font-medium text-[var(--text-muted)]">عملیات</th>
</tr>
</thead>
<tbody class="divide-y divide-[var(--color-card-border)]">
@for (doc of documents(); track doc.id) {
<tr class="table-row-animate">
<td class="px-3 py-2.5 align-top">
<span class="text-sm text-[var(--text-secondary)] truncate block max-w-[14rem]"
>{{ doc.filename }}</span>
</td>
<td class="px-3 py-2.5 align-top">
<span class="text-sm text-[var(--text-secondary)]">{{ doc.title ?? '—' }}</span>
</td>
<td class="px-3 py-2.5 align-top">
<span
class="inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium"
[class.status-queued]="doc.status === 'queued'"
[class.status-processing]="doc.status === 'processing'"
[class.status-ready]="doc.status === 'ready'"
[class.status-failed]="doc.status === 'failed'"
>
<span class="status-dot" [class.dot-queued]="doc.status === 'queued'"
[class.dot-processing]="doc.status === 'processing'" [class.dot-ready]="doc.status === 'ready'"
[class.dot-failed]="doc.status === 'failed'"></span>
{{ statusLabel(doc.status) }}
</span>
@if (isReviewNeeded(doc)) {
<span class="block text-xs text-[var(--color-warning)] mt-1 font-medium">
نیازمند بازبینی ادمین
</span>
}
@if (doc.job.error; as jobError) {
<span class="block text-xs text-[var(--color-danger)] mt-1"
title="{{ jobError.message }}">{{ jobError.code }}</span>
}
</td>
<td class="px-3 py-2.5 align-top">
<span class="text-sm text-[var(--text-muted)]">{{ doc.chunk_count }}</span>
</td>
<td class="px-3 py-2.5 align-top">
<span class="text-sm text-[var(--text-muted)]">{{ formatDateTime(doc.created_at) }}</span>
</td>
<td class="px-3 py-2.5 align-top min-w-[11rem]">
@if (doc.status === 'ready' && !isReviewNeeded(doc) && isAdmin()) {
@if (togglingDocId() === doc.id) {
<div class="flex items-center gap-1.5 text-xs text-[var(--text-muted)]">
<svg
class="w-3 h-3 animate-spin"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
>
<circle cx="12" cy="12" r="9" stroke-opacity="0.2" />
<path d="M21 12a9 9 0 0 0-9-9" />
</svg>
<span>در حال به‌روزرسانی</span>
</div>
} @else {
<button
type="button"
class="active-toggle"
[class.active-toggle--on]="isDocumentActive(doc)"
(click)="toggleDocumentActive(doc)"
>
<span>{{ isDocumentActive(doc) ? 'فعال' : 'غیرفعال' }}</span>
</button>
}
} @else {
<span
class="text-xs"
[class.status-ready]="doc.is_active"
[class.status-failed]="!doc.is_active"
>{{ doc.is_active ? 'فعال' : 'غیرفعال' }}</span
>
}
</td>
<td class="px-3 py-2.5 align-top">
<div class="flex items-center gap-1.5">
@if (isReviewNeeded(doc) && doc.status === 'failed') {
<button
type="button"
class="btn btn--outline"
[disabled]="reviewingDocId() === doc.id"
(click)="openReview(doc)"
>
<svg
class="w-4 h-4"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" />
<circle cx="12" cy="12" r="3" />
</svg>
<span>بازبینی سند</span>
</button>
}
@if (canRetryDocument(doc)) {
<button
type="button"
class="btn btn--outline"
(click)="retryDocument(doc)"
>
<svg
class="w-4 h-4"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M20 7v5h-5" />
<path d="M4 17v-5h5" />
<path d="M5.6 9a7 7 0 0 1 11.55-2.6L20 12" />
<path d="M4 12l2.85 5.6A7 7 0 0 0 18.4 15" />
</svg>
<span>تلاش‌مجدد</span>
</button>
}
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
@if (!hasMoreDocuments() && !documentsLoading()) {
<p class="text-xs text-[var(--text-muted)] text-center mt-3">
{{ documents().length }} سند ثبت شده
</p>
}
@if (hasMoreDocuments() && !documentsLoading()) {
<div class="documents-pagination mt-3 text-center">
<button type="button" class="btn btn--outline" (click)="loadMoreDocuments()">
بیشتر بارگذاری
</button>
</div>
}
} @else {
@if (!documentsLoading() && !documentsError()) {
<div class="documents-empty flex flex-col items-center justify-center gap-3 py-10 text-center">
<svg class="w-10 h-10 text-[var(--text-muted)]" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="1.5" stroke-linecap="round"
stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
<polyline points="14 8 20 8 20 14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 a2 0 0 1 2-2h8z" />
</svg>
<p class="text-sm text-[var(--text-muted)]">هنوز سندی آپلود نشده است.</p>
</div>
}
}
}
</div>
<!-- Extraction review modal -->
@if (reviewingDocId()) {
<div class="review-backdrop" (click)="closeReview()">
<div
class="review-modal"
(click)="onReviewModalClick($event)"
role="dialog"
aria-modal="true"
aria-label="بازبینی سند"
>
<header class="review-modal-header">
<h3 class="text-lg font-semibold text-[var(--text-primary)]">بازبینی استخراج سند</h3>
<button type="button" class="file-remove-btn p-1 text-[var(--text-muted)]"
(click)="closeReview()" aria-label="بستن">
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18" />
<line x1="6" y1="6" x2="18" y2="18" />
</svg>
</button>
</header>
<div class="review-modal-body">
@if (reviewLoading()) {
<div class="review-loading flex items-center justify-center gap-2 py-8 text-[var(--text-muted)]">
<svg
class="w-5 h-5 animate-spin"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="9" stroke-opacity="0.2" />
<path d="M21 12a9 9 0 0 0-9-9" />
</svg>
<span>در حال بارگذاری شواهد...</span>
</div>
}
@if (!reviewLoading() && reviewItems().length === 0) {
<p class="text-sm text-[var(--text-muted)]">شاهده‌ای نیازمند بازبینی یافت نشد.</p>
}
@if (!reviewLoading() && reviewItems().length > 0) {
<div class="review-items space-y-5">
@for (item of reviewItems(); track item.evidence_sha256) {
<div class="review-item border border-[var(--color-card-border)] rounded-xl p-4 bg-[var(--surface-bg)]">
<div class="review-item-header flex items-center justify-between gap-2 mb-3">
<div class="text-xs text-[var(--text-muted)]">
<span>{{ reviewKindLabel(item) }}</span>
@if (item.location; as location) {
<span>
@if (location.page != null) { صفحه {{ location.page }} }
@if (location.section) { — {{ location.section }} }
</span>
}
</div>
@if (decisionFor(item) === 'approve' && isReviewSubmittable(item)) {
<span class="text-xs text-[var(--color-success)] font-medium">تکمیل شد</span>
}
</div>
<div class="review-item-body grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="review-preview min-h-[120px] flex items-center justify-center bg-[var(--sidebar-hover)] rounded-lg overflow-hidden">
@if (previewImageUrl(item); as previewUrl) {
<img
[src]="previewUrl"
[alt]="'پیش‌نمایش صفحه ' + (item.location?.page ?? '')"
class="max-w-full max-h-48 object-contain"
loading="lazy"
/>
} @else {
<span class="text-xs text-[var(--text-muted)]">پیش‌نمایشی موجود نیست</span>
}
</div>
<div class="review-content space-y-3">
<div>
<label class="block text-xs font-medium text-[var(--text-secondary)] mb-1">
متن استخراج‌شده
</label>
<ul class="text-xs text-[var(--text-secondary)] space-y-1 max-h-36 overflow-y-auto pr-2">
@for (block of item.blocks; track block.block_id) {
<li class="leading-relaxed">{{ block.text }}</li>
}
</ul>
</div>
<div>
<label class="block text-xs font-medium text-[var(--text-secondary)] mb-1">
بررسی‌های الزامی
</label>
<ul class="space-y-1 text-xs">
@for (check of item.required_checks; track check) {
<li class="flex items-center gap-2">
<input
type="checkbox"
[id]="item.evidence_sha256 + '-' + check"
[checked]="isCheckChecked(item, check)"
(change)="toggleCheck(item, check, $any($event.target).checked)"
/>
<label [attr.for]="item.evidence_sha256 + '-' + check" class="text-[var(--text-secondary)] cursor-pointer">{{ checkLabel(check) }}</label>
</li>
}
</ul>
</div>
<div>
<label class="block text-xs font-medium text-[var(--text-secondary)] mb-1">
تصمیم
</label>
<div class="flex items-center gap-3 text-xs">
<label class="flex items-center gap-1.5 cursor-pointer">
<input type="radio" name="decision-{{ item.evidence_sha256 }}"
value="approve" [checked]="decisionFor(item) === 'approve'"
(change)="setDecision(item, 'approve')" />
<span class="text-[var(--text-secondary)]">تایید</span>
</label>
<label class="flex items-center gap-1.5 cursor-pointer">
<input type="radio" name="decision-{{ item.evidence_sha256 }}"
value="reject" [checked]="decisionFor(item) === 'reject'"
(change)="setDecision(item, 'reject')" />
<span class="text-[var(--text-secondary)]">رد</span>
</label>
</div>
</div>
<div>
<label class="block text-xs font-medium text-[var(--text-secondary)] mb-1">
یادداشت بازبینی (الزامی)
</label>
<textarea
class="form-input w-full text-xs"
rows="2"
[value]="noteFor(item)"
(input)="setNote(item, $any($event.target).value)"
placeholder="مثال: با صفحه اصلی مقایسه و تاریخ و ساعت تأیید شد."
></textarea>
</div>
@if (item.review_kind !== 'extraction') {
<div>
<label class="block text-xs font-medium text-[var(--text-secondary)] mb-1">
شناسه گروه‌های حذف‌شده (اختیاری)
</label>
<input
type="text"
class="form-input w-full text-xs"
[value]="excludedGroupIdsFor(item)"
(input)="setExcludedGroupIds(item, $any($event.target).value)"
placeholder="با کامای جدا کنید"
/>
</div>
}
</div>
</div>
<div class="review-item-actions flex items-center justify-end gap-2 mt-3">
<button
type="button"
class="btn btn--primary"
[disabled]="!isReviewSubmittable(item)"
(click)="submitReviewDecision(item)"
>
<span>ثبت تصمیم بازبینی</span>
</button>
</div>
</div>
}
</div>
}
</div>
<footer class="review-modal-footer border-t border-[var(--color-card-border)] p-3 flex justify-end gap-2">
@if (canRetryAfterReview()) {
<button type="button" class="btn btn--primary" (click)="finishReviewAndRetry()">
<svg
class="w-4 h-4"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M3 2v6h6" />
<path d="M21 12a9 9 0 0 0-15-6.7L3 8" />
<path d="M21 22v-6h-6" />
<path d="M3 12a9 9 0 0 0 15 6.7L21 16" />
</svg>
<span>بستن و تلاش مجدد پردازش</span>
</button>
}
<button type="button" class="btn btn--outline" (click)="closeReview()">
<span>بستن</span>
</button>
</footer>
</div>
</div>
}
</section>
}
@if (activeTab() === 'app') {
<section class="app-section animate-fade-in">
<div class="section-header mb-6">
<h2
class="text-xl font-semibold text-[var(--text-primary)] mb-1 flex items-center gap-2"
>
<svg
class="w-5 h-5 text-primary"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="3" />
<path
d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l-.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l-.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l-.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"
/>
</svg>
تنظیمات کلی
</h2>
</div>
<div class="settings-grid space-y-3">
<div
class="setting-item flex items-center justify-between gap-4 p-4 bg-[var(--card-bg)] rounded-xl shadow-[0_2px_8px_rgba(0,0,0,0.04)] transition-all duration-200 hover:shadow-[0_4px_16px_rgba(0,0,0,0.08)] hover:-translate-y-0.5"
>
<div class="setting-info flex flex-col gap-1 min-w-0">
<span class="text-sm font-medium text-[var(--text-secondary)]">حالت تاریک</span>
<span class="text-xs text-[var(--text-muted)]">تغییر ظاهر برنامه به حالت تیره</span>
</div>
<div class="setting-control shrink-0">
<label class="toggle-switch" [class.toggle-active]="isDarkMode()">
<input type="checkbox" [checked]="isDarkMode()" (change)="toggleDarkMode()" />
<span class="toggle-slider"></span>
</label>
</div>
</div>
<div
class="setting-item flex items-center justify-between gap-4 p-4 bg-[var(--card-bg)] rounded-xl shadow-[0_2px_8px_rgba(0,0,0,0.04)] transition-all duration-200 hover:shadow-[0_4px_16px_rgba(0,0,0,0.08)] hover:-translate-y-0.5"
>
<div class="setting-info flex flex-col gap-1 min-w-0">
<label class="text-sm font-medium text-[var(--text-secondary)] cursor-pointer">
نیاز به تأیید ادمین برای اسناد OCR شده
</label>
<span class="text-xs text-[var(--text-muted)] block mt-0.5">
در صورت فعال بودن، محتوای استخراج‌شده از اسناد باید توسط ادمین بازبینی و تأیید شود.
</span>
<!-- <span class="text-xs text-[var(--color-warning)] mt-0.5">پیش‌نویس — ذخیره‌سازی در فاز MVP پشتیبانی نمی‌شود</span> -->
</div>
<div class="setting-control shrink-0">
<label class="toggle-switch" [class.toggle-active]="ocrAdminApproval()">
<input type="checkbox" [checked]="ocrAdminApproval()" (change)="toggleOcrApproval()" />
<span class="toggle-slider"></span>
</label>
</div>
</div>
</div>
</section>
}
@if (activeTab() === 'models') {
<section class="models-section animate-fade-in">
<div class="section-header mb-6">
<h2 class="text-xl font-semibold text-[var(--text-primary)] mb-1 flex items-center gap-2">
<svg class="w-5 h-5 text-primary" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" />
<path d="M19 10v2a7 7 0 0 1-14 0v-2" />
<line x1="12" x2="12" y1="19" y2="22" />
</svg>
تنظیمات مدل‌های هوش مصنوعی
</h2>
<p class="text-sm text-[var(--text-muted)]">
هر کارت به‌صورت مستقل پیکربندی می‌شود. در فاز MVP، این تنظیمات در حافظه نگهداری می‌شوند و به سرور ارسال نمی‌شوند.
</p>
</div>
<div class="ai-models-grid grid grid-cols-1 lg:grid-cols-2 gap-6">
<app-ai-model-config-card
title="تنظیمات مدل هوش مصنوعی"
task="text"
[config]="textModelConfig()"
(configChange)="textModelConfig.set($event)"
[connected]="textModelConnected()"
(save)="saveModelConfig('text')"
(testConnection)="testModelConnection('text')"
></app-ai-model-config-card>
<app-ai-model-config-card
title="تنظیمات مدل امبدینگ"
task="embedding"
[config]="embeddingModelConfig()"
(configChange)="embeddingModelConfig.set($event)"
[connected]="embeddingModelConnected()"
(save)="saveModelConfig('embedding')"
(testConnection)="testModelConnection('embedding')"
></app-ai-model-config-card>
<app-ai-model-config-card
title="تنظیمات مدل OCR"
task="ocr"
[config]="ocrModelConfig()"
(configChange)="ocrModelConfig.set($event)"
[connected]="ocrModelConnected()"
(save)="saveModelConfig('ocr')"
(testConnection)="testModelConnection('ocr')"
></app-ai-model-config-card>
</div>
<div class="mt-8">
<h3 class="text-lg font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2">
<svg class="w-5 h-5 text-primary" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" />
<path d="M19 10v2a7 7 0 0 1-14 0v-2" />
<line x1="12" x2="12" y1="19" y2="22" />
</svg>
تنظیمات مدل‌های داخلی
</h3>
<p class="text-xs text-[var(--text-muted)] mb-4">
مدل‌های داخلی مرکز تماس — تبدیل گفتار به نوشتار، تبدیل نوشتار به گفتار و مدل گفتگو —
هر کارت به‌صورت مستقل پیکربندی می‌شود. در فاز MVP، این تنظیمات در حافظه نگهداری می‌شوند و به
سرور ارسال نمی‌شوند.
</p>
<div class="ai-models-grid grid grid-cols-1 lg:grid-cols-2 gap-6">
<app-ai-model-config-card
title="تنظیمات مدل تبدیل گفتار به نوشتار"
task="stt"
[config]="sttModelConfig()"
(configChange)="sttModelConfig.set($event)"
[connected]="sttModelConnected()"
(save)="saveModelConfig('stt')"
(testConnection)="testModelConnection('stt')"
></app-ai-model-config-card>
<app-ai-model-config-card
title="تنظیمات مدل تبدیل نوشتار به گفتار"
task="tts"
[config]="ttsModelConfig()"
(configChange)="ttsModelConfig.set($event)"
[connected]="ttsModelConnected()"
(save)="saveModelConfig('tts')"
(testConnection)="testModelConnection('tts')"
></app-ai-model-config-card>
<app-ai-model-config-card
title="تنظیمات مدل گفتگوی داخلی"
task="dialogue"
[config]="dialogueModelConfig()"
(configChange)="dialogueModelConfig.set($event)"
[connected]="dialogueModelConnected()"
(save)="saveModelConfig('dialogue')"
(testConnection)="testModelConnection('dialogue')"
></app-ai-model-config-card>
</div>
</div>
</section>
}
</div>
</div>
</div>