From 6e1918a42540588a57cd336cf4ea4419d4766d88 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Fri, 20 Jun 2025 11:35:54 -0700
Subject: [PATCH] Add setting, trigger global refresh when needed
---
.../admin/settings/settings.component.html | 1 +
.../admin/settings/settings.component.spec.ts | 2 +-
.../components/admin/settings/settings.component.ts | 13 ++++++++++++-
.../components/app-frame/app-frame.component.html | 4 ++--
.../app/components/app-frame/app-frame.component.ts | 8 +++++---
.../document-detail/document-detail.component.ts | 6 +++++-
.../bulk-editor/bulk-editor.component.ts | 5 ++++-
src-ui/src/app/data/ui-settings.ts | 7 +++++++
.../app/services/rest/saved-view.service.spec.ts | 2 +-
src-ui/src/app/services/rest/saved-view.service.ts | 12 +++++++++---
10 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/src-ui/src/app/components/admin/settings/settings.component.html b/src-ui/src/app/components/admin/settings/settings.component.html
index 9d235a0f3..ccd3cc7e3 100644
--- a/src-ui/src/app/components/admin/settings/settings.component.html
+++ b/src-ui/src/app/components/admin/settings/settings.component.html
@@ -176,6 +176,7 @@
diff --git a/src-ui/src/app/components/admin/settings/settings.component.spec.ts b/src-ui/src/app/components/admin/settings/settings.component.spec.ts
index c6eeaf896..2e6170f78 100644
--- a/src-ui/src/app/components/admin/settings/settings.component.spec.ts
+++ b/src-ui/src/app/components/admin/settings/settings.component.spec.ts
@@ -212,7 +212,7 @@ describe('SettingsComponent', () => {
expect(toastErrorSpy).toHaveBeenCalled()
expect(storeSpy).toHaveBeenCalled()
expect(appearanceSettingsSpy).not.toHaveBeenCalled()
- expect(setSpy).toHaveBeenCalledTimes(29)
+ expect(setSpy).toHaveBeenCalledTimes(30)
// succeed
storeSpy.mockReturnValueOnce(of(true))
diff --git a/src-ui/src/app/components/admin/settings/settings.component.ts b/src-ui/src/app/components/admin/settings/settings.component.ts
index 8737be160..fef27bd1e 100644
--- a/src-ui/src/app/components/admin/settings/settings.component.ts
+++ b/src-ui/src/app/components/admin/settings/settings.component.ts
@@ -49,6 +49,7 @@ import {
PermissionsService,
} from 'src/app/services/permissions.service'
import { GroupService } from 'src/app/services/rest/group.service'
+import { SavedViewService } from 'src/app/services/rest/saved-view.service'
import { UserService } from 'src/app/services/rest/user.service'
import {
LanguageOption,
@@ -138,6 +139,7 @@ export class SettingsComponent
notificationsConsumerSuppressOnDashboard: new FormControl(null),
savedViewsWarnOnUnsavedChange: new FormControl(null),
+ sidebarViewsShowCount: new FormControl(null),
})
SettingsNavIDs = SettingsNavIDs
@@ -192,11 +194,13 @@ export class SettingsComponent
private router: Router,
public permissionsService: PermissionsService,
private modalService: NgbModal,
- private systemStatusService: SystemStatusService
+ private systemStatusService: SystemStatusService,
+ private savedViewsService: SavedViewService
) {
super()
this.settings.settingsSaved.subscribe(() => {
if (!this.savePending) this.initialize()
+ this.savedViewsService.maybeRefreshDocumentCounts()
})
}
@@ -308,6 +312,9 @@ export class SettingsComponent
savedViewsWarnOnUnsavedChange: this.settings.get(
SETTINGS_KEYS.SAVED_VIEWS_WARN_ON_UNSAVED_CHANGE
),
+ sidebarViewsShowCount: this.settings.get(
+ SETTINGS_KEYS.SIDEBAR_VIEWS_SHOW_COUNT
+ ),
defaultPermsOwner: this.settings.get(SETTINGS_KEYS.DEFAULT_PERMS_OWNER),
defaultPermsViewUsers: this.settings.get(
SETTINGS_KEYS.DEFAULT_PERMS_VIEW_USERS
@@ -485,6 +492,10 @@ export class SettingsComponent
SETTINGS_KEYS.SAVED_VIEWS_WARN_ON_UNSAVED_CHANGE,
this.settingsForm.value.savedViewsWarnOnUnsavedChange
)
+ this.settings.set(
+ SETTINGS_KEYS.SIDEBAR_VIEWS_SHOW_COUNT,
+ this.settingsForm.value.sidebarViewsShowCount
+ )
this.settings.set(
SETTINGS_KEYS.DEFAULT_PERMS_OWNER,
this.settingsForm.value.defaultPermsOwner
diff --git a/src-ui/src/app/components/app-frame/app-frame.component.html b/src-ui/src/app/components/app-frame/app-frame.component.html
index aab547dd4..abf47d459 100644
--- a/src-ui/src/app/components/app-frame/app-frame.component.html
+++ b/src-ui/src/app/components/app-frame/app-frame.component.html
@@ -113,11 +113,11 @@
[disablePopover]="!slimSidebarEnabled" placement="end" container="body" triggers="mouseenter:mouseleave"
popoverClass="popover-slim">
{{view.name}}
- @if (!slimSidebarEnabled) {
+ @if (showSidebarCounts && !slimSidebarEnabled) {
{{ savedViewService.getDocumentCount(view) }}
}
- @if (slimSidebarEnabled) {
+ @if (showSidebarCounts && slimSidebarEnabled) {
{{ savedViewService.getDocumentCount(view) }}
}
diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts
index 11ed3a564..c6a48b646 100644
--- a/src-ui/src/app/components/app-frame/app-frame.component.ts
+++ b/src-ui/src/app/components/app-frame/app-frame.component.ts
@@ -104,9 +104,7 @@ export class AppFrameComponent
)
) {
this.savedViewService.reload(() => {
- this.savedViewService.getDocumentCounts(
- this.savedViewService.sidebarViews
- )
+ this.savedViewService.maybeRefreshDocumentCounts()
})
}
}
@@ -288,4 +286,8 @@ export class AppFrameComponent
onLogout() {
this.openDocumentsService.closeAll()
}
+
+ get showSidebarCounts(): boolean {
+ return this.settingsService.get(SETTINGS_KEYS.SIDEBAR_VIEWS_SHOW_COUNT)
+ }
}
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts
index 1bfac60f0..8e100fa7a 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.ts
+++ b/src-ui/src/app/components/document-detail/document-detail.component.ts
@@ -73,6 +73,7 @@ import { CorrespondentService } from 'src/app/services/rest/correspondent.servic
import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
import { DocumentService } from 'src/app/services/rest/document.service'
+import { SavedViewService } from 'src/app/services/rest/saved-view.service'
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
import { UserService } from 'src/app/services/rest/user.service'
import { SettingsService } from 'src/app/services/settings.service'
@@ -278,7 +279,8 @@ export class DocumentDetailComponent
private http: HttpClient,
private hotKeyService: HotKeyService,
private componentRouterService: ComponentRouterService,
- private deviceDetectorService: DeviceDetectorService
+ private deviceDetectorService: DeviceDetectorService,
+ private savedViewService: SavedViewService
) {
super()
}
@@ -845,6 +847,7 @@ export class DocumentDetailComponent
} else {
this.openDocumentService.refreshDocument(this.documentId)
}
+ this.savedViewService.maybeRefreshDocumentCounts()
},
error: (error) => {
this.networkActive = false
@@ -1192,6 +1195,7 @@ export class DocumentDetailComponent
notesUpdated(notes: DocumentNote[]) {
this.document.notes = notes
this.openDocumentService.refreshDocument(this.documentId)
+ this.savedViewService.maybeRefreshDocumentCounts()
}
get userIsOwner(): boolean {
diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts
index bf6d06cd4..30fbb4b1c 100644
--- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts
+++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts
@@ -32,6 +32,7 @@ import {
DocumentService,
SelectionDataItem,
} from 'src/app/services/rest/document.service'
+import { SavedViewService } from 'src/app/services/rest/saved-view.service'
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
import { TagService } from 'src/app/services/rest/tag.service'
import { SettingsService } from 'src/app/services/settings.service'
@@ -106,7 +107,8 @@ export class BulkEditorComponent
private toastService: ToastService,
private storagePathService: StoragePathService,
private customFieldService: CustomFieldsService,
- private permissionService: PermissionsService
+ private permissionService: PermissionsService,
+ public savedViewService: SavedViewService
) {
super()
}
@@ -274,6 +276,7 @@ export class BulkEditorComponent
this.list.selected.forEach((id) => {
this.openDocumentService.refreshDocument(id)
})
+ this.savedViewService.maybeRefreshDocumentCounts()
if (modal) {
modal.close()
}
diff --git a/src-ui/src/app/data/ui-settings.ts b/src-ui/src/app/data/ui-settings.ts
index e3cdeabae..6ace74810 100644
--- a/src-ui/src/app/data/ui-settings.ts
+++ b/src-ui/src/app/data/ui-settings.ts
@@ -58,6 +58,8 @@ export const SETTINGS_KEYS = {
'general-settings:saved-views:dashboard-views-sort-order',
SIDEBAR_VIEWS_SORT_ORDER:
'general-settings:saved-views:sidebar-views-sort-order',
+ SIDEBAR_VIEWS_SHOW_COUNT:
+ 'general-settings:saved-views:sidebar-views-show-count',
TOUR_COMPLETE: 'general-settings:tour-complete',
DEFAULT_PERMS_OWNER: 'general-settings:permissions:default-owner',
DEFAULT_PERMS_VIEW_USERS: 'general-settings:permissions:default-view-users',
@@ -227,6 +229,11 @@ export const SETTINGS: UiSetting[] = [
type: 'array',
default: [],
},
+ {
+ key: SETTINGS_KEYS.SIDEBAR_VIEWS_SHOW_COUNT,
+ type: 'boolean',
+ default: true,
+ },
{
key: SETTINGS_KEYS.APP_LOGO,
type: 'string',
diff --git a/src-ui/src/app/services/rest/saved-view.service.spec.ts b/src-ui/src/app/services/rest/saved-view.service.spec.ts
index d3e1a913e..6419f277c 100644
--- a/src-ui/src/app/services/rest/saved-view.service.spec.ts
+++ b/src-ui/src/app/services/rest/saved-view.service.spec.ts
@@ -235,7 +235,7 @@ describe(`Additional service tests for SavedViewService`, () => {
})
it('should support getting document counts for views', () => {
- service.getDocumentCounts(saved_views)
+ service.maybeRefreshDocumentCounts(saved_views)
saved_views.forEach((saved_view) => {
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}documents/?page=1&page_size=1&ordering=-${saved_view.sort_field}&fields=id&truncate_content=true`
diff --git a/src-ui/src/app/services/rest/saved-view.service.ts b/src-ui/src/app/services/rest/saved-view.service.ts
index 30fd73c17..d37ae7849 100644
--- a/src-ui/src/app/services/rest/saved-view.service.ts
+++ b/src-ui/src/app/services/rest/saved-view.service.ts
@@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
-import { combineLatest, Observable } from 'rxjs'
-import { tap } from 'rxjs/operators'
+import { combineLatest, Observable, Subject } from 'rxjs'
+import { takeUntil, tap } from 'rxjs/operators'
import { Results } from 'src/app/data/results'
import { SavedView } from 'src/app/data/saved-view'
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
@@ -16,6 +16,7 @@ export class SavedViewService extends AbstractPaperlessService {
public loading: boolean = true
private savedViews: SavedView[] = []
private savedViewDocumentCounts: Map = new Map()
+ private unsubscribeNotifier: Subject = new Subject()
constructor(
protected http: HttpClient,
@@ -121,7 +122,11 @@ export class SavedViewService extends AbstractPaperlessService {
return super.delete(o).pipe(tap(() => this.reload()))
}
- getDocumentCounts(views: SavedView[]) {
+ public maybeRefreshDocumentCounts(views: SavedView[] = this.sidebarViews) {
+ if (!this.settingsService.get(SETTINGS_KEYS.SIDEBAR_VIEWS_SHOW_COUNT)) {
+ return
+ }
+ this.unsubscribeNotifier.next() // clear previous subscriptions
views.forEach((view) => {
this.documentService
.listFiltered(
@@ -132,6 +137,7 @@ export class SavedViewService extends AbstractPaperlessService {
view.filter_rules,
{ fields: 'id', truncate_content: true }
)
+ .pipe(takeUntil(this.unsubscribeNotifier))
.subscribe((results: Results) => {
this.savedViewDocumentCounts.set(view.id, results.count)
})