mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Add query params for saved views
This commit is contained in:
parent
98ebb095cc
commit
584082a1df
@ -60,8 +60,9 @@ export class SavedViewWidgetComponent implements OnInit, OnDestroy {
|
||||
if (this.savedView.show_in_sidebar) {
|
||||
this.router.navigate(['view', this.savedView.id])
|
||||
} else {
|
||||
this.list.loadSavedView(this.savedView, true)
|
||||
this.router.navigate(['documents'])
|
||||
this.router.navigate(['documents'], {
|
||||
queryParams: { view: this.savedView.id },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@
|
||||
<button class="btn btn-sm btn-outline-primary dropdown-toggle flex-fill" ngbDropdownToggle i18n>Views</button>
|
||||
<div class="dropdown-menu shadow dropdown-menu-right" ngbDropdownMenu>
|
||||
<ng-container *ngIf="!list.activeSavedViewId">
|
||||
<button ngbDropdownItem *ngFor="let view of savedViewService.allViews" (click)="loadViewConfig(view)">{{view.name}}</button>
|
||||
<button ngbDropdownItem *ngFor="let view of savedViewService.allViews" (click)="loadViewConfig(view.id)">{{view.name}}</button>
|
||||
<div class="dropdown-divider" *ngIf="savedViewService.allViews.length > 0"></div>
|
||||
</ng-container>
|
||||
|
||||
|
@ -137,32 +137,36 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
takeUntil(this.unsubscribeNotifier)
|
||||
)
|
||||
.subscribe((queryParams) => {
|
||||
// transform query params to filter rules
|
||||
let filterRulesFromQueryParams: FilterRule[] = []
|
||||
allFilterRuleQueryParams
|
||||
.filter((frqp) => queryParams.has(frqp))
|
||||
.forEach((filterQueryParamName) => {
|
||||
const filterQueryParamValues: string[] = queryParams
|
||||
.get(filterQueryParamName)
|
||||
.split(',')
|
||||
if (queryParams.has('view')) {
|
||||
this.loadViewConfig(parseInt(queryParams.get('view')))
|
||||
} else {
|
||||
// transform query params to filter rules
|
||||
let filterRulesFromQueryParams: FilterRule[] = []
|
||||
allFilterRuleQueryParams
|
||||
.filter((frqp) => queryParams.has(frqp))
|
||||
.forEach((filterQueryParamName) => {
|
||||
const filterQueryParamValues: string[] = queryParams
|
||||
.get(filterQueryParamName)
|
||||
.split(',')
|
||||
|
||||
filterRulesFromQueryParams = filterRulesFromQueryParams.concat(
|
||||
// map all values to filter rules
|
||||
filterQueryParamValues.map((val) => {
|
||||
return {
|
||||
rule_type: FILTER_RULE_TYPES.find(
|
||||
(rt) => rt.filtervar == filterQueryParamName
|
||||
).id,
|
||||
value: val,
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
filterRulesFromQueryParams = filterRulesFromQueryParams.concat(
|
||||
// map all values to filter rules
|
||||
filterQueryParamValues.map((val) => {
|
||||
return {
|
||||
rule_type: FILTER_RULE_TYPES.find(
|
||||
(rt) => rt.filtervar == filterQueryParamName
|
||||
).id,
|
||||
value: val,
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
this.list.activateSavedView(null)
|
||||
this.list.filterRules = filterRulesFromQueryParams
|
||||
this.list.reload()
|
||||
this.unmodifiedFilterRules = []
|
||||
this.list.activateSavedView(null)
|
||||
this.list.filterRules = filterRulesFromQueryParams
|
||||
this.list.reload()
|
||||
this.unmodifiedFilterRules = []
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -192,9 +196,19 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
this.unsubscribeNotifier.complete()
|
||||
}
|
||||
|
||||
loadViewConfig(view: PaperlessSavedView) {
|
||||
this.list.loadSavedView(view)
|
||||
this.list.reload()
|
||||
loadViewConfig(viewId: number) {
|
||||
this.savedViewService
|
||||
.getCached(viewId)
|
||||
.pipe(first())
|
||||
.subscribe((view) => {
|
||||
this.list.loadSavedView(view)
|
||||
this.list.reload()
|
||||
// update query params if needed
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: { view: viewId },
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
saveViewConfig() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user