From a6c466e1bacbd7e4ad0c30a9aff28f656ef46986 Mon Sep 17 00:00:00 2001 From: PeymanHonarjoo Date: Sun, 11 Oct 2026 17:25:28 +0330 Subject: [PATCH] feat(settings): implement document removal and responsive table layout Add a confirmation workflow for removing documents and refactor the documents table to support responsive layouts. The table now uses a fixed layout with defined column widths and handles overflow on mobile devices. The redundant filename column has been removed. --- src/app/pages/settings/settings.page.css | 54 +++++++++ src/app/pages/settings/settings.page.html | 119 +++++++++++++++++-- src/app/pages/settings/settings.page.spec.ts | 94 ++++++++++++++- src/app/pages/settings/settings.page.ts | 34 ++++++ 4 files changed, 289 insertions(+), 12 deletions(-) diff --git a/src/app/pages/settings/settings.page.css b/src/app/pages/settings/settings.page.css index 64cc985..8f8c67e 100644 --- a/src/app/pages/settings/settings.page.css +++ b/src/app/pages/settings/settings.page.css @@ -208,6 +208,10 @@ background-color: color-mix(in srgb, var(--color-primary) 78%, #000); } +.file-remove-btn:hover{ + cursor: pointer; +} + @keyframes fadeInDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } @@ -428,6 +432,50 @@ } .documents-table-wrapper { border: 1px solid var(--color-card-border); + /* Clip the table to the rounded corners on wide layouts. */ + overflow: hidden; +} + +/* + * md and below (Tailwind md = 48rem/768px). + * + * Six fixed-percentage columns stop being readable well before 768px: the date wraps, + * and the status column's error text overflows its column and bleeds into the + * neighbouring cells — which is what makes the row contents look mixed. + * + * Switching to `table-layout: auto` lets each column size to its own content, so no + * cell can overflow into the next one. The table then grows past the card and the + * wrapper scrolls horizontally instead of squeezing the columns. + */ +@media (max-width: 767.98px) { + .documents-table-wrapper { + overflow-x: auto; + /* Keep the scroll chain inside the card instead of leaking to the page. */ + overscroll-behavior-x: contain; + -webkit-overflow-scrolling: touch; + } + + .documents-table { + /* Auto layout ignores the percentages, so columns follow their content. */ + table-layout: auto; + min-width: 720px; + } + + /* Short cells stay on one line so each column keeps a clean width. */ + .documents-table th, + .documents-table td { + white-space: nowrap; + } + + /* Title and status hold long text; let them wrap instead of widening the table. */ + .documents-table td:nth-child(1), + .documents-table td:nth-child(2) { + white-space: normal; + } + + .documents-table td:nth-child(1) { + max-width: 220px; + } } .documents-table { border-collapse: separate; @@ -439,6 +487,8 @@ text-align: right; vertical-align: top; border-bottom: 1px solid var(--color-card-border); + /* Fixed layout fits the card; wrap long tokens so a cell never widens the table. */ + overflow-wrap: anywhere; } .documents-table thead th { background: var(--sidebar-hover); @@ -562,6 +612,10 @@ padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-card-border); } +/* Narrower variant for confirmations (e.g. remove document). */ +.review-modal--sm { + max-width: 30rem; +} .review-modal-body { padding: 1.25rem; overflow-y: auto; diff --git a/src/app/pages/settings/settings.page.html b/src/app/pages/settings/settings.page.html index 09f05fc..234c05b 100644 --- a/src/app/pages/settings/settings.page.html +++ b/src/app/pages/settings/settings.page.html @@ -496,11 +496,18 @@ -
- +
+
+ + + + + + + + - @@ -513,11 +520,9 @@ @for (doc of documents(); track doc.id) { - - @@ -639,7 +668,7 @@ @if (!documentsLoading()) {
نام فایل عنوان سند وضعیت پردازش تعداد بخش‌ها
- {{ doc.filename }} - - {{ doc.title ?? '—' }} + {{ + doc.title ?? '—' + }} {{ formatDateTime(doc.created_at) }} + @if (doc.status === 'ready' && !isReviewNeeded(doc) && isAdmin()) { @if (togglingDocId() === doc.id) {
@@ -632,6 +637,30 @@ تلاش‌مجدد } +
هیچ سندی با فیلتر انتخاب‌شده مطابقت ندارد. @@ -884,6 +913,57 @@ } + + + @if (deletingDoc(); as doc) { +
+
+
+

حذف سند

+ +
+
+

+ آیا از حذف سند «{{ doc.title ?? doc.filename }}» مطمئن هستید؟ این عملیات قابل بازگشت نیست. +

+
+
+ + +
+
+
+ } } @@ -946,6 +1026,25 @@ + +
+
+ + + در صورت فعال بودن، محتوای استخراج‌شده از اسناد FAQ باید توسط ادمین بازبینی و تأیید شود. + +
+
+ +
+
diff --git a/src/app/pages/settings/settings.page.spec.ts b/src/app/pages/settings/settings.page.spec.ts index b1a1bd8..eba9f69 100644 --- a/src/app/pages/settings/settings.page.spec.ts +++ b/src/app/pages/settings/settings.page.spec.ts @@ -30,12 +30,18 @@ function readyDoc(): DocumentListItem { }; } +const toastr = { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() }; + const filterSelect = (el: HTMLElement): HTMLSelectElement | null => el.querySelector('.documents-filters select'); describe('SettingsPage — document filters', () => { let getDocuments: ReturnType; beforeEach(async () => { + toastr.success.mockClear(); + toastr.error.mockClear(); + toastr.warning.mockClear(); + toastr.info.mockClear(); // Server-side filtering: `all` returns one ready doc; every other status matches none. getDocuments = vi.fn((params: { status?: string } = {}): Observable => { const items = params.status ? [] : [readyDoc()]; @@ -59,7 +65,7 @@ describe('SettingsPage — document filters', () => { { provide: AuthService, useValue: { getCurrentUserValue: () => ({ role: 'admin' }) } }, { provide: HttpService, useValue: { apiUrl: '/api/v1' } }, { provide: ThemeService, useValue: { isDarkMode: () => false, toggleDarkMode: () => {} } }, - { provide: ToastrService, useValue: { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() } }, + { provide: ToastrService, useValue: toastr }, ], }).compileComponents(); }); @@ -108,7 +114,91 @@ describe('SettingsPage — document filters', () => { fixture.detectChanges(); const rows = (fixture.nativeElement as HTMLElement).querySelectorAll('.documents-table tbody tr'); expect(rows.length).toBe(1); - expect(rows[0].textContent).toContain('guide.pdf'); + // نام فایل column was dropped (redundant with عنوان سند); the row shows the title. + expect(rows[0].textContent).toContain('سند آزمون'); + expect(rows[0].textContent).not.toContain('guide.pdf'); + }); + + it('drops the redundant نام فایل column and renders exactly 6 columns', () => { + const fixture = TestBed.createComponent(SettingsPage); + fixture.detectChanges(); + const el = fixture.nativeElement as HTMLElement; + + const headers = Array.from(el.querySelectorAll('.documents-table thead th')).map((t) => + t.textContent?.trim(), + ); + expect(headers).toEqual([ + 'عنوان سند', + 'وضعیت پردازش', + 'تعداد بخش‌ها', + 'تاریخ آپلود', + 'فعال‌سازی', + 'عملیات', + ]); + expect(headers).not.toContain('نام فایل'); + // A data row has exactly 6 cells matching the 6 columns. + expect(el.querySelector('.documents-table tbody tr')?.children.length).toBe(6); + }); + + it('confirms before removing: the bin button opens a modal, cancel keeps the doc, confirm shows the MVP notice', () => { + const fixture = TestBed.createComponent(SettingsPage); + fixture.detectChanges(); + const el = fixture.nativeElement as HTMLElement; + + const openRemoveModal = () => { + const row = el.querySelector('.documents-table tbody tr') as HTMLElement; + const remove = Array.from(row.querySelectorAll('button')).find((b) => + (b.getAttribute('aria-label') ?? '').includes('حذف سند'), + ) as HTMLButtonElement; + remove.click(); + fixture.detectChanges(); + }; + + openRemoveModal(); + const modal = el.querySelector('[role="alertdialog"]') as HTMLElement; + expect(modal).toBeTruthy(); + expect(modal.textContent).toContain('سند آزمون'); + expect(modal.textContent).toContain('مطمئن هستید'); + expect(toastr.info).not.toHaveBeenCalled(); // nothing happens until confirmed + + // Cancel closes the modal and keeps the document, with no notice. + (modal.querySelector('.btn--outline') as HTMLButtonElement).click(); + fixture.detectChanges(); + expect(el.querySelector('[role="alertdialog"]')).toBeNull(); + expect(el.querySelectorAll('.documents-table tbody tr').length).toBe(1); + expect(toastr.info).not.toHaveBeenCalled(); + + // Confirm closes the modal and surfaces the MVP notice (deletion is not yet implemented); + // the row is left in place and no backend delete call is made. + openRemoveModal(); + (el.querySelector('[role="alertdialog"] .btn--primary') as HTMLButtonElement).click(); + fixture.detectChanges(); + expect(toastr.info).toHaveBeenCalledTimes(1); + expect(el.querySelector('[role="alertdialog"]')).toBeNull(); + expect(el.querySelectorAll('.documents-table tbody tr').length).toBe(1); + }); + + it('renders OCR and FAQ admin-approval toggles in the app settings and toggles FAQ', () => { + const fixture = TestBed.createComponent(SettingsPage); + fixture.detectChanges(); + const component = fixture.componentInstance; + component.selectTab('app'); + fixture.detectChanges(); + const el = fixture.nativeElement as HTMLElement; + + const labels = Array.from(el.querySelectorAll('.setting-info label')).map((l) => + l.textContent?.trim(), + ); + expect(labels).toContain('نیاز به تأیید ادمین برای اسناد OCR شده'); + expect(labels).toContain('نیاز به تأیید ادمین برای اسناد FAQ'); + + // Toggles in order: dark mode, OCR, FAQ. The FAQ toggle flips its own signal. + const switches = el.querySelectorAll('.setting-control .toggle-switch'); + expect(switches.length).toBe(3); + expect(component.faqAdminApproval()).toBe(false); + (switches[2].querySelector('input') as HTMLInputElement).click(); + fixture.detectChanges(); + expect(component.faqAdminApproval()).toBe(true); }); it('hasActiveFilters reflects the active status/active-only filters', () => { diff --git a/src/app/pages/settings/settings.page.ts b/src/app/pages/settings/settings.page.ts index 6bca86c..4616a0c 100644 --- a/src/app/pages/settings/settings.page.ts +++ b/src/app/pages/settings/settings.page.ts @@ -241,6 +241,8 @@ export class SettingsPage implements OnInit, OnDestroy { // ---- knowledge selection (K01/K02) ---- readonly knowledgeSelection = signal(null); readonly togglingDocId = signal(null); + /** Document awaiting remove confirmation (non-null while the confirm modal is open). */ + readonly deletingDoc = signal(null); // ---- extraction review modal (D06/D07) ---- readonly reviewingDocId = signal(null); @@ -256,6 +258,7 @@ export class SettingsPage implements OnInit, OnDestroy { readonly notificationsEnabled = signal(true); readonly isDarkMode = this.themeService.isDarkMode; readonly ocrAdminApproval = signal(false); + readonly faqAdminApproval = signal(false); readonly textModelConfig = signal(DEFAULT_MODEL_CONFIG.text); readonly embeddingModelConfig = signal(DEFAULT_MODEL_CONFIG.embedding); @@ -1187,6 +1190,32 @@ export class SettingsPage implements OnInit, OnDestroy { }); } + /** + * Open the remove confirmation for a document. Deletion itself is a destructive, + * epoch-changing action the backend MVP does not expose, so it is confirmed here before the + * (still stubbed) removal runs in `confirmDeleteDocument()`. + */ + removeDocument(doc: DocumentListItem): void { + this.deletingDoc.set(doc); + } + + /** Dismiss the remove confirmation without deleting. */ + cancelDelete(): void { + this.deletingDoc.set(null); + } + + /** + * Confirmed removal. The backend MVP has no document-deletion endpoint (removing an active + * document also revokes its excerpts and can invalidate live voice sessions), so — like the + * other not-yet-implemented actions — this closes the dialog and surfaces an informative + * notice instead of calling an unsupported route. No data is deleted and no call is made. + */ + confirmDeleteDocument(): void { + const doc = this.deletingDoc(); + this.deletingDoc.set(null); + if (doc) this.toastr.info(`حذف سند «${doc.title ?? doc.filename}» در فاز MVP پشتیبانی نمی‌شود.`); + } + /** Server-provided preview URL (authenticated via the session cookie); null = no preview. */ previewImageUrl(item: ExtractionItem): string | null { const path = item.preview_path; @@ -1227,6 +1256,11 @@ export class SettingsPage implements OnInit, OnDestroy { this.toastr.info('ذخیره‌سازی سیاست بازبینی OCR در فاز MVP پشتیبانی نمی‌شود.'); } + toggleFaqApproval(): void { + this.faqAdminApproval.set(!this.faqAdminApproval()); + this.toastr.info('ذخیره‌سازی سیاست بازبینی FAQ در فاز MVP پشتیبانی نمی‌شود.'); + } + toggleDarkMode(): void { this.themeService.toggleDarkMode(); }