From e4ec52ed29d5c3e5aa6cf3dde8e9119a4b56eae0 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Wed, 16 Dec 2020 18:16:14 +0100 Subject: [PATCH] default saved view names --- .../document-list/document-list.component.ts | 2 ++ .../save-view-config-dialog.component.ts | 15 +++++++++++++- .../filter-editor/filter-editor.component.ts | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) 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.ts index 4b711f9dc..25d92e9db 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 @@ -1,6 +1,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { FILTER_CORRESPONDENT } from 'src/app/data/filter-rule-type'; import { PaperlessSavedView } from 'src/app/data/paperless-saved-view'; import { DocumentListViewService } from 'src/app/services/document-list-view.service'; import { DOCUMENT_SORT_FIELDS } from 'src/app/services/rest/document.service'; @@ -83,6 +84,7 @@ export class DocumentListComponent implements OnInit { saveViewConfigAs() { let modal = this.modalService.open(SaveViewConfigDialogComponent, {backdrop: 'static'}) + modal.componentInstance.defaultName = this.filterEditor.generateFilterName() modal.componentInstance.saveClicked.subscribe(formValue => { let savedView = { name: formValue.name, diff --git a/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts b/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts index 284be49f6..8f0eb26f2 100644 --- a/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts +++ b/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, OnInit, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; @@ -14,6 +14,19 @@ export class SaveViewConfigDialogComponent implements OnInit { @Output() public saveClicked = new EventEmitter() + _defaultName = "" + + get defaultName() { + return this._defaultName + } + + @Input() + set defaultName(value: string) { + this._defaultName = value + this.saveViewConfigForm.patchValue({name: value}) + } + + saveViewConfigForm = new FormGroup({ name: new FormControl(''), showInSideBar: new FormControl(false), diff --git a/src-ui/src/app/components/filter-editor/filter-editor.component.ts b/src-ui/src/app/components/filter-editor/filter-editor.component.ts index a11f0736a..f762c6138 100644 --- a/src-ui/src/app/components/filter-editor/filter-editor.component.ts +++ b/src-ui/src/app/components/filter-editor/filter-editor.component.ts @@ -19,6 +19,26 @@ import { DateSelection } from './filter-dropdown-date/filter-dropdown-date.compo }) export class FilterEditorComponent implements OnInit, OnDestroy { + generateFilterName() { + if (this.filterRules.length == 1) { + let rule = this.filterRules[0] + switch(this.filterRules[0].rule_type) { + + case FILTER_CORRESPONDENT: + return `Correspondent: ${this.correspondents.find(c => c.id == +rule.value)?.name}` + + case FILTER_DOCUMENT_TYPE: + return `Type: ${this.documentTypes.find(dt => dt.id == +rule.value)?.name}` + + case FILTER_HAS_TAG: + return `Tag: ${this.tags.find(t => t.id == +rule.value)?.name}` + + } + } + + return "" + } + constructor( private documentTypeService: DocumentTypeService, private tagService: TagService,