mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	more settings
This commit is contained in:
		@@ -195,6 +195,9 @@ export class FilterableDropdownComponent {
 | 
				
			|||||||
  @Input()
 | 
					  @Input()
 | 
				
			||||||
  editing = false
 | 
					  editing = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Input()
 | 
				
			||||||
 | 
					  applyOnClose = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Output()
 | 
					  @Output()
 | 
				
			||||||
  apply = new EventEmitter<ChangedItems>()
 | 
					  apply = new EventEmitter<ChangedItems>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -208,9 +211,11 @@ export class FilterableDropdownComponent {
 | 
				
			|||||||
  applyClicked() {
 | 
					  applyClicked() {
 | 
				
			||||||
    if (this.selectionModel.isDirty()) {
 | 
					    if (this.selectionModel.isDirty()) {
 | 
				
			||||||
      this.dropdown.close()
 | 
					      this.dropdown.close()
 | 
				
			||||||
 | 
					      if (!this.applyOnClose) {
 | 
				
			||||||
        this.apply.emit(this.selectionModel.diff())
 | 
					        this.apply.emit(this.selectionModel.diff())
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  dropdownOpenChange(open: boolean): void {
 | 
					  dropdownOpenChange(open: boolean): void {
 | 
				
			||||||
    if (open) {
 | 
					    if (open) {
 | 
				
			||||||
@@ -223,6 +228,9 @@ export class FilterableDropdownComponent {
 | 
				
			|||||||
      this.open.next()
 | 
					      this.open.next()
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      this.filterText = ''
 | 
					      this.filterText = ''
 | 
				
			||||||
 | 
					      if (this.applyOnClose && this.selectionModel.isDirty()) {
 | 
				
			||||||
 | 
					        this.apply.emit(this.selectionModel.diff())
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,6 +30,7 @@
 | 
				
			|||||||
        [items]="tags"
 | 
					        [items]="tags"
 | 
				
			||||||
        [editing]="true"
 | 
					        [editing]="true"
 | 
				
			||||||
        [multiple]="true"
 | 
					        [multiple]="true"
 | 
				
			||||||
 | 
					        [applyOnClose]="applyOnClose"
 | 
				
			||||||
        (open)="openTagsDropdown()"
 | 
					        (open)="openTagsDropdown()"
 | 
				
			||||||
        [(selectionModel)]="tagSelectionModel"
 | 
					        [(selectionModel)]="tagSelectionModel"
 | 
				
			||||||
        (apply)="setTags($event)">
 | 
					        (apply)="setTags($event)">
 | 
				
			||||||
@@ -37,6 +38,7 @@
 | 
				
			|||||||
      <app-filterable-dropdown class="mr-2 mr-md-3" title="Correspondent" icon="person-fill"
 | 
					      <app-filterable-dropdown class="mr-2 mr-md-3" title="Correspondent" icon="person-fill"
 | 
				
			||||||
        [items]="correspondents"
 | 
					        [items]="correspondents"
 | 
				
			||||||
        [editing]="true"
 | 
					        [editing]="true"
 | 
				
			||||||
 | 
					        [applyOnClose]="applyOnClose"
 | 
				
			||||||
        (open)="openCorrespondentDropdown()"
 | 
					        (open)="openCorrespondentDropdown()"
 | 
				
			||||||
        [(selectionModel)]="correspondentSelectionModel"
 | 
					        [(selectionModel)]="correspondentSelectionModel"
 | 
				
			||||||
        (apply)="setCorrespondents($event)">
 | 
					        (apply)="setCorrespondents($event)">
 | 
				
			||||||
@@ -44,6 +46,7 @@
 | 
				
			|||||||
      <app-filterable-dropdown class="mr-2 mr-md-3" title="Document Type" icon="file-earmark-fill"
 | 
					      <app-filterable-dropdown class="mr-2 mr-md-3" title="Document Type" icon="file-earmark-fill"
 | 
				
			||||||
        [items]="documentTypes"
 | 
					        [items]="documentTypes"
 | 
				
			||||||
        [editing]="true"
 | 
					        [editing]="true"
 | 
				
			||||||
 | 
					        [applyOnClose]="applyOnClose"
 | 
				
			||||||
        (open)="openDocumentTypeDropdown()"
 | 
					        (open)="openDocumentTypeDropdown()"
 | 
				
			||||||
        [(selectionModel)]="documentTypeSelectionModel"
 | 
					        [(selectionModel)]="documentTypeSelectionModel"
 | 
				
			||||||
        (apply)="setDocumentTypes($event)">
 | 
					        (apply)="setDocumentTypes($event)">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ import { ConfirmDialogComponent } from 'src/app/components/common/confirm-dialog
 | 
				
			|||||||
import { ChangedItems, FilterableDropdownSelectionModel } from '../../common/filterable-dropdown/filterable-dropdown.component';
 | 
					import { ChangedItems, FilterableDropdownSelectionModel } from '../../common/filterable-dropdown/filterable-dropdown.component';
 | 
				
			||||||
import { ToggleableItemState } from '../../common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component';
 | 
					import { ToggleableItemState } from '../../common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component';
 | 
				
			||||||
import { MatchingModel } from 'src/app/data/matching-model';
 | 
					import { MatchingModel } from 'src/app/data/matching-model';
 | 
				
			||||||
 | 
					import { SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'app-bulk-editor',
 | 
					  selector: 'app-bulk-editor',
 | 
				
			||||||
@@ -38,9 +39,13 @@ export class BulkEditorComponent {
 | 
				
			|||||||
    public list: DocumentListViewService,
 | 
					    public list: DocumentListViewService,
 | 
				
			||||||
    private documentService: DocumentService,
 | 
					    private documentService: DocumentService,
 | 
				
			||||||
    private modalService: NgbModal,
 | 
					    private modalService: NgbModal,
 | 
				
			||||||
    private openDocumentService: OpenDocumentsService
 | 
					    private openDocumentService: OpenDocumentsService,
 | 
				
			||||||
 | 
					    private settings: SettingsService
 | 
				
			||||||
  ) { }
 | 
					  ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  applyOnClose: boolean = this.settings.get(SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE)
 | 
				
			||||||
 | 
					  showConfirmationDialogs: boolean = this.settings.get(SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    this.tagService.listAll().subscribe(result => this.tags = result.results)
 | 
					    this.tagService.listAll().subscribe(result => this.tags = result.results)
 | 
				
			||||||
    this.correspondentService.listAll().subscribe(result => this.correspondents = result.results)
 | 
					    this.correspondentService.listAll().subscribe(result => this.correspondents = result.results)
 | 
				
			||||||
@@ -54,7 +59,6 @@ export class BulkEditorComponent {
 | 
				
			|||||||
        this.list.selected.forEach(id => {
 | 
					        this.list.selected.forEach(id => {
 | 
				
			||||||
          this.openDocumentService.refreshDocument(id)
 | 
					          this.openDocumentService.refreshDocument(id)
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        this.list.selectNone()
 | 
					 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -105,6 +109,7 @@ export class BulkEditorComponent {
 | 
				
			|||||||
  setTags(changedTags: ChangedItems) {
 | 
					  setTags(changedTags: ChangedItems) {
 | 
				
			||||||
    if (changedTags.itemsToAdd.length == 0 && changedTags.itemsToRemove.length == 0) return
 | 
					    if (changedTags.itemsToAdd.length == 0 && changedTags.itemsToRemove.length == 0) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (this.showConfirmationDialogs) {
 | 
				
			||||||
      let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
 | 
					      let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
 | 
				
			||||||
      modal.componentInstance.title = $localize`Confirm tags assignment`
 | 
					      modal.componentInstance.title = $localize`Confirm tags assignment`
 | 
				
			||||||
      if (changedTags.itemsToAdd.length == 1 && changedTags.itemsToRemove.length == 0) {
 | 
					      if (changedTags.itemsToAdd.length == 1 && changedTags.itemsToRemove.length == 0) {
 | 
				
			||||||
@@ -124,11 +129,20 @@ export class BulkEditorComponent {
 | 
				
			|||||||
      modal.componentInstance.btnClass = "btn-warning"
 | 
					      modal.componentInstance.btnClass = "btn-warning"
 | 
				
			||||||
      modal.componentInstance.btnCaption = $localize`Confirm`
 | 
					      modal.componentInstance.btnCaption = $localize`Confirm`
 | 
				
			||||||
      modal.componentInstance.confirmClicked.subscribe(() => {
 | 
					      modal.componentInstance.confirmClicked.subscribe(() => {
 | 
				
			||||||
 | 
					        this.performSetTags(modal, changedTags)
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      this.performSetTags(null, changedTags)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private performSetTags(modal, changedTags: ChangedItems) {
 | 
				
			||||||
    this.executeBulkOperation('modify_tags', {"add_tags": changedTags.itemsToAdd.map(t => t.id), "remove_tags": changedTags.itemsToRemove.map(t => t.id)}).subscribe(
 | 
					    this.executeBulkOperation('modify_tags', {"add_tags": changedTags.itemsToAdd.map(t => t.id), "remove_tags": changedTags.itemsToRemove.map(t => t.id)}).subscribe(
 | 
				
			||||||
      response => {
 | 
					      response => {
 | 
				
			||||||
        this.tagService.clearCache()
 | 
					        this.tagService.clearCache()
 | 
				
			||||||
 | 
					        if (modal) {
 | 
				
			||||||
          modal.close()
 | 
					          modal.close()
 | 
				
			||||||
        })
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -136,9 +150,11 @@ export class BulkEditorComponent {
 | 
				
			|||||||
  setCorrespondents(changedCorrespondents: ChangedItems) {
 | 
					  setCorrespondents(changedCorrespondents: ChangedItems) {
 | 
				
			||||||
    if (changedCorrespondents.itemsToAdd.length == 0 && changedCorrespondents.itemsToRemove.length == 0) return
 | 
					    if (changedCorrespondents.itemsToAdd.length == 0 && changedCorrespondents.itemsToRemove.length == 0) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let correspondent = changedCorrespondents.itemsToAdd.length > 0 ? changedCorrespondents.itemsToAdd[0] : null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (this.showConfirmationDialogs) {
 | 
				
			||||||
      let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
 | 
					      let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
 | 
				
			||||||
      modal.componentInstance.title = $localize`Confirm correspondent assignment`
 | 
					      modal.componentInstance.title = $localize`Confirm correspondent assignment`
 | 
				
			||||||
    let correspondent = changedCorrespondents.itemsToAdd.length > 0 ? changedCorrespondents.itemsToAdd[0] : null
 | 
					 | 
				
			||||||
      if (correspondent) {
 | 
					      if (correspondent) {
 | 
				
			||||||
        modal.componentInstance.message = $localize`This operation will assign the correspondent ${correspondent.name} to all ${this.list.selected.size} selected document(s).`
 | 
					        modal.componentInstance.message = $localize`This operation will assign the correspondent ${correspondent.name} to all ${this.list.selected.size} selected document(s).`
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
@@ -147,21 +163,32 @@ export class BulkEditorComponent {
 | 
				
			|||||||
      modal.componentInstance.btnClass = "btn-warning"
 | 
					      modal.componentInstance.btnClass = "btn-warning"
 | 
				
			||||||
      modal.componentInstance.btnCaption = $localize`Confirm`
 | 
					      modal.componentInstance.btnCaption = $localize`Confirm`
 | 
				
			||||||
      modal.componentInstance.confirmClicked.subscribe(() => {
 | 
					      modal.componentInstance.confirmClicked.subscribe(() => {
 | 
				
			||||||
 | 
					        this.performSetCorrespondents(modal, correspondent)
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      this.performSetCorrespondents(null, correspondent)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private performSetCorrespondents(modal, correspondent: MatchingModel) {
 | 
				
			||||||
    this.executeBulkOperation('set_correspondent', {"correspondent": correspondent ? correspondent.id : null}).subscribe(
 | 
					    this.executeBulkOperation('set_correspondent', {"correspondent": correspondent ? correspondent.id : null}).subscribe(
 | 
				
			||||||
      response => {
 | 
					      response => {
 | 
				
			||||||
        this.correspondentService.clearCache()
 | 
					        this.correspondentService.clearCache()
 | 
				
			||||||
 | 
					        if (modal) {
 | 
				
			||||||
          modal.close()
 | 
					          modal.close()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setDocumentTypes(changedDocumentTypes: ChangedItems) {
 | 
					  setDocumentTypes(changedDocumentTypes: ChangedItems) {
 | 
				
			||||||
    if (changedDocumentTypes.itemsToAdd.length == 0 && changedDocumentTypes.itemsToRemove.length == 0) return
 | 
					    if (changedDocumentTypes.itemsToAdd.length == 0 && changedDocumentTypes.itemsToRemove.length == 0) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let documentType = changedDocumentTypes.itemsToAdd.length > 0 ? changedDocumentTypes.itemsToAdd[0] : null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (this.showConfirmationDialogs) {
 | 
				
			||||||
      let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
 | 
					      let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
 | 
				
			||||||
      modal.componentInstance.title = $localize`Confirm document type assignment`
 | 
					      modal.componentInstance.title = $localize`Confirm document type assignment`
 | 
				
			||||||
    let documentType = changedDocumentTypes.itemsToAdd.length > 0 ? changedDocumentTypes.itemsToAdd[0] : null
 | 
					 | 
				
			||||||
      if (documentType) {
 | 
					      if (documentType) {
 | 
				
			||||||
        modal.componentInstance.message = $localize`This operation will assign the document type ${documentType.name} to all ${this.list.selected.size} selected document(s).`
 | 
					        modal.componentInstance.message = $localize`This operation will assign the document type ${documentType.name} to all ${this.list.selected.size} selected document(s).`
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
@@ -170,13 +197,22 @@ export class BulkEditorComponent {
 | 
				
			|||||||
      modal.componentInstance.btnClass = "btn-warning"
 | 
					      modal.componentInstance.btnClass = "btn-warning"
 | 
				
			||||||
      modal.componentInstance.btnCaption = $localize`Confirm`
 | 
					      modal.componentInstance.btnCaption = $localize`Confirm`
 | 
				
			||||||
      modal.componentInstance.confirmClicked.subscribe(() => {
 | 
					      modal.componentInstance.confirmClicked.subscribe(() => {
 | 
				
			||||||
 | 
					        this.performSetDocumentTypes(modal, documentType)
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      this.performSetDocumentTypes(null, documentType)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private performSetDocumentTypes(modal, documentType) {
 | 
				
			||||||
    this.executeBulkOperation('set_document_type', {"document_type": documentType ? documentType.id : null}).subscribe(
 | 
					    this.executeBulkOperation('set_document_type', {"document_type": documentType ? documentType.id : null}).subscribe(
 | 
				
			||||||
      response => {
 | 
					      response => {
 | 
				
			||||||
          this.documentService.clearCache()
 | 
					        this.documentTypeService.clearCache()
 | 
				
			||||||
 | 
					        if (modal) {
 | 
				
			||||||
          modal.close()
 | 
					          modal.close()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  applyDelete() {
 | 
					  applyDelete() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,8 +26,15 @@
 | 
				
			|||||||
            </select>
 | 
					            </select>
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <h4 i18n>Bulk editing</h4>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <app-input-check i18n-title title="Show confirmation dialogs" formControlName="bulkEditConfirmationDialogs" i18n-hint hint="Deleting documents will always ask for confirmation."></app-input-check>
 | 
				
			||||||
 | 
					        <app-input-check i18n-title title="Apply on close" formControlName="bulkEditApplyOnClose"></app-input-check>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      </ng-template>
 | 
					      </ng-template>
 | 
				
			||||||
    </li>
 | 
					    </li>
 | 
				
			||||||
    <li [ngbNavItem]="2">
 | 
					    <li [ngbNavItem]="2">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
import { Component, OnInit } from '@angular/core';
 | 
					import { Component, OnInit } from '@angular/core';
 | 
				
			||||||
import { FormControl, FormGroup } from '@angular/forms';
 | 
					import { FormControl, FormGroup } from '@angular/forms';
 | 
				
			||||||
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
 | 
					import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
 | 
				
			||||||
import { GENERAL_SETTINGS } from 'src/app/data/storage-keys';
 | 
					 | 
				
			||||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
 | 
					import { DocumentListViewService } from 'src/app/services/document-list-view.service';
 | 
				
			||||||
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
 | 
					import { SavedViewService } from 'src/app/services/rest/saved-view.service';
 | 
				
			||||||
 | 
					import { SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service';
 | 
				
			||||||
import { ToastService } from 'src/app/services/toast.service';
 | 
					import { ToastService } from 'src/app/services/toast.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
@@ -16,14 +16,17 @@ export class SettingsComponent implements OnInit {
 | 
				
			|||||||
  savedViewGroup = new FormGroup({})
 | 
					  savedViewGroup = new FormGroup({})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  settingsForm = new FormGroup({
 | 
					  settingsForm = new FormGroup({
 | 
				
			||||||
    'documentListItemPerPage': new FormControl(+localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT),
 | 
					    'bulkEditConfirmationDialogs': new FormControl(this.settings.get(SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS)),
 | 
				
			||||||
 | 
					    'bulkEditApplyOnClose': new FormControl(this.settings.get(SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE)),
 | 
				
			||||||
 | 
					    'documentListItemPerPage': new FormControl(this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)),
 | 
				
			||||||
    'savedViews': this.savedViewGroup
 | 
					    'savedViews': this.savedViewGroup
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
    public savedViewService: SavedViewService,
 | 
					    public savedViewService: SavedViewService,
 | 
				
			||||||
    private documentListViewService: DocumentListViewService,
 | 
					    private documentListViewService: DocumentListViewService,
 | 
				
			||||||
    private toastService: ToastService
 | 
					    private toastService: ToastService,
 | 
				
			||||||
 | 
					    private settings: SettingsService
 | 
				
			||||||
  ) { }
 | 
					  ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  savedViews: PaperlessSavedView[]
 | 
					  savedViews: PaperlessSavedView[]
 | 
				
			||||||
@@ -51,7 +54,9 @@ export class SettingsComponent implements OnInit {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private saveLocalSettings() {
 | 
					  private saveLocalSettings() {
 | 
				
			||||||
    localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
 | 
					    this.settings.set(SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE, this.settingsForm.value.bulkEditApplyOnClose)
 | 
				
			||||||
 | 
					    this.settings.set(SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS, this.settingsForm.value.bulkEditConfirmationDialogs)
 | 
				
			||||||
 | 
					    this.settings.set(SETTINGS_KEYS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
 | 
				
			||||||
    this.documentListViewService.updatePageSize()
 | 
					    this.documentListViewService.updatePageSize()
 | 
				
			||||||
    this.toastService.showInfo($localize`Settings saved successfully.`)
 | 
					    this.toastService.showInfo($localize`Settings saved successfully.`)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,3 @@ export const OPEN_DOCUMENT_SERVICE = {
 | 
				
			|||||||
export const DOCUMENT_LIST_SERVICE = {
 | 
					export const DOCUMENT_LIST_SERVICE = {
 | 
				
			||||||
  CURRENT_VIEW_CONFIG: 'document-list-service:currentViewConfig'
 | 
					  CURRENT_VIEW_CONFIG: 'document-list-service:currentViewConfig'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
export const GENERAL_SETTINGS = {
 | 
					 | 
				
			||||||
  DOCUMENT_LIST_SIZE: 'general-settings:documentListSize',
 | 
					 | 
				
			||||||
  DOCUMENT_LIST_SIZE_DEFAULT: 50
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -3,8 +3,9 @@ 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 { PaperlessSavedView } from '../data/paperless-saved-view';
 | 
					import { PaperlessSavedView } from '../data/paperless-saved-view';
 | 
				
			||||||
import { DOCUMENT_LIST_SERVICE, GENERAL_SETTINGS } from '../data/storage-keys';
 | 
					import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys';
 | 
				
			||||||
import { DocumentService } from './rest/document.service';
 | 
					import { DocumentService } from './rest/document.service';
 | 
				
			||||||
 | 
					import { SettingsService, SETTINGS_KEYS } from './settings.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -23,7 +24,7 @@ export class DocumentListViewService {
 | 
				
			|||||||
  isReloading: boolean = false
 | 
					  isReloading: boolean = false
 | 
				
			||||||
  documents: PaperlessDocument[] = []
 | 
					  documents: PaperlessDocument[] = []
 | 
				
			||||||
  currentPage = 1
 | 
					  currentPage = 1
 | 
				
			||||||
  currentPageSize: number = +localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT
 | 
					  currentPageSize: number = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)
 | 
				
			||||||
  collectionSize: number
 | 
					  collectionSize: number
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
@@ -190,7 +191,7 @@ export class DocumentListViewService {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  updatePageSize() {
 | 
					  updatePageSize() {
 | 
				
			||||||
    let newPageSize = +localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT
 | 
					    let newPageSize = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)
 | 
				
			||||||
    if (newPageSize != this.currentPageSize) {
 | 
					    if (newPageSize != this.currentPageSize) {
 | 
				
			||||||
      this.currentPageSize = newPageSize
 | 
					      this.currentPageSize = newPageSize
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -239,7 +240,7 @@ export class DocumentListViewService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(private documentService: DocumentService) {
 | 
					  constructor(private documentService: DocumentService, private settings: SettingsService) {
 | 
				
			||||||
    let documentListViewConfigJson = sessionStorage.getItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG)
 | 
					    let documentListViewConfigJson = sessionStorage.getItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG)
 | 
				
			||||||
    if (documentListViewConfigJson) {
 | 
					    if (documentListViewConfigJson) {
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								src-ui/src/app/services/settings.service.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src-ui/src/app/services/settings.service.spec.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import { TestBed } from '@angular/core/testing';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { SettingsService } from './settings.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe('SettingsService', () => {
 | 
				
			||||||
 | 
					  let service: SettingsService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  beforeEach(() => {
 | 
				
			||||||
 | 
					    TestBed.configureTestingModule({});
 | 
				
			||||||
 | 
					    service = TestBed.inject(SettingsService);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it('should be created', () => {
 | 
				
			||||||
 | 
					    expect(service).toBeTruthy();
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										60
									
								
								src-ui/src/app/services/settings.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src-ui/src/app/services/settings.service.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
				
			|||||||
 | 
					import { Injectable } from '@angular/core';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface PaperlessSettings {
 | 
				
			||||||
 | 
					  key: string
 | 
				
			||||||
 | 
					  type: string
 | 
				
			||||||
 | 
					  default: any
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const SETTINGS_KEYS = {
 | 
				
			||||||
 | 
					  BULK_EDIT_CONFIRMATION_DIALOGS: 'general-settings:bulk-edit:confirmation-dialogs',
 | 
				
			||||||
 | 
					  BULK_EDIT_APPLY_ON_CLOSE: 'general-settings:bulk-edit:apply-on-close',
 | 
				
			||||||
 | 
					  DOCUMENT_LIST_SIZE: 'general-settings:documentListSize',
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const SETTINGS: PaperlessSettings[] = [
 | 
				
			||||||
 | 
					  {key: SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS, type: "boolean", default: true},
 | 
				
			||||||
 | 
					  {key: SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE, type: "boolean", default: false},
 | 
				
			||||||
 | 
					  {key: SETTINGS_KEYS.DOCUMENT_LIST_SIZE, type: "number", default: 50}
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Injectable({
 | 
				
			||||||
 | 
					  providedIn: 'root'
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					export class SettingsService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  constructor() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  get(key: string): any {
 | 
				
			||||||
 | 
					    let setting = SETTINGS.find(s => s.key == key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!setting) {
 | 
				
			||||||
 | 
					      return null
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let value = localStorage.getItem(key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (value != null) {
 | 
				
			||||||
 | 
					      switch (setting.type) {
 | 
				
			||||||
 | 
					        case "boolean":
 | 
				
			||||||
 | 
					          return JSON.parse(value)
 | 
				
			||||||
 | 
					        case "number":
 | 
				
			||||||
 | 
					          return +value
 | 
				
			||||||
 | 
					        case "string":
 | 
				
			||||||
 | 
					          return value
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					          return value
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      return setting.default
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  set(key: string, value: any) {
 | 
				
			||||||
 | 
					    localStorage.setItem(key, value.toString())
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  unset(key: string) {
 | 
				
			||||||
 | 
					    localStorage.removeItem(key)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user