</ng-template>
</li>
- <li [ngbNavItem]="SettingsNavIDs.SavedViews">
+ <li [ngbNavItem]="SettingsNavIDs.SavedViews" *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.SavedView }">
<a ngbNavLink i18n>Saved views</a>
<ng-template ngbNavContent>
{
provide: SavedViewService,
useValue: {
- initialize: () => {},
+ reload: () => {},
listAll: () =>
of({
all: [saved_views.map((v) => v.id)],
.mockReturnValue('Hello World')
jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
- savedViewSpy = jest.spyOn(savedViewService, 'initialize')
+ savedViewSpy = jest.spyOn(savedViewService, 'reload')
fixture = TestBed.createComponent(AppFrameComponent)
component = fixture.componentInstance
PermissionType.SavedView
)
) {
- this.savedViewService.initialize()
+ this.savedViewService.reload()
}
}
let settingsService
it('should retrieve saved views and sort them', () => {
- service.initialize()
+ service.reload()
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
)
})
it('should gracefully handle errors', () => {
- service.initialize()
+ service.reload()
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
)
import { AbstractPaperlessService } from './abstract-paperless-service'
import { SettingsService } from '../settings.service'
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
+import { Results } from 'src/app/data/results'
@Injectable({
providedIn: 'root',
super(http, 'saved_views')
}
- public initialize() {
- this.reload()
+ public list(
+ page?: number,
+ pageSize?: number,
+ sortField?: string,
+ sortReverse?: boolean,
+ extraParams?: any
+ ): Observable<Results<SavedView>> {
+ return super.list(page, pageSize, sortField, sortReverse, extraParams).pipe(
+ tap({
+ next: (r) => {
+ this.savedViews = r.results
+ this.loading = false
+ this.settingsService.dashboardIsEmpty =
+ this.dashboardViews.length === 0
+ },
+ error: () => {
+ this.loading = false
+ this.settingsService.dashboardIsEmpty = true
+ },
+ })
+ )
}
- private reload() {
- this.listAll().subscribe({
- next: (r) => {
- this.savedViews = r.results
- this.loading = false
- this.settingsService.dashboardIsEmpty = this.dashboardViews.length === 0
- },
- error: () => {
- this.loading = false
- this.settingsService.dashboardIsEmpty = true
- },
- })
+ public reload() {
+ this.listAll().subscribe()
}
get allViews() {