mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-20 23:08:14 +00:00
Cleanup save now that we're modal
This commit is contained in:
2 files changed
+10
-21
No files matched your search
+7
-6
@@ -397,7 +397,7 @@ describe('OcrTemplateEditorComponent', () => {
|
||||
expect(customZone.name).toBe('New name')
|
||||
})
|
||||
|
||||
it('tracks unsaved changes against the last loaded or saved state', () => {
|
||||
it('tracks unsaved changes against the initial state', () => {
|
||||
fixture.detectChanges()
|
||||
expect(component.isDirty).toBe(false)
|
||||
|
||||
@@ -407,8 +407,7 @@ describe('OcrTemplateEditorComponent', () => {
|
||||
component.template.name = 'Invoices'
|
||||
expect(component.isDirty).toBe(true)
|
||||
|
||||
templates.create.mockReturnValue(of({ ...component.template, id: 3 }))
|
||||
component.save()
|
||||
component.template.name = ''
|
||||
expect(component.isDirty).toBe(false)
|
||||
|
||||
component.previewDocId = 5
|
||||
@@ -431,10 +430,12 @@ describe('OcrTemplateEditorComponent', () => {
|
||||
component.onOverlayPointerUp(pointer(700, 700))
|
||||
expect(component.template.zones).toHaveLength(0)
|
||||
|
||||
pending.next({ ...component.template, id: 3 })
|
||||
const saved = { ...component.template, id: 3 }
|
||||
const succeeded = jest.spyOn(component.succeeded, 'emit')
|
||||
pending.next(saved)
|
||||
pending.complete()
|
||||
expect(component.saving).toBe(false)
|
||||
expect(activeModal.close).toHaveBeenCalledWith(component.template)
|
||||
expect(succeeded).toHaveBeenCalledWith(saved)
|
||||
expect(activeModal.close).toHaveBeenCalledWith(saved)
|
||||
})
|
||||
|
||||
it('stops an active move and unlocks editing without losing changes after a failed save', () => {
|
||||
|
||||
+3
-15
@@ -272,11 +272,10 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy {
|
||||
: null
|
||||
}
|
||||
|
||||
/** Snapshot of the editor state as last loaded or saved. */
|
||||
private savedState = ''
|
||||
private initialState = ''
|
||||
|
||||
get isDirty(): boolean {
|
||||
return this.editorState() !== this.savedState
|
||||
return this.editorState() !== this.initialState
|
||||
}
|
||||
|
||||
private editorState(): string {
|
||||
@@ -290,10 +289,6 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy {
|
||||
})
|
||||
}
|
||||
|
||||
private markSaved() {
|
||||
this.savedState = this.editorState()
|
||||
}
|
||||
|
||||
get dialogTitle(): string {
|
||||
return this.isNew
|
||||
? $localize`New OCR Template`
|
||||
@@ -337,7 +332,7 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy {
|
||||
this.loadPreview()
|
||||
}
|
||||
}
|
||||
this.markSaved()
|
||||
this.initialState = this.editorState()
|
||||
}
|
||||
|
||||
searchDocuments = (text$: Observable<string>): Observable<Document[]> =>
|
||||
@@ -883,14 +878,7 @@ export class OcrTemplateEditorComponent implements OnInit, OnDestroy {
|
||||
|
||||
obs.pipe(takeUntil(this.destroy$)).subscribe({
|
||||
next: (saved) => {
|
||||
const idx = this.selectedZoneIndex
|
||||
this.template = saved
|
||||
this.isNew = false
|
||||
this.selectedZoneIndex = idx
|
||||
this.saving = false
|
||||
this.markSaved()
|
||||
this.toastService.showInfo($localize`OCR template saved.`)
|
||||
this.changeDetector.markForCheck()
|
||||
this.succeeded.emit(saved)
|
||||
this.activeModal.close(saved)
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user