From cd72ed2cec8220dc63981d0f48961d92b1ec46a7 Mon Sep 17 00:00:00 2001
From: Michael Shamoon <4887959+shamoon@users.noreply.github.com>
Date: Wed, 24 Mar 2021 12:13:37 -0700
Subject: [PATCH 1/8] Support passing current term from tag search to create
dialog
---
.../common/input/tags/tags.component.html | 7 ++++---
.../components/common/input/tags/tags.component.ts | 14 ++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src-ui/src/app/components/common/input/tags/tags.component.html b/src-ui/src/app/components/common/input/tags/tags.component.html
index 677b9f4d1..5500930bb 100644
--- a/src-ui/src/app/components/common/input/tags/tags.component.html
+++ b/src-ui/src/app/components/common/input/tags/tags.component.html
@@ -8,7 +8,8 @@
[clearSearchOnAdd]="true"
[hideSelected]="true"
(change)="onChange(value)"
- (blur)="onTouched()">
+ (search)="onSearch($event)"
+ (focus)="onFocus()">
@@ -39,8 +40,8 @@
{{tag.name}}
-
-
+
+
diff --git a/src-ui/src/app/components/common/input/tags/tags.component.ts b/src-ui/src/app/components/common/input/tags/tags.component.ts
index f77d0570d..336341bc3 100644
--- a/src-ui/src/app/components/common/input/tags/tags.component.ts
+++ b/src-ui/src/app/components/common/input/tags/tags.component.ts
@@ -56,6 +56,8 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
tags: PaperlessTag[]
+ private _lastSearchTerm: string
+
getTag(id) {
if (this.tags) {
return this.tags.find(tag => tag.id == id)
@@ -77,6 +79,7 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
createTag() {
var modal = this.modalService.open(TagEditDialogComponent, {backdrop: 'static'})
modal.componentInstance.dialogMode = 'create'
+ if (this._lastSearchTerm) modal.componentInstance.object = { name: this._lastSearchTerm }
modal.componentInstance.success.subscribe(newTag => {
this.tagService.listAll().subscribe(tags => {
this.tags = tags.results
@@ -84,6 +87,9 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
this.onChange(this.value)
})
})
+ modal.result.then(() => {
+ this._lastSearchTerm = null
+ })
}
getSuggestions() {
@@ -99,4 +105,12 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
this.onChange(this.value)
}
+ onFocus() {
+ this._lastSearchTerm = null
+ }
+
+ onSearch($event) {
+ this._lastSearchTerm = $event.term
+ }
+
}
From 52bc1a62e1525204a6803e538ba7a850c7855a62 Mon Sep 17 00:00:00 2001
From: Michael Shamoon <4887959+shamoon@users.noreply.github.com>
Date: Wed, 24 Mar 2021 12:21:13 -0700
Subject: [PATCH 2/8] Support passing current term from input-select search to
create dialog e.g. for doc type / correspondent
---
.../common/input/select/select.component.html | 9 +++++----
.../common/input/select/select.component.ts | 17 ++++++++++++++++-
.../document-detail.component.html | 4 ++--
.../document-detail.component.ts | 6 ++++--
4 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/src-ui/src/app/components/common/input/select/select.component.html b/src-ui/src/app/components/common/input/select/select.component.html
index 540429e89..59d0f9ca3 100644
--- a/src-ui/src/app/components/common/input/select/select.component.html
+++ b/src-ui/src/app/components/common/input/select/select.component.html
@@ -10,11 +10,12 @@
bindLabel="name"
bindValue="id"
(change)="onChange(value)"
- (blur)="onTouched()">
+ (search)="onSearch($event)"
+ (focus)="onFocus()">
diff --git a/src-ui/src/app/components/common/input/select/select.component.ts b/src-ui/src/app/components/common/input/select/select.component.ts
index e02aaab72..6eaf7795f 100644
--- a/src-ui/src/app/components/common/input/select/select.component.ts
+++ b/src-ui/src/app/components/common/input/select/select.component.ts
@@ -34,7 +34,9 @@ export class SelectComponent extends AbstractInputComponent {
suggestions: number[]
@Output()
- createNew = new EventEmitter()
+ createNew = new EventEmitter()
+
+ private _lastSearchTerm: string
showPlusButton(): boolean {
return this.createNew.observers.length > 0
@@ -48,4 +50,17 @@ export class SelectComponent extends AbstractInputComponent {
}
}
+ clickNew() {
+ this.createNew.next(this._lastSearchTerm)
+ this._lastSearchTerm = null
+ }
+
+ onFocus() {
+ this._lastSearchTerm = null
+ }
+
+ onSearch($event) {
+ this._lastSearchTerm = $event.term
+ }
+
}
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html
index f9b87aee3..1286225fb 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.html
+++ b/src-ui/src/app/components/document-detail/document-detail.component.html
@@ -60,9 +60,9 @@
+ (createNew)="createCorrespondent($event)" [suggestions]="suggestions?.correspondents">
+ (createNew)="createDocumentType($event)" [suggestions]="suggestions?.document_types">
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.ts
index af98a6f7f..7dd5dd80d 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
@@ -127,9 +127,10 @@ export class DocumentDetailComponent implements OnInit {
this.documentForm.patchValue(doc)
}
- createDocumentType() {
+ createDocumentType(newName: string) {
var modal = this.modalService.open(DocumentTypeEditDialogComponent, {backdrop: 'static'})
modal.componentInstance.dialogMode = 'create'
+ if (newName) modal.componentInstance.object = { name: newName }
modal.componentInstance.success.subscribe(newDocumentType => {
this.documentTypeService.listAll().subscribe(documentTypes => {
this.documentTypes = documentTypes.results
@@ -138,9 +139,10 @@ export class DocumentDetailComponent implements OnInit {
})
}
- createCorrespondent() {
+ createCorrespondent(newName: string) {
var modal = this.modalService.open(CorrespondentEditDialogComponent, {backdrop: 'static'})
modal.componentInstance.dialogMode = 'create'
+ if (newName) modal.componentInstance.object = { name: newName }
modal.componentInstance.success.subscribe(newCorrespondent => {
this.correspondentService.listAll().subscribe(correspondents => {
this.correspondents = correspondents.results
From 8ddb3e80b7674cf7906a21e7ed3cee1fc385ff2a Mon Sep 17 00:00:00 2001
From: Michael Shamoon <4887959+shamoon@users.noreply.github.com>
Date: Wed, 24 Mar 2021 12:21:51 -0700
Subject: [PATCH 3/8] Add timeout for clearing last search term on select blur
---
.../components/common/input/select/select.component.html | 3 ++-
.../app/components/common/input/select/select.component.ts | 6 ++++++
.../app/components/common/input/tags/tags.component.html | 3 ++-
.../src/app/components/common/input/tags/tags.component.ts | 6 ++++++
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src-ui/src/app/components/common/input/select/select.component.html b/src-ui/src/app/components/common/input/select/select.component.html
index 59d0f9ca3..a2834a1c9 100644
--- a/src-ui/src/app/components/common/input/select/select.component.html
+++ b/src-ui/src/app/components/common/input/select/select.component.html
@@ -11,7 +11,8 @@
bindValue="id"
(change)="onChange(value)"
(search)="onSearch($event)"
- (focus)="onFocus()">
+ (focus)="onFocus()"
+ (blur)="onBlur()">