mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Adds quick filters from document detail
This commit is contained in:
@@ -74,15 +74,15 @@
|
||||
|
||||
<app-input-text #inputTitle i18n-title title="Title" formControlName="title" (keyup)="titleKeyUp($event)" [error]="error?.title"></app-input-text>
|
||||
<app-input-number i18n-title title="Archive serial number" [error]="error?.archive_serial_number" formControlName='archive_serial_number'></app-input-number>
|
||||
<app-input-date i18n-title title="Date created" formControlName="created_date" [suggestions]="suggestions?.dates"
|
||||
<app-input-date i18n-title title="Date created" formControlName="created_date" [suggestions]="suggestions?.dates" [showFilter]="true" (filterDocuments)="filterDocuments($event)"
|
||||
[error]="error?.created_date"></app-input-date>
|
||||
<app-input-select [items]="correspondents" i18n-title title="Correspondent" formControlName="correspondent" [allowNull]="true"
|
||||
<app-input-select [items]="correspondents" i18n-title title="Correspondent" formControlName="correspondent" [allowNull]="true" [showFilter]="true" (filterDocuments)="filterDocuments($event)"
|
||||
(createNew)="createCorrespondent($event)" [suggestions]="suggestions?.correspondents" *appIfPermissions="{ action: PermissionAction.View, type: PermissionType.Correspondent }"></app-input-select>
|
||||
<app-input-select [items]="documentTypes" i18n-title title="Document type" formControlName="document_type" [allowNull]="true"
|
||||
<app-input-select [items]="documentTypes" i18n-title title="Document type" formControlName="document_type" [allowNull]="true" [showFilter]="true" (filterDocuments)="filterDocuments($event)"
|
||||
(createNew)="createDocumentType($event)" [suggestions]="suggestions?.document_types" *appIfPermissions="{ action: PermissionAction.View, type: PermissionType.DocumentType }"></app-input-select>
|
||||
<app-input-select [items]="storagePaths" i18n-title title="Storage path" formControlName="storage_path" [allowNull]="true"
|
||||
<app-input-select [items]="storagePaths" i18n-title title="Storage path" formControlName="storage_path" [allowNull]="true" [showFilter]="true" (filterDocuments)="filterDocuments($event)"
|
||||
(createNew)="createStoragePath($event)" [suggestions]="suggestions?.storage_paths" i18n-placeholder placeholder="Default" *appIfPermissions="{ action: PermissionAction.View, type: PermissionType.StoragePath }"></app-input-select>
|
||||
<app-input-tags formControlName="tags" [suggestions]="suggestions?.tags" *appIfPermissions="{ action: PermissionAction.View, type: PermissionType.Tag }"></app-input-tags>
|
||||
<app-input-tags formControlName="tags" [suggestions]="suggestions?.tags" [showFilter]="true" (filterDocuments)="filterDocuments($event)" *appIfPermissions="{ action: PermissionAction.View, type: PermissionType.Tag }"></app-input-tags>
|
||||
|
||||
</ng-template>
|
||||
</li>
|
||||
|
@@ -1,11 +1,17 @@
|
||||
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'
|
||||
import { FormControl, FormGroup } from '@angular/forms'
|
||||
import { ActivatedRoute, Router } from '@angular/router'
|
||||
import { NgbModal, NgbNav, NgbNavChangeEvent } from '@ng-bootstrap/ng-bootstrap'
|
||||
import {
|
||||
NgbDateStruct,
|
||||
NgbModal,
|
||||
NgbNav,
|
||||
NgbNavChangeEvent,
|
||||
} from '@ng-bootstrap/ng-bootstrap'
|
||||
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
|
||||
import { PaperlessDocument } from 'src/app/data/paperless-document'
|
||||
import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata'
|
||||
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
|
||||
import { PaperlessTag } from 'src/app/data/paperless-tag'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
|
||||
import { OpenDocumentsService } from 'src/app/services/open-documents.service'
|
||||
@@ -30,7 +36,18 @@ import {
|
||||
distinctUntilChanged,
|
||||
} from 'rxjs/operators'
|
||||
import { PaperlessDocumentSuggestions } from 'src/app/data/paperless-document-suggestions'
|
||||
import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type'
|
||||
import {
|
||||
FILTER_CORRESPONDENT,
|
||||
FILTER_CREATED_AFTER,
|
||||
FILTER_CREATED_BEFORE,
|
||||
FILTER_CREATED_DAY,
|
||||
FILTER_CREATED_MONTH,
|
||||
FILTER_CREATED_YEAR,
|
||||
FILTER_DOCUMENT_TYPE,
|
||||
FILTER_FULLTEXT_MORELIKE,
|
||||
FILTER_HAS_TAGS_ALL,
|
||||
FILTER_STORAGE_PATH,
|
||||
} from 'src/app/data/filter-rule-type'
|
||||
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
|
||||
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
|
||||
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
|
||||
@@ -45,6 +62,9 @@ import { UserService } from 'src/app/services/rest/user.service'
|
||||
import { PaperlessDocumentNote } from 'src/app/data/paperless-document-note'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { ComponentWithPermissions } from '../with-permissions/with-permissions.component'
|
||||
import { FilterRule } from 'src/app/data/filter-rule'
|
||||
import { ObjectWithId } from 'src/app/data/object-with-id'
|
||||
import { ISODateAdapter } from 'src/app/utils/ngb-iso-date-adapter'
|
||||
|
||||
enum DocumentDetailNavIDs {
|
||||
Details = 1,
|
||||
@@ -762,4 +782,53 @@ export class DocumentDetailComponent
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
filterDocuments(items: ObjectWithId[] | NgbDateStruct[]) {
|
||||
const filterRules: FilterRule[] = items.flatMap((i) => {
|
||||
if (i.hasOwnProperty('year')) {
|
||||
const isoDateAdapter = new ISODateAdapter()
|
||||
const dateAfter: Date = new Date(isoDateAdapter.toModel(i))
|
||||
dateAfter.setDate(dateAfter.getDate() - 1)
|
||||
const dateBefore: Date = new Date(isoDateAdapter.toModel(i))
|
||||
dateBefore.setDate(dateBefore.getDate() + 1)
|
||||
// Created Date
|
||||
return [
|
||||
{
|
||||
rule_type: FILTER_CREATED_AFTER,
|
||||
value: dateAfter.toISOString().substring(0, 10),
|
||||
},
|
||||
{
|
||||
rule_type: FILTER_CREATED_BEFORE,
|
||||
value: dateBefore.toISOString().substring(0, 10),
|
||||
},
|
||||
]
|
||||
} else if (i.hasOwnProperty('last_correspondence')) {
|
||||
// Correspondent
|
||||
return {
|
||||
rule_type: FILTER_CORRESPONDENT,
|
||||
value: (i as PaperlessCorrespondent).id.toString(),
|
||||
}
|
||||
} else if (i.hasOwnProperty('path')) {
|
||||
// Storage Path
|
||||
return {
|
||||
rule_type: FILTER_STORAGE_PATH,
|
||||
value: (i as PaperlessStoragePath).id.toString(),
|
||||
}
|
||||
} else if (i.hasOwnProperty('is_inbox_tag')) {
|
||||
// Tag
|
||||
return {
|
||||
rule_type: FILTER_HAS_TAGS_ALL,
|
||||
value: (i as PaperlessTag).id.toString(),
|
||||
}
|
||||
} else {
|
||||
// Document Type, has no specific props
|
||||
return {
|
||||
rule_type: FILTER_DOCUMENT_TYPE,
|
||||
value: (i as PaperlessDocumentType).id.toString(),
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.documentListViewService.quickFilter(filterRules)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user