Crude send only changed fields

This commit is contained in:
shamoon 2025-03-26 08:59:50 -07:00
parent 87427a60a8
commit ec5a63cbef
No known key found for this signature in database
3 changed files with 30 additions and 8 deletions

View File

@ -793,11 +793,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
.patch(this.document)
.patch(this.getChangedFields())
.pipe(first())
.subscribe({
next: (docValues) => {
@ -851,7 +870,7 @@ export class DocumentDetailComponent
this.networkActive = true
this.store.next(this.documentForm.value)
this.documentsService
.patch(this.document)
.patch(this.getChangedFields())
.pipe(
switchMap((updateResult) => {
return this.documentListViewService
@ -1304,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) {
@ -1312,6 +1333,7 @@ export class DocumentDetailComponent
1
)
this.updateFormForCustomFields(true)
this.documentForm.get('custom_fields').markAsDirty()
this.documentForm.updateValueAndValidity()
}

View File

@ -268,15 +268,15 @@ describe(`DocumentService`, () => {
expect(req.request.method).toEqual('GET')
})
it('should pass remove_inbox_tags setting to update', () => {
subscription = service.update(documents[0]).subscribe()
it('should pass remove_inbox_tags setting to patch', () => {
subscription = service.patch(documents[0]).subscribe()
let req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/`
)
expect(req.request.body.remove_inbox_tags).toEqual(false)
settingsService.set(SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS, true)
subscription = service.update(documents[0]).subscribe()
subscription = service.patch(documents[0]).subscribe()
req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/`
)

View File

@ -189,13 +189,13 @@ export class DocumentService extends AbstractPaperlessService<Document> {
return this.http.get<number>(this.getResourceUrl(null, 'next_asn'))
}
update(o: Document): Observable<Document> {
patch(o: Document): Observable<Document> {
// we want to only set created_date
o.created = undefined
delete o.created
o.remove_inbox_tags = !!this.settingsService.get(
SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS
)
return super.update(o)
return super.patch(o)
}
uploadDocument(formData) {