Change detection of modified filter rules to wait for filter editor changes only

This commit is contained in:
Michael Shamoon 2021-01-06 07:53:48 -08:00
parent 507085ee7b
commit 14a2ad2b0d
2 changed files with 11 additions and 5 deletions

View File

@ -78,7 +78,7 @@
</app-page-header> </app-page-header>
<div class="w-100 mb-2 mb-sm-4"> <div class="w-100 mb-2 mb-sm-4">
<app-filter-editor [hidden]="isBulkEditing" [(filterRules)]="list.filterRules" [rulesModified]="filterRulesModified" (reset)="resetFilters()" #filterEditor></app-filter-editor> <app-filter-editor [hidden]="isBulkEditing" [(filterRules)]="list.filterRules" [rulesModified]="filterRulesModified" (filterRulesChange)="rulesChanged()" (reset)="resetFilters()" #filterEditor></app-filter-editor>
<app-bulk-editor [hidden]="!isBulkEditing"></app-bulk-editor> <app-bulk-editor [hidden]="!isBulkEditing"></app-bulk-editor>
</div> </div>

View File

@ -66,9 +66,12 @@ export class DocumentListComponent implements OnInit {
this.list.reload() this.list.reload()
}) })
this.rulesChanged()
} }
loadViewConfig(view: PaperlessSavedView) { loadViewConfig(view: PaperlessSavedView) {
this.filterRulesModified = false
this.list.load(view) this.list.load(view)
this.list.reload() this.list.reload()
} }
@ -105,6 +108,7 @@ export class DocumentListComponent implements OnInit {
} }
resetFilters(): void { resetFilters(): void {
this.filterRulesModified = false;
if (this.list.savedViewId) { if (this.list.savedViewId) {
this.savedViewService.getCached(this.list.savedViewId).subscribe(viewUntouched => { this.savedViewService.getCached(this.list.savedViewId).subscribe(viewUntouched => {
this.list.filterRules = viewUntouched.filter_rules this.list.filterRules = viewUntouched.filter_rules
@ -116,12 +120,14 @@ export class DocumentListComponent implements OnInit {
} }
} }
get filterRulesModified(): boolean { filterRulesModified: boolean = false
rulesChanged() {
let modified = false
if (this.list.savedView == null) { if (this.list.savedView == null) {
return this.list.filterRules.length > 0 // documents list is modified if it has any filters modified = this.list.filterRules.length > 0 // documents list is modified if it has any filters
} else { } else {
// compare savedView current filters vs original // compare savedView current filters vs original
let modified = false
this.savedViewService.getCached(this.list.savedViewId).subscribe(view => { this.savedViewService.getCached(this.list.savedViewId).subscribe(view => {
let filterRulesInitial = view.filter_rules let filterRulesInitial = view.filter_rules
@ -135,8 +141,8 @@ export class DocumentListComponent implements OnInit {
}) })
} }
}) })
return modified
} }
this.filterRulesModified = modified
} }
clickTag(tagID: number) { clickTag(tagID: number) {