mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	refactor filter reset
This commit is contained in:
		| @@ -76,7 +76,7 @@ | ||||
| </app-page-header> | ||||
|  | ||||
| <div class="w-100 mb-2 mb-sm-4"> | ||||
|   <app-filter-editor [hidden]="isBulkEditing" [(filterRules)]="list.filterRules" [rulesModified]="filterRulesModified" (filterRulesChange)="rulesChanged()" (reset)="resetFilters()" #filterEditor></app-filter-editor> | ||||
|   <app-filter-editor [hidden]="isBulkEditing" [(filterRules)]="list.filterRules" [unmodifiedFilterRules]="unmodifiedFilterRules" #filterEditor></app-filter-editor> | ||||
|   <app-bulk-editor [hidden]="!isBulkEditing"></app-bulk-editor> | ||||
| </div> | ||||
|  | ||||
|   | ||||
| @@ -2,6 +2,7 @@ import { Component, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren } from | ||||
| import { ActivatedRoute, Router } from '@angular/router'; | ||||
| import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||||
| import { Subscription } from 'rxjs'; | ||||
| import { FilterRule } from 'src/app/data/filter-rule'; | ||||
| import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type'; | ||||
| import { PaperlessDocument } from 'src/app/data/paperless-document'; | ||||
| import { PaperlessSavedView } from 'src/app/data/paperless-saved-view'; | ||||
| @@ -38,7 +39,7 @@ export class DocumentListComponent implements OnInit, OnDestroy { | ||||
|  | ||||
|   displayMode = 'smallCards' // largeCards, smallCards, details | ||||
|  | ||||
|   filterRulesModified: boolean = false | ||||
|   unmodifiedFilterRules: FilterRule[] = [] | ||||
|  | ||||
|   private consumptionFinishedSubscription: Subscription | ||||
|  | ||||
| @@ -82,12 +83,12 @@ export class DocumentListComponent implements OnInit, OnDestroy { | ||||
|           } | ||||
|           this.list.activateSavedView(view) | ||||
|           this.list.reload() | ||||
|           this.rulesChanged() | ||||
|           this.unmodifiedFilterRules = view.filter_rules | ||||
|         }) | ||||
|       } else { | ||||
|         this.list.activateSavedView(null) | ||||
|         this.list.reload() | ||||
|         this.rulesChanged() | ||||
|         this.unmodifiedFilterRules = [] | ||||
|       } | ||||
|     }) | ||||
|   } | ||||
| @@ -101,7 +102,6 @@ export class DocumentListComponent implements OnInit, OnDestroy { | ||||
|   loadViewConfig(view: PaperlessSavedView) { | ||||
|     this.list.loadSavedView(view) | ||||
|     this.list.reload() | ||||
|     this.rulesChanged() | ||||
|   } | ||||
|  | ||||
|   saveViewConfig() { | ||||
| @@ -142,46 +142,6 @@ export class DocumentListComponent implements OnInit, OnDestroy { | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   resetFilters(): void { | ||||
|     this.filterRulesModified = false | ||||
|     if (this.list.activeSavedViewId) { | ||||
|       this.savedViewService.getCached(this.list.activeSavedViewId).subscribe(viewUntouched => { | ||||
|         this.list.filterRules = viewUntouched.filter_rules | ||||
|         this.list.reload() | ||||
|       }) | ||||
|     } else { | ||||
|       this.list.filterRules = [] | ||||
|       this.list.reload() | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   rulesChanged() { | ||||
|     let modified = false | ||||
|     if (this.list.activeSavedViewId == null) { | ||||
|       modified = this.list.filterRules.length > 0 // documents list is modified if it has any filters | ||||
|     } else { | ||||
|       // compare savedView current filters vs original | ||||
|       this.savedViewService.getCached(this.list.activeSavedViewId).subscribe(view => { | ||||
|         let filterRulesInitial = view.filter_rules | ||||
|  | ||||
|         if (this.list.filterRules.length !== filterRulesInitial.length) modified = true | ||||
|         else { | ||||
|           modified = this.list.filterRules.some(rule => { | ||||
|             return (filterRulesInitial.find(fri => fri.rule_type == rule.rule_type && fri.value == rule.value) == undefined) | ||||
|           }) | ||||
|  | ||||
|           if (!modified) { | ||||
|             // only check other direction if we havent already determined is modified | ||||
|             modified = filterRulesInitial.some(rule => { | ||||
|               this.list.filterRules.find(fr => fr.rule_type == rule.rule_type && fr.value == rule.value) == undefined | ||||
|             }) | ||||
|           } | ||||
|         } | ||||
|       }) | ||||
|     } | ||||
|     this.filterRulesModified = modified | ||||
|   } | ||||
|  | ||||
|   toggleSelected(document: PaperlessDocument, event: MouseEvent): void { | ||||
|     if (!event.shiftKey) this.list.toggleSelected(document) | ||||
|     else this.list.selectRangeTo(document) | ||||
|   | ||||
| @@ -109,8 +109,23 @@ export class FilterEditorComponent implements OnInit, OnDestroy { | ||||
|   dateAddedBefore: string | ||||
|   dateAddedAfter: string | ||||
|  | ||||
|   _unmodifiedFilterRules: FilterRule[] = [] | ||||
|   _filterRules: FilterRule[] = [] | ||||
|  | ||||
|   @Input() | ||||
|   set unmodifiedFilterRules(value: FilterRule[]) { | ||||
|     this._unmodifiedFilterRules = value | ||||
|     this.checkIfRulesHaveChanged() | ||||
|   } | ||||
|  | ||||
|   get unmodifiedFilterRules(): FilterRule[] { | ||||
|     return this._unmodifiedFilterRules | ||||
|   } | ||||
|  | ||||
|   @Input() | ||||
|   set filterRules (value: FilterRule[]) { | ||||
|     this._filterRules = value | ||||
|      | ||||
|     this.documentTypeSelectionModel.clear(false) | ||||
|     this.tagSelectionModel.clear(false) | ||||
|     this.correspondentSelectionModel.clear(false) | ||||
| @@ -172,6 +187,7 @@ export class FilterEditorComponent implements OnInit, OnDestroy { | ||||
|           break | ||||
|       } | ||||
|     }) | ||||
|     this.checkIfRulesHaveChanged() | ||||
|   } | ||||
|  | ||||
|   get filterRules(): FilterRule[] { | ||||
| @@ -222,12 +238,27 @@ export class FilterEditorComponent implements OnInit, OnDestroy { | ||||
|   @Output() | ||||
|   filterRulesChange = new EventEmitter<FilterRule[]>() | ||||
|  | ||||
|   @Output() | ||||
|   reset = new EventEmitter() | ||||
|  | ||||
|   @Input() | ||||
|   rulesModified: boolean = false | ||||
|  | ||||
|   private checkIfRulesHaveChanged() { | ||||
|     let modified = false | ||||
|     if (this._unmodifiedFilterRules.length != this._filterRules.length) { | ||||
|       modified = true | ||||
|     } else { | ||||
|       modified = this._unmodifiedFilterRules.some(rule => { | ||||
|         return (this._filterRules.find(fri => fri.rule_type == rule.rule_type && fri.value == rule.value) == undefined) | ||||
|       }) | ||||
|  | ||||
|       if (!modified) { | ||||
|         // only check other direction if we havent already determined is modified | ||||
|         modified = this._filterRules.some(rule => { | ||||
|           this._unmodifiedFilterRules.find(fr => fr.rule_type == rule.rule_type && fr.value == rule.value) == undefined | ||||
|         }) | ||||
|       } | ||||
|     } | ||||
|     this.rulesModified = modified | ||||
|   } | ||||
|  | ||||
|   updateRules() { | ||||
|     this.filterRulesChange.next(this.filterRules) | ||||
|   } | ||||
| @@ -265,7 +296,8 @@ export class FilterEditorComponent implements OnInit, OnDestroy { | ||||
|  | ||||
|   resetSelected() { | ||||
|     this.textFilterTarget = TEXT_FILTER_TARGET_TITLE_CONTENT | ||||
|     this.reset.next() | ||||
|     this.filterRules = this._unmodifiedFilterRules | ||||
|     this.updateRules() | ||||
|   } | ||||
|  | ||||
|   toggleTag(tagId: number) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler