mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
Enhancement: use patch instead of put for frontend document changes (#9744)
This commit is contained in:
@@ -784,6 +784,7 @@ export class DocumentDetailComponent
|
||||
this.title = doc.title
|
||||
this.updateFormForCustomFields()
|
||||
this.documentForm.patchValue(doc)
|
||||
this.documentForm.markAsPristine()
|
||||
this.openDocumentService.setDirty(doc, false)
|
||||
},
|
||||
error: () => {
|
||||
@@ -794,11 +795,30 @@ export class DocumentDetailComponent
|
||||
})
|
||||
}
|
||||
|
||||
private getChangedFields(): any {
|
||||
const changes = {
|
||||
id: this.document.id,
|
||||
}
|
||||
Object.keys(this.documentForm.controls).forEach((key) => {
|
||||
if (this.documentForm.get(key).dirty) {
|
||||
if (key === 'permissions_form') {
|
||||
changes['owner'] =
|
||||
this.documentForm.get('permissions_form').value['owner']
|
||||
changes['set_permissions'] =
|
||||
this.documentForm.get('permissions_form').value['set_permissions']
|
||||
} else {
|
||||
changes[key] = this.documentForm.get(key).value
|
||||
}
|
||||
}
|
||||
})
|
||||
return changes
|
||||
}
|
||||
|
||||
save(close: boolean = false) {
|
||||
this.networkActive = true
|
||||
;(document.activeElement as HTMLElement)?.dispatchEvent(new Event('change'))
|
||||
this.documentsService
|
||||
.update(this.document)
|
||||
.patch(this.getChangedFields())
|
||||
.pipe(first())
|
||||
.subscribe({
|
||||
next: (docValues) => {
|
||||
@@ -852,7 +872,7 @@ export class DocumentDetailComponent
|
||||
this.networkActive = true
|
||||
this.store.next(this.documentForm.value)
|
||||
this.documentsService
|
||||
.update(this.document)
|
||||
.patch(this.getChangedFields())
|
||||
.pipe(
|
||||
switchMap((updateResult) => {
|
||||
return this.documentListViewService
|
||||
@@ -1303,6 +1323,8 @@ export class DocumentDetailComponent
|
||||
created: new Date(),
|
||||
})
|
||||
this.updateFormForCustomFields(true)
|
||||
this.documentForm.get('custom_fields').markAsDirty()
|
||||
this.documentForm.updateValueAndValidity()
|
||||
}
|
||||
|
||||
public removeField(fieldInstance: CustomFieldInstance) {
|
||||
@@ -1311,6 +1333,7 @@ export class DocumentDetailComponent
|
||||
1
|
||||
)
|
||||
this.updateFormForCustomFields(true)
|
||||
this.documentForm.get('custom_fields').markAsDirty()
|
||||
this.documentForm.updateValueAndValidity()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user