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