Fix pagination
This commit is contained in:
parent
413320674b
commit
ecee3ae477
@ -18,7 +18,7 @@ info="Manage trashed items."
|
||||
</pngx-page-header>
|
||||
|
||||
<div class="row mb-3">
|
||||
<ngb-pagination class="col-auto" [pageSize]="25" [collectionSize]="documentsInTrash.length" [(page)]="page" [maxSize]="5" (pageChange)="reload()" size="sm" aria-label="Pagination"></ngb-pagination>
|
||||
<ngb-pagination class="col-auto" [pageSize]="25" [collectionSize]="totalDocuments" [(page)]="page" [maxSize]="5" (pageChange)="reload()" size="sm" aria-label="Pagination"></ngb-pagination>
|
||||
</div>
|
||||
|
||||
<div class="card border table-responsive mb-3">
|
||||
@ -85,13 +85,13 @@ info="Manage trashed items."
|
||||
@if (!isLoading) {
|
||||
<div class="d-flex mb-2">
|
||||
<div>
|
||||
<ng-container i18n>{documentsInTrash.length, plural, =1 {One object in trash} other {{{documentsInTrash.length || 0}} total documents in trash}}</ng-container>
|
||||
<ng-container i18n>{totalDocuments, plural, =1 {One object in trash} other {{{totalDocuments || 0}} total documents in trash}}</ng-container>
|
||||
@if (selectedDocuments.size > 0) {
|
||||
({{selectedDocuments.size}} selected)
|
||||
({{selectedDocuments.size}} selected)
|
||||
}
|
||||
</div>
|
||||
@if (documentsInTrash.length > 20) {
|
||||
<ngb-pagination class="ms-auto" [pageSize]="25" [collectionSize]="documentsInTrash.length" [(page)]="page" [maxSize]="5" (pageChange)="reload()" size="sm" aria-label="Pagination"></ngb-pagination>
|
||||
<ngb-pagination class="ms-auto" [pageSize]="25" [collectionSize]="totalDocuments" [(page)]="page" [maxSize]="5" (pageChange)="reload()" size="sm" aria-label="Pagination"></ngb-pagination>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
@ -62,7 +62,13 @@ describe('TrashComponent', () => {
|
||||
|
||||
it('should call correct service method on reload', () => {
|
||||
const trashSpy = jest.spyOn(trashService, 'getTrash')
|
||||
trashSpy.mockReturnValue(of(documentsInTrash))
|
||||
trashSpy.mockReturnValue(
|
||||
of({
|
||||
count: 2,
|
||||
all: documentsInTrash.map((d) => d.id),
|
||||
results: documentsInTrash,
|
||||
})
|
||||
)
|
||||
component.reload()
|
||||
expect(trashSpy).toHaveBeenCalled()
|
||||
expect(component.documentsInTrash).toEqual(documentsInTrash)
|
||||
|
@ -18,6 +18,7 @@ export class TrashComponent implements OnDestroy {
|
||||
public selectedDocuments: Set<number> = new Set()
|
||||
public allToggled: boolean = false
|
||||
public page: number = 1
|
||||
public totalDocuments: number
|
||||
public isLoading: boolean = false
|
||||
unsubscribeNotifier: Subject<void> = new Subject()
|
||||
|
||||
@ -37,8 +38,9 @@ export class TrashComponent implements OnDestroy {
|
||||
|
||||
reload() {
|
||||
this.isLoading = true
|
||||
this.trashService.getTrash().subscribe((documentsInTrash) => {
|
||||
this.documentsInTrash = documentsInTrash
|
||||
this.trashService.getTrash(this.page).subscribe((r) => {
|
||||
this.documentsInTrash = r.results
|
||||
this.totalDocuments = r.count
|
||||
this.isLoading = false
|
||||
this.selectedDocuments.clear()
|
||||
})
|
||||
|
@ -22,7 +22,7 @@ describe('TrashServiceService', () => {
|
||||
it('should call correct endpoint for getTrash', () => {
|
||||
service.getTrash().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}trash/`
|
||||
`${environment.apiBaseUrl}trash/?page=1`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { Document } from '../data/document'
|
||||
import { Results } from '../data/results'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -10,8 +11,11 @@ import { Document } from '../data/document'
|
||||
export class TrashService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
public getTrash(): Observable<Document[]> {
|
||||
return this.http.get<Document[]>(`${environment.apiBaseUrl}trash/`)
|
||||
public getTrash(page: number = 1): Observable<Results<Document>> {
|
||||
const httpParams = new HttpParams().set('page', page.toString())
|
||||
return this.http.get<Results<Document>>(`${environment.apiBaseUrl}trash/`, {
|
||||
params: httpParams,
|
||||
})
|
||||
}
|
||||
|
||||
public emptyTrash(documents: number[] = []): Observable<any> {
|
||||
|
@ -2056,24 +2056,19 @@ class SystemStatusView(PassUserMixin):
|
||||
)
|
||||
|
||||
|
||||
class TrashView(PassUserMixin):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
class TrashView(ListModelMixin, PassUserMixin):
|
||||
permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
|
||||
serializer_class = TrashSerializer
|
||||
filter_backends = (ObjectOwnedOrGrantedPermissionsFilter,)
|
||||
pagination_class = StandardPagination
|
||||
|
||||
model = Document
|
||||
|
||||
queryset = Document.deleted_objects.all()
|
||||
|
||||
def get(self, request, format=None):
|
||||
user = self.request.user
|
||||
documents = Document.deleted_objects.filter(
|
||||
owner=user,
|
||||
) | Document.deleted_objects.filter(
|
||||
owner=None,
|
||||
)
|
||||
|
||||
context = {
|
||||
"request": request,
|
||||
}
|
||||
|
||||
serializer = DocumentSerializer(documents, many=True, context=context)
|
||||
return Response(serializer.data)
|
||||
self.serializer_class = DocumentSerializer
|
||||
return self.list(request, format)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user