mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-22 00:49:35 -06:00
Add to dialog
This commit is contained in:
@@ -553,12 +553,35 @@ describe('DocumentListComponent', () => {
|
||||
component.saveViewConfigAs()
|
||||
|
||||
const modalCloseSpy = jest.spyOn(openModal, 'close')
|
||||
const permissions = {
|
||||
owner: 5,
|
||||
set_permissions: {
|
||||
view: {
|
||||
users: [4],
|
||||
groups: [3],
|
||||
},
|
||||
change: {
|
||||
users: [2],
|
||||
groups: [1],
|
||||
},
|
||||
},
|
||||
}
|
||||
openModal.componentInstance.saveClicked.next({
|
||||
name: 'Foo Bar',
|
||||
show_on_dashboard: true,
|
||||
show_in_sidebar: true,
|
||||
showOnDashboard: true,
|
||||
showInSideBar: true,
|
||||
permissions_form: permissions,
|
||||
})
|
||||
expect(savedViewServiceCreate).toHaveBeenCalled()
|
||||
expect(savedViewServiceCreate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
name: 'Foo Bar',
|
||||
show_on_dashboard: true,
|
||||
show_in_sidebar: true,
|
||||
owner: permissions.owner,
|
||||
set_permissions: permissions.set_permissions,
|
||||
})
|
||||
)
|
||||
expect(modalSpy).toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalled()
|
||||
expect(modalCloseSpy).toHaveBeenCalled()
|
||||
@@ -604,8 +627,8 @@ describe('DocumentListComponent', () => {
|
||||
|
||||
openModal.componentInstance.saveClicked.next({
|
||||
name: 'Foo Bar',
|
||||
show_on_dashboard: true,
|
||||
show_in_sidebar: true,
|
||||
showOnDashboard: true,
|
||||
showInSideBar: true,
|
||||
})
|
||||
expect(openModal.componentInstance.error).toEqual({ filter_rules: ['11'] })
|
||||
})
|
||||
|
||||
@@ -454,6 +454,15 @@ export class DocumentListComponent
|
||||
display_mode: this.list.displayMode,
|
||||
display_fields: this.activeDisplayFields,
|
||||
}
|
||||
const permissions = formValue.permissions_form
|
||||
if (permissions) {
|
||||
if (permissions.owner !== null && permissions.owner !== undefined) {
|
||||
savedView.owner = permissions.owner
|
||||
}
|
||||
if (permissions.set_permissions) {
|
||||
savedView['set_permissions'] = permissions.set_permissions
|
||||
}
|
||||
}
|
||||
|
||||
this.savedViewService
|
||||
.create(savedView)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<pngx-input-text i18n-title title="Name" formControlName="name" [error]="error?.name" autocomplete="off"></pngx-input-text>
|
||||
<pngx-input-check i18n-title title="Show in sidebar" formControlName="showInSideBar"></pngx-input-check>
|
||||
<pngx-input-check i18n-title title="Show on dashboard" formControlName="showOnDashboard"></pngx-input-check>
|
||||
<pngx-permissions-form [users]="users" accordion="true" formControlName="permissions_form"></pngx-permissions-form>
|
||||
@if (error?.filter_rules) {
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<h6 class="alert-heading" i18n>Filter rules error occurred while saving this view</h6>
|
||||
|
||||
@@ -7,7 +7,13 @@ import {
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||
import { By } from '@angular/platform-browser'
|
||||
import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { of } from 'rxjs'
|
||||
import { GroupService } from 'src/app/services/rest/group.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
import { CheckComponent } from '../../common/input/check/check.component'
|
||||
import { PermissionsFormComponent } from '../../common/input/permissions/permissions-form/permissions-form.component'
|
||||
import { PermissionsGroupComponent } from '../../common/input/permissions/permissions-group/permissions-group.component'
|
||||
import { PermissionsUserComponent } from '../../common/input/permissions/permissions-user/permissions-user.component'
|
||||
import { TextComponent } from '../../common/input/text/text.component'
|
||||
import { SaveViewConfigDialogComponent } from './save-view-config-dialog.component'
|
||||
|
||||
@@ -18,7 +24,21 @@ describe('SaveViewConfigDialogComponent', () => {
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [NgbActiveModal],
|
||||
providers: [
|
||||
NgbActiveModal,
|
||||
{
|
||||
provide: UserService,
|
||||
useValue: {
|
||||
listAll: () => of({ results: [] }),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: GroupService,
|
||||
useValue: {
|
||||
listAll: () => of({ results: [] }),
|
||||
},
|
||||
},
|
||||
],
|
||||
imports: [
|
||||
NgbModalModule,
|
||||
FormsModule,
|
||||
@@ -26,6 +46,9 @@ describe('SaveViewConfigDialogComponent', () => {
|
||||
SaveViewConfigDialogComponent,
|
||||
TextComponent,
|
||||
CheckComponent,
|
||||
PermissionsFormComponent,
|
||||
PermissionsUserComponent,
|
||||
PermissionsGroupComponent,
|
||||
],
|
||||
}).compileComponents()
|
||||
|
||||
@@ -81,6 +104,26 @@ describe('SaveViewConfigDialogComponent', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should support permissions input', () => {
|
||||
const permissions = {
|
||||
owner: 10,
|
||||
set_permissions: {
|
||||
view: { users: [2], groups: [3] },
|
||||
change: { users: [4], groups: [5] },
|
||||
},
|
||||
}
|
||||
let result
|
||||
component.saveClicked.subscribe((saveResult) => (result = saveResult))
|
||||
component.saveViewConfigForm.get('permissions_form').patchValue(permissions)
|
||||
component.save()
|
||||
expect(result).toEqual({
|
||||
name: '',
|
||||
showInSideBar: false,
|
||||
showOnDashboard: false,
|
||||
permissions_form: permissions,
|
||||
})
|
||||
})
|
||||
|
||||
it('should support default name', () => {
|
||||
const saveClickedSpy = jest.spyOn(component.saveClicked, 'emit')
|
||||
const modalCloseSpy = jest.spyOn(modal, 'close')
|
||||
|
||||
@@ -13,17 +13,27 @@ import {
|
||||
ReactiveFormsModule,
|
||||
} from '@angular/forms'
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { User } from 'src/app/data/user'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
import { CheckComponent } from '../../common/input/check/check.component'
|
||||
import { PermissionsFormComponent } from '../../common/input/permissions/permissions-form/permissions-form.component'
|
||||
import { TextComponent } from '../../common/input/text/text.component'
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-save-view-config-dialog',
|
||||
templateUrl: './save-view-config-dialog.component.html',
|
||||
styleUrls: ['./save-view-config-dialog.component.scss'],
|
||||
imports: [CheckComponent, TextComponent, FormsModule, ReactiveFormsModule],
|
||||
imports: [
|
||||
CheckComponent,
|
||||
TextComponent,
|
||||
PermissionsFormComponent,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
})
|
||||
export class SaveViewConfigDialogComponent implements OnInit {
|
||||
private modal = inject(NgbActiveModal)
|
||||
private userService = inject(UserService)
|
||||
|
||||
@Output()
|
||||
public saveClicked = new EventEmitter()
|
||||
@@ -36,6 +46,8 @@ export class SaveViewConfigDialogComponent implements OnInit {
|
||||
|
||||
closeEnabled = false
|
||||
|
||||
users: User[]
|
||||
|
||||
_defaultName = ''
|
||||
|
||||
get defaultName() {
|
||||
@@ -52,6 +64,7 @@ export class SaveViewConfigDialogComponent implements OnInit {
|
||||
name: new FormControl(''),
|
||||
showInSideBar: new FormControl(false),
|
||||
showOnDashboard: new FormControl(false),
|
||||
permissions_form: new FormControl(null),
|
||||
})
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -59,10 +72,22 @@ export class SaveViewConfigDialogComponent implements OnInit {
|
||||
setTimeout(() => {
|
||||
this.closeEnabled = true
|
||||
})
|
||||
this.userService.listAll().subscribe((r) => {
|
||||
this.users = r.results
|
||||
})
|
||||
}
|
||||
|
||||
save() {
|
||||
this.saveClicked.emit(this.saveViewConfigForm.value)
|
||||
const formValue = this.saveViewConfigForm.value
|
||||
const saveViewConfig = {
|
||||
name: formValue.name,
|
||||
showInSideBar: formValue.showInSideBar,
|
||||
showOnDashboard: formValue.showOnDashboard,
|
||||
}
|
||||
if (formValue.permissions_form) {
|
||||
saveViewConfig['permissions_form'] = formValue.permissions_form
|
||||
}
|
||||
this.saveClicked.emit(saveViewConfig)
|
||||
}
|
||||
|
||||
cancel() {
|
||||
|
||||
Reference in New Issue
Block a user