Automatically remove suggestions after add

This commit is contained in:
shamoon
2025-04-22 00:21:26 -07:00
parent be20c48588
commit 105b823fd9
3 changed files with 86 additions and 1 deletions

View File

@@ -90,6 +90,7 @@ import { CorrespondentEditDialogComponent } from '../common/edit-dialog/correspo
import { DocumentTypeEditDialogComponent } from '../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component'
import { EditDialogMode } from '../common/edit-dialog/edit-dialog.component'
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
import { TagEditDialogComponent } from '../common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component'
import { EmailDocumentDialogComponent } from '../common/email-document-dialog/email-document-dialog.component'
import { CheckComponent } from '../common/input/check/check.component'
import { DateComponent } from '../common/input/date/date.component'
@@ -694,6 +695,47 @@ export class DocumentDetailComponent
})
}
public removeSuggestion(type: string, value: string) {
if (!this.suggestions) return
switch (type) {
case 'tag':
this.suggestions.suggested_tags =
this.suggestions.suggested_tags.filter((t) => t !== value)
break
case 'correspondent':
this.suggestions.suggested_correspondents =
this.suggestions.suggested_correspondents.filter((c) => c !== value)
break
case 'documentType':
this.suggestions.suggested_document_types =
this.suggestions.suggested_document_types.filter((dt) => dt !== value)
break
}
}
createTag(newName: string) {
var modal = this.modalService.open(TagEditDialogComponent, {
backdrop: 'static',
})
modal.componentInstance.dialogMode = EditDialogMode.CREATE
if (newName) modal.componentInstance.object = { name: newName }
modal.componentInstance.succeeded
.pipe(
switchMap((newTag) => {
return this.tagService
.listAll()
.pipe(map((tags) => ({ newTag, tags })))
})
)
.pipe(takeUntil(this.unsubscribeNotifier))
.subscribe(({ newTag, tags }) => {
this.tagsInput.tags = tags.results
this.tagsInput.addTag(newTag.id)
this.removeSuggestion('tag', newName)
})
}
createDocumentType(newName: string) {
var modal = this.modalService.open(DocumentTypeEditDialogComponent, {
backdrop: 'static',
@@ -713,6 +755,7 @@ export class DocumentDetailComponent
this.documentTypes = documentTypes.results
this.documentForm.get('document_type').setValue(newDocumentType.id)
this.documentForm.get('document_type').markAsDirty()
this.removeSuggestion('documentType', newName)
})
}
@@ -737,6 +780,7 @@ export class DocumentDetailComponent
this.correspondents = correspondents.results
this.documentForm.get('correspondent').setValue(newCorrespondent.id)
this.documentForm.get('correspondent').markAsDirty()
this.removeSuggestion('correspondent', newName)
})
}