From 948b93db891bb38d109ea025501e9e45d9ed7891 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 20 May 2024 11:34:00 -0700 Subject: [PATCH] Adjust doc detail filtering --- .../document-detail.component.html | 8 +-- .../document-detail.component.spec.ts | 10 ++-- .../document-detail.component.ts | 51 ++++++++++--------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index b226e97a2..3f96ee811 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -105,13 +105,13 @@ - - - - + @for (fieldInstance of document?.custom_fields; track fieldInstance.field; let i = $index) {
@switch (getCustomFieldFromInstance(fieldInstance)?.data_type) { diff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts index d27c13ef1..e34dc8b2f 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts @@ -81,6 +81,7 @@ import { environment } from 'src/environments/environment' import { RotateConfirmDialogComponent } from '../common/confirm-dialog/rotate-confirm-dialog/rotate-confirm-dialog.component' import { SplitConfirmDialogComponent } from '../common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component' import { PdfViewerModule } from 'ng2-pdf-viewer' +import { DataType } from 'src/app/data/datatype' const doc: Document = { id: 3, @@ -781,10 +782,9 @@ describe('DocumentDetailComponent', () => { const object = { id: 22, name: 'Correspondent22', - last_correspondence: new Date().toISOString(), } as Correspondent const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') - component.filterDocuments([object]) + component.filterDocuments([object], DataType.Correspondent) expect(qfSpy).toHaveBeenCalledWith([ { rule_type: FILTER_CORRESPONDENT, @@ -797,7 +797,7 @@ describe('DocumentDetailComponent', () => { initNormally() const object = { id: 22, name: 'DocumentType22' } as DocumentType const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') - component.filterDocuments([object]) + component.filterDocuments([object], DataType.DocumentType) expect(qfSpy).toHaveBeenCalledWith([ { rule_type: FILTER_DOCUMENT_TYPE, @@ -814,7 +814,7 @@ describe('DocumentDetailComponent', () => { path: '/foo/bar/', } as StoragePath const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') - component.filterDocuments([object]) + component.filterDocuments([object], DataType.StoragePath) expect(qfSpy).toHaveBeenCalledWith([ { rule_type: FILTER_STORAGE_PATH, @@ -840,7 +840,7 @@ describe('DocumentDetailComponent', () => { text_color: '#000000', } as Tag const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') - component.filterDocuments([object1, object2]) + component.filterDocuments([object1, object2], DataType.Tag) expect(qfSpy).toHaveBeenCalledWith([ { rule_type: FILTER_HAS_TAGS_ALL, diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 820d7fbd5..8b03d7c1a 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -70,6 +70,7 @@ import { SplitConfirmDialogComponent } from '../common/confirm-dialog/split-conf import { RotateConfirmDialogComponent } from '../common/confirm-dialog/rotate-confirm-dialog/rotate-confirm-dialog.component' import { HotKeyService } from 'src/app/services/hot-key.service' import { PDFDocumentProxy } from 'ng2-pdf-viewer' +import { DataType } from 'src/app/data/datatype' enum DocumentDetailNavIDs { Details = 1, @@ -170,6 +171,8 @@ export class DocumentDetailComponent public readonly ContentRenderType = ContentRenderType + public readonly DataType = DataType + @ViewChild('nav') nav: NgbNav @ViewChild('pdfPreview') set pdfPreview(element) { // this gets called when component added or removed from DOM @@ -989,7 +992,7 @@ export class DocumentDetailComponent ) } - filterDocuments(items: ObjectWithId[] | NgbDateStruct[]) { + filterDocuments(items: ObjectWithId[] | NgbDateStruct[], type?: DataType) { const filterRules: FilterRule[] = items.flatMap((i) => { if (i.hasOwnProperty('year')) { const isoDateAdapter = new ISODateAdapter() @@ -1008,30 +1011,28 @@ export class DocumentDetailComponent value: dateBefore.toISOString().substring(0, 10), }, ] - } else if (i.hasOwnProperty('last_correspondence')) { - // Correspondent - return { - rule_type: FILTER_CORRESPONDENT, - value: (i as Correspondent).id.toString(), - } - } else if (i.hasOwnProperty('path')) { - // Storage Path - return { - rule_type: FILTER_STORAGE_PATH, - value: (i as StoragePath).id.toString(), - } - } else if (i.hasOwnProperty('is_inbox_tag')) { - // Tag - return { - rule_type: FILTER_HAS_TAGS_ALL, - value: (i as Tag).id.toString(), - } - } else { - // Document Type, has no specific props - return { - rule_type: FILTER_DOCUMENT_TYPE, - value: (i as DocumentType).id.toString(), - } + } + switch (type) { + case DataType.Correspondent: + return { + rule_type: FILTER_CORRESPONDENT, + value: (i as Correspondent).id.toString(), + } + case DataType.DocumentType: + return { + rule_type: FILTER_DOCUMENT_TYPE, + value: (i as DocumentType).id.toString(), + } + case DataType.StoragePath: + return { + rule_type: FILTER_STORAGE_PATH, + value: (i as StoragePath).id.toString(), + } + case DataType.Tag: + return { + rule_type: FILTER_HAS_TAGS_ALL, + value: (i as Tag).id.toString(), + } } })