-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skeleton user / group admin dialogs [WIP]
- Loading branch information
Showing
21 changed files
with
515 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<form [formGroup]="objectForm" (ngSubmit)="save()"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> | ||
<button type="button" [disabled]="!closeEnabled" class="btn-close" aria-label="Close" (click)="cancel()"> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="row"> | ||
<div class="col"> | ||
<app-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></app-input-text> | ||
<app-permissions-select i18n-title title="Permissions" formControlName="permissions"></app-permissions-select> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-outline-secondary" (click)="cancel()" i18n [disabled]="networkActive">Cancel</button> | ||
<button type="submit" class="btn btn-primary" i18n [disabled]="networkActive">Save</button> | ||
</div> | ||
</form> |
Empty file.
32 changes: 32 additions & 0 deletions
32
...ui/src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Component } from '@angular/core' | ||
import { FormControl, FormGroup } from '@angular/forms' | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' | ||
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component' | ||
import { PaperlessGroup } from 'src/app/data/paperless-group' | ||
import { GroupService } from 'src/app/services/rest/group.service' | ||
|
||
@Component({ | ||
selector: 'app-group-edit-dialog', | ||
templateUrl: './group-edit-dialog.component.html', | ||
styleUrls: ['./group-edit-dialog.component.scss'], | ||
}) | ||
export class GroupEditDialogComponent extends EditDialogComponent<PaperlessGroup> { | ||
constructor(service: GroupService, activeModal: NgbActiveModal) { | ||
super(service, activeModal) | ||
} | ||
|
||
getCreateTitle() { | ||
return $localize`Create new user group` | ||
} | ||
|
||
getEditTitle() { | ||
return $localize`Edit user group` | ||
} | ||
|
||
getForm(): FormGroup { | ||
return new FormGroup({ | ||
name: new FormControl(''), | ||
permissions: new FormControl(''), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<form [formGroup]="objectForm" (ngSubmit)="save()"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> | ||
<button type="button" [disabled]="!closeEnabled" class="btn-close" aria-label="Close" (click)="cancel()"> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="row"> | ||
<div class="col"> | ||
<app-input-text i18n-title title="Username" formControlName="username" [error]="error?.username"></app-input-text> | ||
<app-input-text i18n-title title="First name" formControlName="first_name" [error]="error?.first_name"></app-input-text> | ||
<app-input-text i18n-title title="Last name" formControlName="last_name" [error]="error?.first_name"></app-input-text> | ||
|
||
<div class="form-check form-switch"> | ||
<input type="checkbox" class="form-check-input" id="is_active" formControlName="is_active"> | ||
<label class="form-check-label" for="is_active" i18n>Active</label> | ||
</div> | ||
|
||
<div class="form-check form-switch"> | ||
<input type="checkbox" class="form-check-input" id="is_superuser" formControlName="is_superuser"> | ||
<label class="form-check-label" for="is_superuser" i18n>Superuser</label> | ||
</div> | ||
</div> | ||
<div class="col"> | ||
<app-input-select i18n-title title="Groups" [items]="groups" multiple="true" formControlName="groups"></app-input-select> | ||
<app-permissions-select i18n-title title="Permissions" formControlName="permissions"></app-permissions-select> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-outline-secondary" (click)="cancel()" i18n [disabled]="networkActive">Cancel</button> | ||
<button type="submit" class="btn btn-primary" i18n [disabled]="networkActive">Save</button> | ||
</div> | ||
</form> |
Empty file.
51 changes: 51 additions & 0 deletions
51
src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Component } from '@angular/core' | ||
import { FormControl, FormGroup } from '@angular/forms' | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' | ||
import { first } from 'rxjs' | ||
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component' | ||
import { PaperlessGroup } from 'src/app/data/paperless-group' | ||
import { PaperlessUser } from 'src/app/data/paperless-user' | ||
import { GroupService } from 'src/app/services/rest/group.service' | ||
import { UserService } from 'src/app/services/rest/user.service' | ||
|
||
@Component({ | ||
selector: 'app-user-edit-dialog', | ||
templateUrl: './user-edit-dialog.component.html', | ||
styleUrls: ['./user-edit-dialog.component.scss'], | ||
}) | ||
export class UserEditDialogComponent extends EditDialogComponent<PaperlessUser> { | ||
groups: PaperlessGroup[] | ||
|
||
constructor( | ||
service: UserService, | ||
activeModal: NgbActiveModal, | ||
groupsService: GroupService | ||
) { | ||
super(service, activeModal) | ||
|
||
groupsService | ||
.listAll() | ||
.pipe(first()) | ||
.subscribe((result) => (this.groups = result.results)) | ||
} | ||
|
||
getCreateTitle() { | ||
return $localize`Create new user account` | ||
} | ||
|
||
getEditTitle() { | ||
return $localize`Edit user account` | ||
} | ||
|
||
getForm(): FormGroup { | ||
return new FormGroup({ | ||
username: new FormControl(''), | ||
first_name: new FormControl(''), | ||
last_name: new FormControl(''), | ||
is_active: new FormControl(''), | ||
is_superuser: new FormControl(''), | ||
groups: new FormControl(''), | ||
permissions: new FormControl(''), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src-ui/src/app/components/common/permissions-select/permissions-select.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<form [formGroup]="form"> | ||
<label>{{title}}</label> | ||
<ul class="list-group"> | ||
<li class="list-group-item" *ngFor="let type of PermissionType | keyvalue" [formGroupName]="type.key"> | ||
{{type.key}}: | ||
|
||
<div class="form-check form-check-inline form-switch"> | ||
<input type="checkbox" class="form-check-input" id="{{type.key}}_all" formControlName="all"> | ||
<label class="form-check-label" for="{{type.key}}_all" i18n>All</label> | ||
</div> | ||
|
||
<div *ngFor="let action of PermissionAction | keyvalue" class="form-check form-check-inline" [disabled]="isAll(type.key)"> | ||
<input type="checkbox" class="form-check-input" id="{{type.key}}_{{action.key}}" formControlName="{{action.key}}"> | ||
<label class="form-check-label" for="{{type.key}}_{{action.key}}" i18n>{{action.key}}</label> | ||
</div> | ||
</li> | ||
</ul> | ||
</form> |
Empty file.
79 changes: 79 additions & 0 deletions
79
src-ui/src/app/components/common/permissions-select/permissions-select.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Component, forwardRef, Input, OnInit } from '@angular/core' | ||
import { | ||
ControlValueAccessor, | ||
FormControl, | ||
FormGroup, | ||
NG_VALUE_ACCESSOR, | ||
} from '@angular/forms' | ||
import { | ||
PermissionAction, | ||
PermissionsService, | ||
PermissionType, | ||
} from 'src/app/services/permissions.service' | ||
import { AbstractInputComponent } from '../input/abstract-input' | ||
|
||
@Component({ | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => PermissionsSelectComponent), | ||
multi: true, | ||
}, | ||
], | ||
selector: 'app-permissions-select', | ||
templateUrl: './permissions-select.component.html', | ||
styleUrls: ['./permissions-select.component.scss'], | ||
}) | ||
export class PermissionsSelectComponent | ||
implements OnInit, ControlValueAccessor | ||
{ | ||
PermissionType = PermissionType | ||
PermissionAction = PermissionAction | ||
|
||
@Input() | ||
title: string = 'Permissions' | ||
|
||
permissions: string[] | ||
|
||
form = new FormGroup({}) | ||
|
||
constructor(private readonly permissionsService: PermissionsService) { | ||
for (const type in PermissionType) { | ||
const control = new FormGroup({}) | ||
control.addControl('all', new FormControl(null)) | ||
for (const action in PermissionAction) { | ||
control.addControl(action, new FormControl(null)) | ||
} | ||
this.form.addControl(type, control) | ||
} | ||
} | ||
|
||
writeValue(permissions: string[]): void { | ||
this.permissions = permissions | ||
this.permissions.forEach((permissionStr) => { | ||
const { actionKey, typeKey } = | ||
this.permissionsService.getPermissionKeys(permissionStr) | ||
|
||
if (actionKey && typeKey) { | ||
if (this.form.get(typeKey)?.get(actionKey)) { | ||
this.form.get(typeKey).get(actionKey).setValue(true) | ||
} | ||
} | ||
}) | ||
} | ||
registerOnChange(fn: any): void { | ||
throw new Error('Method not implemented.') | ||
} | ||
registerOnTouched(fn: any): void { | ||
throw new Error('Method not implemented.') | ||
} | ||
setDisabledState?(isDisabled: boolean): void { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
ngOnInit(): void {} | ||
|
||
isAll(key: string): boolean { | ||
return this.form.get(key).get('all').value == true | ||
} | ||
} |
Oops, something went wrong.