Add query params for saved views

This commit is contained in:
Michael Shamoon 2022-05-04 22:31:09 -07:00
parent 98ebb095cc
commit 584082a1df
3 changed files with 45 additions and 30 deletions

View File

@ -60,8 +60,9 @@ export class SavedViewWidgetComponent implements OnInit, OnDestroy {
if (this.savedView.show_in_sidebar) { if (this.savedView.show_in_sidebar) {
this.router.navigate(['view', this.savedView.id]) this.router.navigate(['view', this.savedView.id])
} else { } else {
this.list.loadSavedView(this.savedView, true) this.router.navigate(['documents'], {
this.router.navigate(['documents']) queryParams: { view: this.savedView.id },
})
} }
} }

View File

@ -64,7 +64,7 @@
<button class="btn btn-sm btn-outline-primary dropdown-toggle flex-fill" ngbDropdownToggle i18n>Views</button> <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> <div class="dropdown-menu shadow dropdown-menu-right" ngbDropdownMenu>
<ng-container *ngIf="!list.activeSavedViewId"> <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> <div class="dropdown-divider" *ngIf="savedViewService.allViews.length > 0"></div>
</ng-container> </ng-container>

View File

@ -137,32 +137,36 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
takeUntil(this.unsubscribeNotifier) takeUntil(this.unsubscribeNotifier)
) )
.subscribe((queryParams) => { .subscribe((queryParams) => {
// transform query params to filter rules if (queryParams.has('view')) {
let filterRulesFromQueryParams: FilterRule[] = [] this.loadViewConfig(parseInt(queryParams.get('view')))
allFilterRuleQueryParams } else {
.filter((frqp) => queryParams.has(frqp)) // transform query params to filter rules
.forEach((filterQueryParamName) => { let filterRulesFromQueryParams: FilterRule[] = []
const filterQueryParamValues: string[] = queryParams allFilterRuleQueryParams
.get(filterQueryParamName) .filter((frqp) => queryParams.has(frqp))
.split(',') .forEach((filterQueryParamName) => {
const filterQueryParamValues: string[] = queryParams
.get(filterQueryParamName)
.split(',')
filterRulesFromQueryParams = filterRulesFromQueryParams.concat( filterRulesFromQueryParams = filterRulesFromQueryParams.concat(
// map all values to filter rules // map all values to filter rules
filterQueryParamValues.map((val) => { filterQueryParamValues.map((val) => {
return { return {
rule_type: FILTER_RULE_TYPES.find( rule_type: FILTER_RULE_TYPES.find(
(rt) => rt.filtervar == filterQueryParamName (rt) => rt.filtervar == filterQueryParamName
).id, ).id,
value: val, value: val,
} }
}) })
) )
}) })
this.list.activateSavedView(null) this.list.activateSavedView(null)
this.list.filterRules = filterRulesFromQueryParams this.list.filterRules = filterRulesFromQueryParams
this.list.reload() this.list.reload()
this.unmodifiedFilterRules = [] this.unmodifiedFilterRules = []
}
}) })
} }
@ -192,9 +196,19 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
this.unsubscribeNotifier.complete() this.unsubscribeNotifier.complete()
} }
loadViewConfig(view: PaperlessSavedView) { loadViewConfig(viewId: number) {
this.list.loadSavedView(view) this.savedViewService
this.list.reload() .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() { saveViewConfig() {