mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-24 00:59:35 -06:00
Add UIsettings for dashboard / sidebar view setting
This commit is contained in:
@@ -62,6 +62,10 @@ export const SETTINGS_KEYS = {
|
|||||||
'general-settings:update-checking:backend-setting',
|
'general-settings:update-checking:backend-setting',
|
||||||
SAVED_VIEWS_WARN_ON_UNSAVED_CHANGE:
|
SAVED_VIEWS_WARN_ON_UNSAVED_CHANGE:
|
||||||
'general-settings:saved-views:warn-on-unsaved-change',
|
'general-settings:saved-views:warn-on-unsaved-change',
|
||||||
|
DASHBOARD_VIEWS_VISIBLE_IDS:
|
||||||
|
'general-settings:saved-views:dashboard-views-visible-ids',
|
||||||
|
SIDEBAR_VIEWS_VISIBLE_IDS:
|
||||||
|
'general-settings:saved-views:sidebar-views-visible-ids',
|
||||||
DASHBOARD_VIEWS_SORT_ORDER:
|
DASHBOARD_VIEWS_SORT_ORDER:
|
||||||
'general-settings:saved-views:dashboard-views-sort-order',
|
'general-settings:saved-views:dashboard-views-sort-order',
|
||||||
SIDEBAR_VIEWS_SORT_ORDER:
|
SIDEBAR_VIEWS_SORT_ORDER:
|
||||||
@@ -248,6 +252,16 @@ export const SETTINGS: UiSetting[] = [
|
|||||||
type: 'array',
|
type: 'array',
|
||||||
default: [],
|
default: [],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS,
|
||||||
|
type: 'array',
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS,
|
||||||
|
type: 'array',
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: SETTINGS_KEYS.DASHBOARD_VIEWS_SORT_ORDER,
|
key: SETTINGS_KEYS.DASHBOARD_VIEWS_SORT_ORDER,
|
||||||
type: 'array',
|
type: 'array',
|
||||||
|
|||||||
@@ -102,6 +102,15 @@ describe(`Additional service tests for SavedViewService`, () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should use user-specific dashboard visibility when configured', () => {
|
||||||
|
service['savedViews'] = saved_views
|
||||||
|
jest.spyOn(settingsService, 'get').mockImplementation((key) => {
|
||||||
|
if (key === SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS) return [4, 2]
|
||||||
|
if (key === SETTINGS_KEYS.DASHBOARD_VIEWS_SORT_ORDER) return []
|
||||||
|
})
|
||||||
|
expect(service.dashboardViews).toEqual([saved_views[1], saved_views[3]])
|
||||||
|
})
|
||||||
|
|
||||||
it('should sort sidebar views', () => {
|
it('should sort sidebar views', () => {
|
||||||
service['savedViews'] = saved_views
|
service['savedViews'] = saved_views
|
||||||
jest.spyOn(settingsService, 'get').mockImplementation((key) => {
|
jest.spyOn(settingsService, 'get').mockImplementation((key) => {
|
||||||
@@ -114,6 +123,15 @@ describe(`Additional service tests for SavedViewService`, () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should use user-specific sidebar visibility when configured', () => {
|
||||||
|
service['savedViews'] = saved_views
|
||||||
|
jest.spyOn(settingsService, 'get').mockImplementation((key) => {
|
||||||
|
if (key === SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS) return [4, 2]
|
||||||
|
if (key === SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER) return []
|
||||||
|
})
|
||||||
|
expect(service.sidebarViews).toEqual([saved_views[1], saved_views[3]])
|
||||||
|
})
|
||||||
|
|
||||||
it('should treat empty display_fields as null', () => {
|
it('should treat empty display_fields as null', () => {
|
||||||
subscription = service
|
subscription = service
|
||||||
.patch({
|
.patch({
|
||||||
|
|||||||
@@ -65,8 +65,27 @@ export class SavedViewService extends AbstractPaperlessService<SavedView> {
|
|||||||
return this.savedViews
|
return this.savedViews
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getVisibleViewIds(setting: string): number[] | null {
|
||||||
|
const configured = this.settingsService.get(setting)
|
||||||
|
return Array.isArray(configured) ? configured : null
|
||||||
|
}
|
||||||
|
|
||||||
|
private isDashboardVisible(view: SavedView): boolean {
|
||||||
|
const visibleIds = this.getVisibleViewIds(
|
||||||
|
SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS
|
||||||
|
)
|
||||||
|
return visibleIds ? visibleIds.includes(view.id) : !!view.show_on_dashboard
|
||||||
|
}
|
||||||
|
|
||||||
|
private isSidebarVisible(view: SavedView): boolean {
|
||||||
|
const visibleIds = this.getVisibleViewIds(
|
||||||
|
SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS
|
||||||
|
)
|
||||||
|
return visibleIds ? visibleIds.includes(view.id) : !!view.show_in_sidebar
|
||||||
|
}
|
||||||
|
|
||||||
get sidebarViews(): SavedView[] {
|
get sidebarViews(): SavedView[] {
|
||||||
const sidebarViews = this.savedViews.filter((v) => v.show_in_sidebar)
|
const sidebarViews = this.savedViews.filter((v) => this.isSidebarVisible(v))
|
||||||
|
|
||||||
const sorted: number[] = this.settingsService.get(
|
const sorted: number[] = this.settingsService.get(
|
||||||
SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER
|
SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER
|
||||||
@@ -81,7 +100,9 @@ export class SavedViewService extends AbstractPaperlessService<SavedView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get dashboardViews(): SavedView[] {
|
get dashboardViews(): SavedView[] {
|
||||||
const dashboardViews = this.savedViews.filter((v) => v.show_on_dashboard)
|
const dashboardViews = this.savedViews.filter((v) =>
|
||||||
|
this.isDashboardVisible(v)
|
||||||
|
)
|
||||||
|
|
||||||
const sorted: number[] = this.settingsService.get(
|
const sorted: number[] = this.settingsService.get(
|
||||||
SETTINGS_KEYS.DASHBOARD_VIEWS_SORT_ORDER
|
SETTINGS_KEYS.DASHBOARD_VIEWS_SORT_ORDER
|
||||||
|
|||||||
Reference in New Issue
Block a user