Fix quick filtering

This commit is contained in:
Michael Shamoon 2022-03-27 00:09:09 -07:00
parent 7149d407cd
commit 0a29f51862
4 changed files with 14 additions and 21 deletions

View File

@ -81,7 +81,10 @@ export class AppFrameComponent {
search() {
this.closeMenu()
this.list.quickFilter([
{ rule_type: FILTER_FULLTEXT_QUERY, value: this.searchField.value },
{
rule_type: FILTER_FULLTEXT_QUERY,
value: (this.searchField.value as string).trim(),
},
])
}

View File

@ -151,8 +151,9 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
ngAfterViewInit(): void {
this.filterEditor.filterRulesChange.subscribe({
next: (rules) => {
const params = this.documentService.queryParams
next: (filterRules) => {
const params =
this.documentService.filterRulesToQueryParams(filterRules)
// if we were on a saved view we navigate 'away' to /documents
let base = []

View File

@ -249,20 +249,11 @@ export class DocumentListViewService {
}
quickFilter(filterRules: FilterRule[]) {
this._activeSavedViewId = null
this.activeListViewState.filterRules = filterRules
this.activeListViewState.currentPage = 1
if (isFullTextFilterRule(filterRules)) {
this.activeListViewState.sortField = 'score'
this.activeListViewState.sortReverse = false
}
this.reduceSelectionToFilter()
this.saveDocumentListView()
if (this.router.url == '/documents') {
this.reload()
} else {
this.router.navigate(['documents'])
}
const params = this.documentService.filterRulesToQueryParams(filterRules)
this.router.navigate(['/documents'], {
relativeTo: this.route,
queryParams: params,
})
}
getLastPage(): number {

View File

@ -47,7 +47,6 @@ export interface SelectionData {
})
export class DocumentService extends AbstractPaperlessService<PaperlessDocument> {
private _searchQuery: string
public queryParams: Object = {}
constructor(
http: HttpClient,
@ -58,7 +57,7 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
super(http, 'documents')
}
private filterRulesToQueryParams(filterRules: FilterRule[]): Object {
public filterRulesToQueryParams(filterRules: FilterRule[]): Object {
if (filterRules) {
let params = {}
for (let rule of filterRules) {
@ -102,13 +101,12 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
filterRules?: FilterRule[],
extraParams = {}
): Observable<Results<PaperlessDocument>> {
this.queryParams = this.filterRulesToQueryParams(filterRules)
return this.list(
page,
pageSize,
sortField,
sortReverse,
Object.assign(extraParams, this.queryParams)
Object.assign(extraParams, this.filterRulesToQueryParams(filterRules))
).pipe(
map((results) => {
results.results.forEach((doc) => this.addObservablesToDocument(doc))