mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-01-10 21:34:20 -06:00
Tweak: use anchor element for filter documents list
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
||||||
import { Component, inject } from '@angular/core'
|
import { Component, inject } from '@angular/core'
|
||||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||||
|
import { RouterModule } from '@angular/router'
|
||||||
import {
|
import {
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
NgbPaginationModule,
|
NgbPaginationModule,
|
||||||
@@ -29,6 +30,7 @@ import { ManagementListComponent } from '../management-list/management-list.comp
|
|||||||
TitleCasePipe,
|
TitleCasePipe,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
|
RouterModule,
|
||||||
NgClass,
|
NgClass,
|
||||||
NgTemplateOutlet,
|
NgTemplateOutlet,
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
||||||
import { Component, inject } from '@angular/core'
|
import { Component, inject } from '@angular/core'
|
||||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||||
|
import { RouterModule } from '@angular/router'
|
||||||
import {
|
import {
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
NgbPaginationModule,
|
NgbPaginationModule,
|
||||||
@@ -27,6 +28,7 @@ import { ManagementListComponent } from '../management-list/management-list.comp
|
|||||||
IfPermissionsDirective,
|
IfPermissionsDirective,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
|
RouterModule,
|
||||||
NgClass,
|
NgClass,
|
||||||
NgTemplateOutlet,
|
NgTemplateOutlet,
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
|
|||||||
@@ -120,7 +120,14 @@
|
|||||||
<button (click)="openEditDialog(object)" *pngxIfPermissions="{ action: PermissionAction.Change, type: permissionType }" ngbDropdownItem i18n>Edit</button>
|
<button (click)="openEditDialog(object)" *pngxIfPermissions="{ action: PermissionAction.Change, type: permissionType }" ngbDropdownItem i18n>Edit</button>
|
||||||
<button class="text-danger" (click)="openDeleteDialog(object)" *pngxIfPermissions="{ action: PermissionAction.Delete, type: permissionType }" ngbDropdownItem i18n>Delete</button>
|
<button class="text-danger" (click)="openDeleteDialog(object)" *pngxIfPermissions="{ action: PermissionAction.Delete, type: permissionType }" ngbDropdownItem i18n>Delete</button>
|
||||||
@if (getDocumentCount(object) > 0) {
|
@if (getDocumentCount(object) > 0) {
|
||||||
<button (click)="filterDocuments(object)" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Document }" ngbDropdownItem i18n>Filter Documents ({{ getDocumentCount(object) }})</button>
|
<a
|
||||||
|
*pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Document }"
|
||||||
|
ngbDropdownItem
|
||||||
|
[routerLink]="getDocumentFilterUrl(object)"
|
||||||
|
(click)="$event?.stopPropagation()"
|
||||||
|
i18n
|
||||||
|
>Filter Documents ({{ getDocumentCount(object) }})</a
|
||||||
|
>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -135,9 +142,15 @@
|
|||||||
</div>
|
</div>
|
||||||
@if (getDocumentCount(object) > 0) {
|
@if (getDocumentCount(object) > 0) {
|
||||||
<div class="btn-group d-none d-sm-inline-block">
|
<div class="btn-group d-none d-sm-inline-block">
|
||||||
<button class="btn btn-sm btn-outline-secondary" (click)="filterDocuments(object); $event.stopPropagation();" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Document }">
|
<a
|
||||||
<i-bs width="1em" height="1em" name="filter"></i-bs> <ng-container i18n>Documents</ng-container><span class="badge bg-light text-secondary ms-2">{{ getDocumentCount(object) }}</span>
|
class="btn btn-sm btn-outline-secondary"
|
||||||
</button>
|
*pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Document }"
|
||||||
|
[routerLink]="getDocumentFilterUrl(object)"
|
||||||
|
(click)="$event?.stopPropagation()"
|
||||||
|
>
|
||||||
|
<i-bs width="1em" height="1em" name="filter"></i-bs> <ng-container i18n>Documents</ng-container
|
||||||
|
><span class="badge bg-light text-secondary ms-2">{{ getDocumentCount(object) }}</span>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -230,8 +230,8 @@ export abstract class ManagementListComponent<T extends MatchingModel>
|
|||||||
|
|
||||||
abstract getDeleteMessage(object: T)
|
abstract getDeleteMessage(object: T)
|
||||||
|
|
||||||
filterDocuments(object: MatchingModel) {
|
getDocumentFilterUrl(object: MatchingModel) {
|
||||||
this.documentListViewService.quickFilter([
|
return this.documentListViewService.getQuickFilterUrl([
|
||||||
{ rule_type: this.filterRuleType, value: object.id.toString() },
|
{ rule_type: this.filterRuleType, value: object.id.toString() },
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
||||||
import { Component, inject } from '@angular/core'
|
import { Component, inject } from '@angular/core'
|
||||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||||
|
import { RouterModule } from '@angular/router'
|
||||||
import {
|
import {
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
NgbPaginationModule,
|
NgbPaginationModule,
|
||||||
@@ -27,6 +28,7 @@ import { ManagementListComponent } from '../management-list/management-list.comp
|
|||||||
IfPermissionsDirective,
|
IfPermissionsDirective,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
|
RouterModule,
|
||||||
NgClass,
|
NgClass,
|
||||||
NgTemplateOutlet,
|
NgTemplateOutlet,
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
import { NgClass, NgTemplateOutlet, TitleCasePipe } from '@angular/common'
|
||||||
import { Component, inject } from '@angular/core'
|
import { Component, inject } from '@angular/core'
|
||||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||||
|
import { RouterModule } from '@angular/router'
|
||||||
import {
|
import {
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
NgbPaginationModule,
|
NgbPaginationModule,
|
||||||
@@ -27,6 +28,7 @@ import { ManagementListComponent } from '../management-list/management-list.comp
|
|||||||
IfPermissionsDirective,
|
IfPermissionsDirective,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
|
RouterModule,
|
||||||
NgClass,
|
NgClass,
|
||||||
NgTemplateOutlet,
|
NgTemplateOutlet,
|
||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
|
|||||||
@@ -651,4 +651,25 @@ describe('DocumentListViewService', () => {
|
|||||||
documentListViewService.displayFields = customFields as any
|
documentListViewService.displayFields = customFields as any
|
||||||
expect(documentListViewService.displayFields).toEqual(['custom_field_1'])
|
expect(documentListViewService.displayFields).toEqual(['custom_field_1'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should generate quick filter URL with filter rules', () => {
|
||||||
|
const routerSpy = jest.spyOn(router, 'createUrlTree')
|
||||||
|
const urlTree = documentListViewService.getQuickFilterUrl(filterRules)
|
||||||
|
expect(routerSpy).toHaveBeenCalledWith(['/documents'], {
|
||||||
|
queryParams: expect.objectContaining({
|
||||||
|
tags__id__all: tags__id__all,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
expect(urlTree).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should generate quick filter URL preserving default state', () => {
|
||||||
|
documentListViewService.reload()
|
||||||
|
httpTestingController.expectOne(
|
||||||
|
`${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true`
|
||||||
|
)
|
||||||
|
const urlTree = documentListViewService.getQuickFilterUrl(filterRules)
|
||||||
|
expect(urlTree).toBeDefined()
|
||||||
|
expect(router.createUrlTree).toBeDefined()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable, inject } from '@angular/core'
|
import { Injectable, inject } from '@angular/core'
|
||||||
import { ParamMap, Router } from '@angular/router'
|
import { ParamMap, Router, UrlTree } from '@angular/router'
|
||||||
import { Observable, Subject, first, takeUntil } from 'rxjs'
|
import { Observable, Subject, first, takeUntil } from 'rxjs'
|
||||||
import {
|
import {
|
||||||
DEFAULT_DISPLAY_FIELDS,
|
DEFAULT_DISPLAY_FIELDS,
|
||||||
@@ -483,6 +483,18 @@ export class DocumentListViewService {
|
|||||||
this.router.navigate(['documents'])
|
this.router.navigate(['documents'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getQuickFilterUrl(filterRules: FilterRule[]): UrlTree {
|
||||||
|
const defaultState = {
|
||||||
|
...this.defaultListViewState(),
|
||||||
|
...(this.listViewStates.get(null) ?? {}),
|
||||||
|
filterRules,
|
||||||
|
}
|
||||||
|
const params = paramsFromViewState(defaultState)
|
||||||
|
return this.router.createUrlTree(['/documents'], {
|
||||||
|
queryParams: params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
getLastPage(): number {
|
getLastPage(): number {
|
||||||
return Math.ceil(this.collectionSize / this.pageSize)
|
return Math.ceil(this.collectionSize / this.pageSize)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user