mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-22 00:49:35 -06:00
Use UISettings on create too
This commit is contained in:
@@ -549,6 +549,10 @@ describe('DocumentListComponent', () => {
|
|||||||
const modalSpy = jest.spyOn(modalService, 'open')
|
const modalSpy = jest.spyOn(modalService, 'open')
|
||||||
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||||
const savedViewServiceCreate = jest.spyOn(savedViewService, 'create')
|
const savedViewServiceCreate = jest.spyOn(savedViewService, 'create')
|
||||||
|
const settingsSetSpy = jest.spyOn(settingsService, 'set')
|
||||||
|
const settingsStoreSpy = jest
|
||||||
|
.spyOn(settingsService, 'storeSettings')
|
||||||
|
.mockReturnValue(of({ success: true }))
|
||||||
savedViewServiceCreate.mockReturnValueOnce(of(modifiedView))
|
savedViewServiceCreate.mockReturnValueOnce(of(modifiedView))
|
||||||
component.saveViewConfigAs()
|
component.saveViewConfigAs()
|
||||||
|
|
||||||
@@ -576,12 +580,21 @@ describe('DocumentListComponent', () => {
|
|||||||
expect(savedViewServiceCreate).toHaveBeenCalledWith(
|
expect(savedViewServiceCreate).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
name: 'Foo Bar',
|
name: 'Foo Bar',
|
||||||
show_on_dashboard: true,
|
show_on_dashboard: false,
|
||||||
show_in_sidebar: true,
|
show_in_sidebar: false,
|
||||||
owner: permissions.owner,
|
owner: permissions.owner,
|
||||||
set_permissions: permissions.set_permissions,
|
set_permissions: permissions.set_permissions,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
expect(settingsSetSpy).toHaveBeenCalledWith(
|
||||||
|
SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS,
|
||||||
|
expect.arrayContaining([modifiedView.id])
|
||||||
|
)
|
||||||
|
expect(settingsSetSpy).toHaveBeenCalledWith(
|
||||||
|
SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS,
|
||||||
|
expect.arrayContaining([modifiedView.id])
|
||||||
|
)
|
||||||
|
expect(settingsStoreSpy).toHaveBeenCalled()
|
||||||
expect(modalSpy).toHaveBeenCalled()
|
expect(modalSpy).toHaveBeenCalled()
|
||||||
expect(toastSpy).toHaveBeenCalled()
|
expect(toastSpy).toHaveBeenCalled()
|
||||||
expect(modalCloseSpy).toHaveBeenCalled()
|
expect(modalCloseSpy).toHaveBeenCalled()
|
||||||
@@ -615,6 +628,7 @@ describe('DocumentListComponent', () => {
|
|||||||
|
|
||||||
let openModal: NgbModalRef
|
let openModal: NgbModalRef
|
||||||
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
||||||
|
const settingsStoreSpy = jest.spyOn(settingsService, 'storeSettings')
|
||||||
jest.spyOn(savedViewService, 'create').mockReturnValueOnce(
|
jest.spyOn(savedViewService, 'create').mockReturnValueOnce(
|
||||||
throwError(
|
throwError(
|
||||||
() =>
|
() =>
|
||||||
@@ -630,6 +644,7 @@ describe('DocumentListComponent', () => {
|
|||||||
showOnDashboard: true,
|
showOnDashboard: true,
|
||||||
showInSideBar: true,
|
showInSideBar: true,
|
||||||
})
|
})
|
||||||
|
expect(settingsStoreSpy).not.toHaveBeenCalled()
|
||||||
expect(openModal.componentInstance.error).toEqual({ filter_rules: ['11'] })
|
expect(openModal.componentInstance.error).toEqual({ filter_rules: ['11'] })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
} from '@ng-bootstrap/ng-bootstrap'
|
} from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
|
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
|
||||||
import { TourNgBootstrap } from 'ngx-ui-tour-ng-bootstrap'
|
import { TourNgBootstrap } from 'ngx-ui-tour-ng-bootstrap'
|
||||||
import { filter, first, map, Subject, switchMap, takeUntil } from 'rxjs'
|
import { filter, first, map, of, Subject, switchMap, takeUntil } from 'rxjs'
|
||||||
import {
|
import {
|
||||||
DEFAULT_DISPLAY_FIELDS,
|
DEFAULT_DISPLAY_FIELDS,
|
||||||
DisplayField,
|
DisplayField,
|
||||||
@@ -446,8 +446,9 @@ export class DocumentListComponent
|
|||||||
modal.componentInstance.buttonsEnabled = false
|
modal.componentInstance.buttonsEnabled = false
|
||||||
let savedView: SavedView = {
|
let savedView: SavedView = {
|
||||||
name: formValue.name,
|
name: formValue.name,
|
||||||
show_on_dashboard: formValue.showOnDashboard,
|
// Visibility is in per-user UISettings.
|
||||||
show_in_sidebar: formValue.showInSideBar,
|
show_on_dashboard: false,
|
||||||
|
show_in_sidebar: false,
|
||||||
filter_rules: this.list.filterRules,
|
filter_rules: this.list.filterRules,
|
||||||
sort_reverse: this.list.sortReverse,
|
sort_reverse: this.list.sortReverse,
|
||||||
sort_field: this.list.sortField,
|
sort_field: this.list.sortField,
|
||||||
@@ -466,6 +467,14 @@ export class DocumentListComponent
|
|||||||
|
|
||||||
this.savedViewService
|
this.savedViewService
|
||||||
.create(savedView)
|
.create(savedView)
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe({
|
||||||
|
next: (createdView) => {
|
||||||
|
this.saveCreatedViewVisibility(
|
||||||
|
createdView,
|
||||||
|
formValue.showOnDashboard,
|
||||||
|
formValue.showInSideBar
|
||||||
|
)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
@@ -474,6 +483,15 @@ export class DocumentListComponent
|
|||||||
$localize`View "${savedView.name}" created successfully.`
|
$localize`View "${savedView.name}" created successfully.`
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
error: (error) => {
|
||||||
|
modal.close()
|
||||||
|
this.toastService.showError(
|
||||||
|
$localize`View "${savedView.name}" created successfully, but could not update visibility settings.`,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
error: (httpError) => {
|
error: (httpError) => {
|
||||||
let error = httpError.error
|
let error = httpError.error
|
||||||
if (error.filter_rules) {
|
if (error.filter_rules) {
|
||||||
@@ -486,6 +504,35 @@ export class DocumentListComponent
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private saveCreatedViewVisibility(
|
||||||
|
createdView: SavedView,
|
||||||
|
showOnDashboard: boolean,
|
||||||
|
showInSideBar: boolean
|
||||||
|
) {
|
||||||
|
if (!showOnDashboard && !showInSideBar) {
|
||||||
|
return of(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const dashboardViewIds = this.savedViewService.dashboardViews.map(
|
||||||
|
(v) => v.id
|
||||||
|
)
|
||||||
|
const sidebarViewIds = this.savedViewService.sidebarViews.map((v) => v.id)
|
||||||
|
if (showOnDashboard) {
|
||||||
|
dashboardViewIds.push(createdView.id)
|
||||||
|
}
|
||||||
|
if (showInSideBar) {
|
||||||
|
sidebarViewIds.push(createdView.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.settingsService.set(SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS, [
|
||||||
|
...new Set(dashboardViewIds),
|
||||||
|
])
|
||||||
|
this.settingsService.set(SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS, [
|
||||||
|
...new Set(sidebarViewIds),
|
||||||
|
])
|
||||||
|
return this.settingsService.storeSettings()
|
||||||
|
}
|
||||||
|
|
||||||
openDocumentDetail(document: Document | number) {
|
openDocumentDetail(document: Document | number) {
|
||||||
this.router.navigate([
|
this.router.navigate([
|
||||||
'documents',
|
'documents',
|
||||||
|
|||||||
Reference in New Issue
Block a user