A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
current view persists during session, code cleanup
Jonas Winklerd3b1a20a99cf
diff --git a/src-ui/src/app/components/dashboard/dashboard.component.html b/src-ui/src/app/components/dashboard/dashboard.component.htmlindex 694b431c4..a6d7b3d1b 100644--- a/src-ui/src/app/components/dashboard/dashboard.component.html+++ b/src-ui/src/app/components/dashboard/dashboard.component.html@@ -46,19 +46,5 @@</ngx-file-drop></form>- <h5 class="mt-3">Document conumser status</h5>- <p>This is what it might look like in the future.</p>- <div class="card bg-light mb-2">- <div class="card-body">- <p class="card-text"><strong>Filename.pdf:</strong> Running tesseract on page 4/8...</p>- <p><ngb-progressbar type="info" [value]="50"></ngb-progressbar></p>- </div>- </div>- <div class="card bg-light mb-2">- <div class="card-body">- <p class="card-text"><strong>Filename2.pdf:</strong> Completed.</p>- <p><ngb-progressbar type="success" [value]="100"></ngb-progressbar></p>- </div>- </div></div></div>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.tsindex ad9a3ac07..802a3b212 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@@ -134,8 +134,8 @@ export class DocumentDetailComponent implements OnInit {close() {this.openDocumentService.closeDocument(this.document)- if (this.documentListViewService.viewConfig) {- this.router.navigate(['view', this.documentListViewService.viewConfig.id])+ if (this.documentListViewService.viewId) {+ this.router.navigate(['view', this.documentListViewService.viewId])} else {this.router.navigate(['documents'])}diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.htmlindex 9d275854e..6eafb7b80 100644--- a/src-ui/src/app/components/document-list/document-list.component.html+++ b/src-ui/src/app/components/document-list/document-list.component.html@@ -1,4 +1,4 @@-<app-page-header [title]="docs.viewConfig ? docs.viewConfig.title : 'Documents'">+<app-page-header [title]="getTitle()"><div class="btn-group btn-group-toggle mr-2" ngbRadioGroup [(ngModel)]="displayMode"(ngModelChange)="saveDisplayMode()">@@ -21,14 +21,13 @@</svg></label></div>- <div class="btn-group btn-group-toggle mr-2" ngbRadioGroup [(ngModel)]="docs.currentSortDirection"- (ngModelChange)="reload()"- *ngIf="!docs.viewConfig">+ <div class="btn-group btn-group-toggle mr-2" ngbRadioGroup [(ngModel)]="docs.sortDirection"+ *ngIf="!docs.viewId"><div ngbDropdown class="btn-group"><button class="btn btn-outline-secondary btn-sm" id="dropdownBasic1" ngbDropdownToggle>Sort by</button><div ngbDropdownMenu aria-labelledby="dropdownBasic1"><button *ngFor="let f of getSortFields()" ngbDropdownItem (click)="setSort(f.field)"- [class.active]="docs.currentSortField == f.field">{{f.name}}</button>+ [class.active]="docs.sortField == f.field">{{f.name}}</button></div></div><label ngbButtonLabel class="btn-outline-secondary btn-sm">@@ -44,7 +43,7 @@</svg></label></div>- <div class="btn-group" *ngIf="!docs.viewConfig">+ <div class="btn-group" *ngIf="!docs.viewId"><button type="button" class="btn btn-sm btn-outline-secondary" (click)="showFilter=!showFilter"><svg class="toolbaricon" fill="currentColor">@@ -62,7 +61,6 @@</div></div>-</div></app-page-header>diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.tsindex be83bf0bf..2ea2c9e3e 100644--- a/src-ui/src/app/components/document-list/document-list.component.ts+++ b/src-ui/src/app/components/document-list/document-list.component.ts@@ -26,13 +26,16 @@ export class DocumentListComponent implements OnInit {filterRules: FilterRule[] = []showFilter = false+ getTitle() {+ return this.docs.viewConfigOverride ? this.docs.viewConfigOverride.title : "Documents"+ }+getSortFields() {return DOCUMENT_SORT_FIELDS}setSort(field: string) {- this.docs.currentSortField = field- this.reload()+ this.docs.sortField = field}saveDisplayMode() {@@ -45,11 +48,11 @@ export class DocumentListComponent implements OnInit {}this.route.paramMap.subscribe(params => {if (params.has('id')) {- this.docs.viewConfig = this.savedViewConfigService.getConfig(params.get('id'))+ this.docs.viewConfigOverride = this.savedViewConfigService.getConfig(params.get('id'))} else {- this.filterRules = cloneFilterRules(this.docs.currentFilterRules)+ this.filterRules = this.docs.filterRulesthis.showFilter = this.filterRules.length > 0- this.docs.viewConfig = null+ this.docs.viewConfigOverride = null}this.reload()})@@ -60,28 +63,24 @@ export class DocumentListComponent implements OnInit {}applyFilterRules() {- this.docs.setFilterRules(this.filterRules)- this.reload()+ this.docs.filterRules = this.filterRules}loadViewConfig(config: SavedViewConfig) {this.filterRules = cloneFilterRules(config.filterRules)- this.docs.setFilterRules(config.filterRules)- this.docs.currentSortField = config.sortField- this.docs.currentSortDirection = config.sortDirection- this.reload()+ this.docs.loadViewConfig(config)}saveViewConfig() {let modal = this.modalService.open(SaveViewConfigDialogComponent, {backdrop: 'static'})modal.componentInstance.saveClicked.subscribe(formValue => {this.savedViewConfigService.saveConfig({- filterRules: cloneFilterRules(this.filterRules),title: formValue.title,showInDashboard: formValue.showInDashboard,showInSideBar: formValue.showInSideBar,- sortDirection: this.docs.currentSortDirection,- sortField: this.docs.currentSortField+ filterRules: this.docs.filterRules,+ sortDirection: this.docs.sortDirection,+ sortField: this.docs.sortField})modal.close()})diff --git a/src-ui/src/app/data/saved-view-config.ts b/src-ui/src/app/data/saved-view-config.tsindex 29d881510..9d7076215 100644--- a/src-ui/src/app/data/saved-view-config.ts+++ b/src-ui/src/app/data/saved-view-config.ts@@ -10,10 +10,10 @@ export interface SavedViewConfig {sortDirection: string- title: string+ title?: string- showInSideBar: boolean+ showInSideBar?: boolean- showInDashboard: boolean+ showInDashboard?: boolean}\ No newline at end of filediff --git a/src-ui/src/app/data/storage-keys.ts b/src-ui/src/app/data/storage-keys.tsindex cc4a05ec2..13b41d4a7 100644--- a/src-ui/src/app/data/storage-keys.ts+++ b/src-ui/src/app/data/storage-keys.ts@@ -2,6 +2,10 @@ export const OPEN_DOCUMENT_SERVICE = {DOCUMENTS: 'open-documents-service:openDocuments'}+export const DOCUMENT_LIST_SERVICE = {+ CURRENT_VIEW_CONFIG: 'document-list-service:currentViewConfig'+}+export const GENERAL_SETTINGS = {DOCUMENT_LIST_SIZE: 'general-settings:documentListSize',DOCUMENT_LIST_SIZE_DEFAULT: 50diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.tsindex e554f2c8f..39a8661b9 100644--- a/src-ui/src/app/services/document-list-view.service.ts+++ b/src-ui/src/app/services/document-list-view.service.ts@@ -3,8 +3,8 @@ import { Observable } from 'rxjs';import { cloneFilterRules, FilterRule } from '../data/filter-rule';import { PaperlessDocument } from '../data/paperless-document';import { SavedViewConfig } from '../data/saved-view-config';-import { GENERAL_SETTINGS } from '../data/storage-keys';-import { DocumentService, SORT_DIRECTION_DESCENDING } from './rest/document.service';+import { DOCUMENT_LIST_SERVICE, GENERAL_SETTINGS } from '../data/storage-keys';+import { DocumentService } from './rest/document.service';@Injectable({@@ -18,33 +18,24 @@ export class DocumentListViewService {currentPage = 1currentPageSize: number = +localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULTcollectionSize: number-- currentFilterRules: FilterRule[] = []- currentSortDirection = SORT_DIRECTION_DESCENDING- currentSortField = DocumentListViewService.DEFAULT_SORT_FIELD- viewConfig: SavedViewConfig+ private currentViewConfig: SavedViewConfig+ //TODO: make private+ viewConfigOverride: SavedViewConfig++ get viewId() {+ return this.viewConfigOverride?.id+ }reload(onFinish?) {- let sortField: string- let sortDirection: string- let filterRules: FilterRule[]- if (this.viewConfig) {- sortField = this.viewConfig.sortField- sortDirection = this.viewConfig.sortDirection- filterRules = this.viewConfig.filterRules- } else {- sortField = this.currentSortField- sortDirection = this.currentSortDirection- filterRules = this.currentFilterRules- }+ let viewConfig = this.viewConfigOverride || this.currentViewConfigthis.documentService.list(this.currentPage,this.currentPageSize,- sortField,- sortDirection,- filterRules).subscribe(+ viewConfig.sortField,+ viewConfig.sortDirection,+ viewConfig.filterRules).subscribe(result => {this.collectionSize = result.countthis.documents = result.results@@ -60,9 +51,43 @@ export class DocumentListViewService {})}+ set filterRules(filterRules: FilterRule[]) {+ this.currentViewConfig.filterRules = cloneFilterRules(filterRules)+ this.saveCurrentViewConfig()+ this.reload()+ }++ get filterRules(): FilterRule[] {+ return cloneFilterRules(this.currentViewConfig.filterRules)+ }++ set sortField(field: string) {+ this.currentViewConfig.sortField = field+ this.saveCurrentViewConfig()+ this.reload()+ }++ get sortField(): string {+ return this.currentViewConfig.sortField+ }++ set sortDirection(direction: string) {+ this.currentViewConfig.sortDirection = direction+ this.saveCurrentViewConfig()+ this.reload()+ }++ get sortDirection(): string {+ return this.currentViewConfig.sortDirection+ }++ loadViewConfig(config: SavedViewConfig) {+ Object.assign(this.currentViewConfig, config)+ this.reload()+ }- setFilterRules(filterRules: FilterRule[]) {- this.currentFilterRules = cloneFilterRules(filterRules)+ private saveCurrentViewConfig() {+ sessionStorage.setItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG, JSON.stringify(this.currentViewConfig))}getLastPage(): number {@@ -108,5 +133,22 @@ export class DocumentListViewService {}}- constructor(private documentService: DocumentService) { }+ constructor(private documentService: DocumentService) {+ let currentViewConfigJson = sessionStorage.getItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG)+ if (currentViewConfigJson) {+ try {+ this.currentViewConfig = JSON.parse(currentViewConfigJson)+ } catch (e) {+ sessionStorage.removeItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG)+ this.currentViewConfig = null+ }+ }+ if (!this.currentViewConfig) {+ this.currentViewConfig = {+ filterRules: [],+ sortDirection: 'des',+ sortField: 'created'+ }+ }+ }}diff --git a/src-ui/src/app/services/saved-view-config.service.ts b/src-ui/src/app/services/saved-view-config.service.tsindex a6b538b0d..d69791209 100644--- a/src-ui/src/app/services/saved-view-config.service.ts+++ b/src-ui/src/app/services/saved-view-config.service.ts@@ -10,7 +10,11 @@ export class SavedViewConfigService {constructor() {let savedConfigs = localStorage.getItem('saved-view-config-service:savedConfigs')if (savedConfigs) {- this.configs = JSON.parse(savedConfigs)+ try {+ this.configs = JSON.parse(savedConfigs)+ } catch (e) {+ this.configs = []+ }}}