mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-21 21:12:40 +00:00
Fix some permissions stuff, show error on toggle
This commit is contained in:
3 files changed
+36
-4
No files matched your search
@@ -288,6 +288,18 @@ export const routes: Routes = [
|
|||||||
componentName: 'OcrTemplatesComponent',
|
componentName: 'OcrTemplatesComponent',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'ocr-templates/new',
|
||||||
|
component: OcrTemplateEditorComponent,
|
||||||
|
canActivate: [PermissionsGuard],
|
||||||
|
data: {
|
||||||
|
requiredPermission: {
|
||||||
|
action: PermissionAction.Add,
|
||||||
|
type: PermissionType.OcrTemplate,
|
||||||
|
},
|
||||||
|
componentName: 'OcrTemplateEditorComponent',
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'ocr-templates/:id',
|
path: 'ocr-templates/:id',
|
||||||
component: OcrTemplateEditorComponent,
|
component: OcrTemplateEditorComponent,
|
||||||
|
|||||||
@@ -82,11 +82,20 @@
|
|||||||
<i-bs name="pencil" class="me-1"></i-bs><ng-container i18n>PDF Editor</ng-container>
|
<i-bs name="pencil" class="me-1"></i-bs><ng-container i18n>PDF Editor</ng-container>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button ngbDropdownItem (click)="runZoneOcr()" [disabled]="!userCanEdit || !document?.document_type">
|
<button
|
||||||
|
ngbDropdownItem
|
||||||
|
(click)="runZoneOcr()"
|
||||||
|
[disabled]="!userCanEdit || !document?.document_type"
|
||||||
|
*pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.OcrTemplate }"
|
||||||
|
>
|
||||||
<i-bs width="1em" height="1em" name="file-earmark-ruled" class="me-1"></i-bs><span i18n>Run Zone OCR</span>
|
<i-bs width="1em" height="1em" name="file-earmark-ruled" class="me-1"></i-bs><span i18n>Run Zone OCR</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button ngbDropdownItem (click)="createOcrTemplate()">
|
<button
|
||||||
|
ngbDropdownItem
|
||||||
|
(click)="createOcrTemplate()"
|
||||||
|
*pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.OcrTemplate }"
|
||||||
|
>
|
||||||
<i-bs width="1em" height="1em" name="file-earmark-medical" class="me-1"></i-bs><span i18n>Create OCR Template</span>
|
<i-bs width="1em" height="1em" name="file-earmark-medical" class="me-1"></i-bs><span i18n>Create OCR Template</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { IfPermissionsDirective } from 'src/app/directives/if-permissions.direct
|
|||||||
import { PermissionsService } from 'src/app/services/permissions.service'
|
import { PermissionsService } from 'src/app/services/permissions.service'
|
||||||
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
|
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
|
||||||
import { OcrTemplateService } from 'src/app/services/rest/ocr-template.service'
|
import { OcrTemplateService } from 'src/app/services/rest/ocr-template.service'
|
||||||
|
import { ToastService } from 'src/app/services/toast.service'
|
||||||
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
|
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
|
||||||
import { PageHeaderComponent } from '../../common/page-header/page-header.component'
|
import { PageHeaderComponent } from '../../common/page-header/page-header.component'
|
||||||
import { LoadingComponentWithPermissions } from '../../loading-component/loading.component'
|
import { LoadingComponentWithPermissions } from '../../loading-component/loading.component'
|
||||||
@@ -32,6 +33,7 @@ export class OcrTemplatesComponent
|
|||||||
private readonly documentTypeService = inject(DocumentTypeService)
|
private readonly documentTypeService = inject(DocumentTypeService)
|
||||||
private readonly router = inject(Router)
|
private readonly router = inject(Router)
|
||||||
private readonly modalService = inject(NgbModal)
|
private readonly modalService = inject(NgbModal)
|
||||||
|
private readonly toastService = inject(ToastService)
|
||||||
permissionsService = inject(PermissionsService)
|
permissionsService = inject(PermissionsService)
|
||||||
|
|
||||||
public templates: OcrTemplate[] = []
|
public templates: OcrTemplate[] = []
|
||||||
@@ -79,8 +81,17 @@ export class OcrTemplatesComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggleTemplate(t: OcrTemplate) {
|
toggleTemplate(t: OcrTemplate) {
|
||||||
// ngModel has already flipped t.enabled — just persist it.
|
// ngModel has already flipped t.enabled; restore it if persistence fails.
|
||||||
this.service.patch(t).subscribe()
|
const enabled = t.enabled
|
||||||
|
this.service.patch(t).subscribe({
|
||||||
|
error: (error) => {
|
||||||
|
t.enabled = !enabled
|
||||||
|
this.toastService.showError(
|
||||||
|
$localize`Error updating OCR template.`,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteTemplate(t: OcrTemplate) {
|
deleteTemplate(t: OcrTemplate) {
|
||||||
|
|||||||
Reference in new issue
Block a user