mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-06 14:59:22 +00:00
Fixhancement: rework saved view widget queue processing to expected (#14699)
* activateSavedViewWithDocuments, move most of loadSavedView to a helper * Consolidate the page size thing * Pass widget's documents to list service fpr next / previous * Tests for the page size + widget click * Fix close from a dashboard widget list
This commit is contained in:
1 parent
e88303cc16
commit
c5239f9f74
8 files changed
+150
-13
No files matched your search
@@ -386,6 +386,46 @@ describe('DocumentListViewService', () => {
|
||||
documentListViewService.activateSavedView(null)
|
||||
})
|
||||
|
||||
it('should support activating saved view with pre-fetched documents', () => {
|
||||
const routerSpy = jest.spyOn(router, 'navigate')
|
||||
routerSpy.mockClear()
|
||||
documentListViewService.activateSavedViewWithDocuments(
|
||||
view,
|
||||
documents.slice(0, 2),
|
||||
documents.length,
|
||||
2
|
||||
)
|
||||
// no navigation, no reload
|
||||
expect(routerSpy).not.toHaveBeenCalled()
|
||||
httpTestingController.expectNone(
|
||||
(req) => req.url === `${environment.apiBaseUrl}documents/`
|
||||
)
|
||||
expect(documentListViewService.activeSavedViewId).toEqual(view.id)
|
||||
expect(documentListViewService.activeSavedViewTitle).toEqual(view.name)
|
||||
expect(documentListViewService.documents).toEqual(documents.slice(0, 2))
|
||||
expect(documentListViewService.collectionSize).toEqual(documents.length)
|
||||
expect(documentListViewService.currentPage).toEqual(1)
|
||||
expect(documentListViewService.pageSize).toEqual(2)
|
||||
expect(documentListViewService.hasNext(documents[0].id)).toBeTruthy()
|
||||
|
||||
let nextDocId: number
|
||||
documentListViewService
|
||||
.getNext(documents[1].id)
|
||||
.subscribe((docId) => (nextDocId = docId))
|
||||
// crossing the page uses the view's sort + filters and the given page size
|
||||
// (the currentPage setter reloads too, so the first request is cancelled)
|
||||
const reqs = httpTestingController.match(
|
||||
`${environment.apiBaseUrl}documents/?page=2&page_size=2&ordering=-added&truncate_content=true&include_selection_data=true&tags__id__all=${tags__id__all}`
|
||||
)
|
||||
expect(reqs.length).toBeGreaterThan(0)
|
||||
reqs[reqs.length - 1].flush({
|
||||
count: documents.length,
|
||||
results: documents.slice(2, 4),
|
||||
})
|
||||
expect(nextDocId).toEqual(documents[2].id)
|
||||
documentListViewService.activateSavedView(null)
|
||||
})
|
||||
|
||||
it('should support navigating next / previous', () => {
|
||||
documentListViewService.setFilterRules([])
|
||||
let req = httpTestingController.expectOne(
|
||||
|
||||
@@ -270,11 +270,28 @@ export class DocumentListViewService {
|
||||
this.currentPage = viewState.currentPage
|
||||
}
|
||||
|
||||
loadSavedView(view: SavedView, closeCurrentView: boolean = false) {
|
||||
if (closeCurrentView) {
|
||||
this._activeSavedViewId = null
|
||||
}
|
||||
/**
|
||||
* Activate a saved view using documents that were already fetched, e.g. by a
|
||||
* dashboard widget. Does not navigate or reload.
|
||||
*/
|
||||
activateSavedViewWithDocuments(
|
||||
view: SavedView,
|
||||
documents: Document[],
|
||||
collectionSize: number,
|
||||
pageSize: number
|
||||
) {
|
||||
this.cancelPending()
|
||||
this.rangeSelectionAnchorIndex = this.lastRangeSelectionToIndex = null
|
||||
this._activeSavedViewId = view.id
|
||||
this.applySavedViewConfig(view)
|
||||
this.activeListViewState.pageSize = pageSize // match the page size the documents were fetched with
|
||||
this.activeListViewState.currentPage = 1
|
||||
this.activeListViewState.documents = documents
|
||||
this.activeListViewState.collectionSize = collectionSize
|
||||
this.markChanged()
|
||||
}
|
||||
|
||||
private applySavedViewConfig(view: SavedView) {
|
||||
this.activeListViewState.filterRules = cloneFilterRules(view.filter_rules)
|
||||
this.activeListViewState.sortField = view.sort_field
|
||||
this.activeListViewState.sortReverse = view.sort_reverse
|
||||
@@ -284,6 +301,14 @@ export class DocumentListViewService {
|
||||
this.activeListViewState.displayMode = view.display_mode
|
||||
this.activeListViewState.pageSize = view.page_size
|
||||
this.activeListViewState.displayFields = view.display_fields
|
||||
}
|
||||
|
||||
loadSavedView(view: SavedView, closeCurrentView: boolean = false) {
|
||||
if (closeCurrentView) {
|
||||
this._activeSavedViewId = null
|
||||
}
|
||||
|
||||
this.applySavedViewConfig(view)
|
||||
|
||||
this.reduceSelectionToFilter()
|
||||
this.markChanged()
|
||||
|
||||
Reference in new issue
Block a user