mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
Fix: track and restore changed document fields from session storage (#10468)
This commit is contained in:
@@ -241,4 +241,15 @@ describe('OpenDocumentsService', () => {
|
||||
openDocumentsService.openDocument(doc)
|
||||
expect(consoleSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should set dirty status with changed fields', () => {
|
||||
subscriptions.push(
|
||||
openDocumentsService.openDocument(documents[0]).subscribe()
|
||||
)
|
||||
const changedFields = { title: 'foo', content: 'bar' }
|
||||
openDocumentsService.setDirty(documents[0], true, changedFields)
|
||||
expect(
|
||||
openDocumentsService.getOpenDocument(documents[0].id).__changedFields
|
||||
).toEqual(['title', 'content'])
|
||||
})
|
||||
})
|
||||
|
@@ -84,10 +84,20 @@ export class OpenDocumentsService {
|
||||
this.save()
|
||||
}
|
||||
|
||||
setDirty(doc: Document, dirty: boolean) {
|
||||
if (!this.openDocuments.find((d) => d.id == doc.id)) return
|
||||
if (dirty) this.dirtyDocuments.add(doc.id)
|
||||
else this.dirtyDocuments.delete(doc.id)
|
||||
setDirty(doc: Document, dirty: boolean, changedFields: object = {}) {
|
||||
const existingDoc = this.getOpenDocument(doc.id)
|
||||
if (!existingDoc) return
|
||||
if (dirty) {
|
||||
this.dirtyDocuments.add(doc.id)
|
||||
existingDoc.__changedFields = Object.keys(changedFields).filter(
|
||||
(key) => key !== 'id'
|
||||
)
|
||||
} else {
|
||||
this.dirtyDocuments.delete(doc.id)
|
||||
existingDoc.__changedFields = []
|
||||
}
|
||||
|
||||
this.save()
|
||||
}
|
||||
|
||||
hasDirty(): boolean {
|
||||
|
Reference in New Issue
Block a user