mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	current view persists during session, code cleanup
This commit is contained in:
		@@ -46,19 +46,5 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      </ngx-file-drop>
 | 
					      </ngx-file-drop>
 | 
				
			||||||
    </form>
 | 
					    </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>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -134,8 +134,8 @@ export class DocumentDetailComponent implements OnInit {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  close() {
 | 
					  close() {
 | 
				
			||||||
    this.openDocumentService.closeDocument(this.document)
 | 
					    this.openDocumentService.closeDocument(this.document)
 | 
				
			||||||
    if (this.documentListViewService.viewConfig) {
 | 
					    if (this.documentListViewService.viewId) {
 | 
				
			||||||
      this.router.navigate(['view', this.documentListViewService.viewConfig.id])
 | 
					      this.router.navigate(['view', this.documentListViewService.viewId])
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      this.router.navigate(['documents'])
 | 
					      this.router.navigate(['documents'])
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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"
 | 
					  <div class="btn-group btn-group-toggle mr-2" ngbRadioGroup [(ngModel)]="displayMode"
 | 
				
			||||||
    (ngModelChange)="saveDisplayMode()">
 | 
					    (ngModelChange)="saveDisplayMode()">
 | 
				
			||||||
@@ -21,14 +21,13 @@
 | 
				
			|||||||
      </svg>
 | 
					      </svg>
 | 
				
			||||||
    </label>
 | 
					    </label>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <div class="btn-group btn-group-toggle mr-2" ngbRadioGroup [(ngModel)]="docs.currentSortDirection"
 | 
					  <div class="btn-group btn-group-toggle mr-2" ngbRadioGroup [(ngModel)]="docs.sortDirection"
 | 
				
			||||||
    (ngModelChange)="reload()"
 | 
					    *ngIf="!docs.viewId">
 | 
				
			||||||
    *ngIf="!docs.viewConfig">
 | 
					 | 
				
			||||||
    <div ngbDropdown class="btn-group">
 | 
					    <div ngbDropdown class="btn-group">
 | 
				
			||||||
      <button class="btn btn-outline-secondary btn-sm" id="dropdownBasic1" ngbDropdownToggle>Sort by</button>
 | 
					      <button class="btn btn-outline-secondary btn-sm" id="dropdownBasic1" ngbDropdownToggle>Sort by</button>
 | 
				
			||||||
      <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
 | 
					      <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
 | 
				
			||||||
        <button *ngFor="let f of getSortFields()" ngbDropdownItem (click)="setSort(f.field)"
 | 
					        <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>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
    <label ngbButtonLabel class="btn-outline-secondary btn-sm">
 | 
					    <label ngbButtonLabel class="btn-outline-secondary btn-sm">
 | 
				
			||||||
@@ -44,7 +43,7 @@
 | 
				
			|||||||
      </svg>
 | 
					      </svg>
 | 
				
			||||||
    </label>
 | 
					    </label>
 | 
				
			||||||
  </div>
 | 
					  </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">
 | 
					    <button type="button" class="btn btn-sm btn-outline-secondary" (click)="showFilter=!showFilter">
 | 
				
			||||||
      <svg class="toolbaricon" fill="currentColor">
 | 
					      <svg class="toolbaricon" fill="currentColor">
 | 
				
			||||||
@@ -62,7 +61,6 @@
 | 
				
			|||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</app-page-header>
 | 
					</app-page-header>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,13 +26,16 @@ export class DocumentListComponent implements OnInit {
 | 
				
			|||||||
  filterRules: FilterRule[] = []
 | 
					  filterRules: FilterRule[] = []
 | 
				
			||||||
  showFilter = false
 | 
					  showFilter = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  getTitle() {
 | 
				
			||||||
 | 
					    return this.docs.viewConfigOverride ? this.docs.viewConfigOverride.title : "Documents"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getSortFields() {
 | 
					  getSortFields() {
 | 
				
			||||||
    return DOCUMENT_SORT_FIELDS
 | 
					    return DOCUMENT_SORT_FIELDS
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setSort(field: string) {
 | 
					  setSort(field: string) {
 | 
				
			||||||
    this.docs.currentSortField = field
 | 
					    this.docs.sortField = field
 | 
				
			||||||
    this.reload()
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  saveDisplayMode() {
 | 
					  saveDisplayMode() {
 | 
				
			||||||
@@ -45,11 +48,11 @@ export class DocumentListComponent implements OnInit {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    this.route.paramMap.subscribe(params => {
 | 
					    this.route.paramMap.subscribe(params => {
 | 
				
			||||||
      if (params.has('id')) {
 | 
					      if (params.has('id')) {
 | 
				
			||||||
        this.docs.viewConfig = this.savedViewConfigService.getConfig(params.get('id'))
 | 
					        this.docs.viewConfigOverride = this.savedViewConfigService.getConfig(params.get('id'))
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        this.filterRules = cloneFilterRules(this.docs.currentFilterRules)
 | 
					        this.filterRules = this.docs.filterRules
 | 
				
			||||||
        this.showFilter = this.filterRules.length > 0
 | 
					        this.showFilter = this.filterRules.length > 0
 | 
				
			||||||
        this.docs.viewConfig = null
 | 
					        this.docs.viewConfigOverride = null
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      this.reload()
 | 
					      this.reload()
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
@@ -60,28 +63,24 @@ export class DocumentListComponent implements OnInit {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  applyFilterRules() {
 | 
					  applyFilterRules() {
 | 
				
			||||||
    this.docs.setFilterRules(this.filterRules)
 | 
					    this.docs.filterRules = this.filterRules
 | 
				
			||||||
    this.reload()
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  loadViewConfig(config: SavedViewConfig) {
 | 
					  loadViewConfig(config: SavedViewConfig) {
 | 
				
			||||||
    this.filterRules = cloneFilterRules(config.filterRules)
 | 
					    this.filterRules = cloneFilterRules(config.filterRules)
 | 
				
			||||||
    this.docs.setFilterRules(config.filterRules)
 | 
					    this.docs.loadViewConfig(config)
 | 
				
			||||||
    this.docs.currentSortField = config.sortField
 | 
					 | 
				
			||||||
    this.docs.currentSortDirection = config.sortDirection
 | 
					 | 
				
			||||||
    this.reload()
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  saveViewConfig() {
 | 
					  saveViewConfig() {
 | 
				
			||||||
    let modal = this.modalService.open(SaveViewConfigDialogComponent, {backdrop: 'static'})
 | 
					    let modal = this.modalService.open(SaveViewConfigDialogComponent, {backdrop: 'static'})
 | 
				
			||||||
    modal.componentInstance.saveClicked.subscribe(formValue => {
 | 
					    modal.componentInstance.saveClicked.subscribe(formValue => {
 | 
				
			||||||
      this.savedViewConfigService.saveConfig({
 | 
					      this.savedViewConfigService.saveConfig({
 | 
				
			||||||
        filterRules: cloneFilterRules(this.filterRules),
 | 
					 | 
				
			||||||
        title: formValue.title,
 | 
					        title: formValue.title,
 | 
				
			||||||
        showInDashboard: formValue.showInDashboard,
 | 
					        showInDashboard: formValue.showInDashboard,
 | 
				
			||||||
        showInSideBar: formValue.showInSideBar,
 | 
					        showInSideBar: formValue.showInSideBar,
 | 
				
			||||||
        sortDirection: this.docs.currentSortDirection,
 | 
					        filterRules: this.docs.filterRules,
 | 
				
			||||||
        sortField: this.docs.currentSortField
 | 
					        sortDirection: this.docs.sortDirection,
 | 
				
			||||||
 | 
					        sortField: this.docs.sortField
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      modal.close()
 | 
					      modal.close()
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,10 +10,10 @@ export interface SavedViewConfig {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  sortDirection: string
 | 
					  sortDirection: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  title: string
 | 
					  title?: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  showInSideBar: boolean
 | 
					  showInSideBar?: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  showInDashboard: boolean
 | 
					  showInDashboard?: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -2,6 +2,10 @@ export const OPEN_DOCUMENT_SERVICE = {
 | 
				
			|||||||
  DOCUMENTS: 'open-documents-service:openDocuments'
 | 
					  DOCUMENTS: 'open-documents-service:openDocuments'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const DOCUMENT_LIST_SERVICE = {
 | 
				
			||||||
 | 
					  CURRENT_VIEW_CONFIG: 'document-list-service:currentViewConfig'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const GENERAL_SETTINGS = {
 | 
					export const GENERAL_SETTINGS = {
 | 
				
			||||||
  DOCUMENT_LIST_SIZE: 'general-settings:documentListSize',
 | 
					  DOCUMENT_LIST_SIZE: 'general-settings:documentListSize',
 | 
				
			||||||
  DOCUMENT_LIST_SIZE_DEFAULT: 50
 | 
					  DOCUMENT_LIST_SIZE_DEFAULT: 50
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,8 @@ import { Observable } from 'rxjs';
 | 
				
			|||||||
import { cloneFilterRules, FilterRule } from '../data/filter-rule';
 | 
					import { cloneFilterRules, FilterRule } from '../data/filter-rule';
 | 
				
			||||||
import { PaperlessDocument } from '../data/paperless-document';
 | 
					import { PaperlessDocument } from '../data/paperless-document';
 | 
				
			||||||
import { SavedViewConfig } from '../data/saved-view-config';
 | 
					import { SavedViewConfig } from '../data/saved-view-config';
 | 
				
			||||||
import { GENERAL_SETTINGS } from '../data/storage-keys';
 | 
					import { DOCUMENT_LIST_SERVICE, GENERAL_SETTINGS } from '../data/storage-keys';
 | 
				
			||||||
import { DocumentService, SORT_DIRECTION_DESCENDING } from './rest/document.service';
 | 
					import { DocumentService } from './rest/document.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Injectable({
 | 
					@Injectable({
 | 
				
			||||||
@@ -19,32 +19,23 @@ export class DocumentListViewService {
 | 
				
			|||||||
  currentPageSize: number = +localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT
 | 
					  currentPageSize: number = +localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT
 | 
				
			||||||
  collectionSize: number
 | 
					  collectionSize: number
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  currentFilterRules: FilterRule[] = []
 | 
					  private currentViewConfig: SavedViewConfig
 | 
				
			||||||
  currentSortDirection = SORT_DIRECTION_DESCENDING
 | 
					  //TODO: make private
 | 
				
			||||||
  currentSortField = DocumentListViewService.DEFAULT_SORT_FIELD
 | 
					  viewConfigOverride: SavedViewConfig
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  viewConfig: SavedViewConfig
 | 
					  get viewId() {
 | 
				
			||||||
 | 
					    return this.viewConfigOverride?.id
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  reload(onFinish?) {
 | 
					  reload(onFinish?) {
 | 
				
			||||||
    let sortField: string
 | 
					    let viewConfig = this.viewConfigOverride || this.currentViewConfig
 | 
				
			||||||
    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
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.documentService.list(
 | 
					    this.documentService.list(
 | 
				
			||||||
      this.currentPage,
 | 
					      this.currentPage,
 | 
				
			||||||
      this.currentPageSize,
 | 
					      this.currentPageSize,
 | 
				
			||||||
      sortField,
 | 
					      viewConfig.sortField,
 | 
				
			||||||
      sortDirection,
 | 
					      viewConfig.sortDirection,
 | 
				
			||||||
      filterRules).subscribe(
 | 
					      viewConfig.filterRules).subscribe(
 | 
				
			||||||
        result => {
 | 
					        result => {
 | 
				
			||||||
          this.collectionSize = result.count
 | 
					          this.collectionSize = result.count
 | 
				
			||||||
          this.documents = result.results
 | 
					          this.documents = result.results
 | 
				
			||||||
@@ -60,9 +51,43 @@ export class DocumentListViewService {
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  set filterRules(filterRules: FilterRule[]) {
 | 
				
			||||||
 | 
					    this.currentViewConfig.filterRules = cloneFilterRules(filterRules)
 | 
				
			||||||
 | 
					    this.saveCurrentViewConfig()
 | 
				
			||||||
 | 
					    this.reload()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setFilterRules(filterRules: FilterRule[]) {
 | 
					  get filterRules(): FilterRule[] {
 | 
				
			||||||
    this.currentFilterRules = cloneFilterRules(filterRules)
 | 
					    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()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private saveCurrentViewConfig() {
 | 
				
			||||||
 | 
					    sessionStorage.setItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG, JSON.stringify(this.currentViewConfig))
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getLastPage(): number {
 | 
					  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'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,11 @@ export class SavedViewConfigService {
 | 
				
			|||||||
  constructor() { 
 | 
					  constructor() { 
 | 
				
			||||||
    let savedConfigs = localStorage.getItem('saved-view-config-service:savedConfigs')
 | 
					    let savedConfigs = localStorage.getItem('saved-view-config-service:savedConfigs')
 | 
				
			||||||
    if (savedConfigs) {
 | 
					    if (savedConfigs) {
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
        this.configs = JSON.parse(savedConfigs)
 | 
					        this.configs = JSON.parse(savedConfigs)
 | 
				
			||||||
 | 
					      } catch (e) {
 | 
				
			||||||
 | 
					        this.configs = []
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user