initNormally()
component.title = 'Foo Bar'
const closeSpy = jest.spyOn(component, 'close')
- const updateSpy = jest.spyOn(documentService, 'update')
+ const patchSpy = jest.spyOn(documentService, 'patch')
const toastSpy = jest.spyOn(toastService, 'showInfo')
- updateSpy.mockImplementation((o) => of(doc))
+ patchSpy.mockImplementation((o) => of(doc))
component.save(true)
- expect(updateSpy).toHaveBeenCalled()
+ expect(patchSpy).toHaveBeenCalled()
expect(closeSpy).toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalledWith(
'Document "Doc 3" saved successfully.'
initNormally()
component.title = 'Foo Bar'
const closeSpy = jest.spyOn(component, 'close')
- const updateSpy = jest.spyOn(documentService, 'update')
+ const patchSpy = jest.spyOn(documentService, 'patch')
const toastSpy = jest.spyOn(toastService, 'showInfo')
- updateSpy.mockImplementation((o) => of(doc))
+ patchSpy.mockImplementation((o) => of(doc))
component.save()
- expect(updateSpy).toHaveBeenCalled()
+ expect(patchSpy).toHaveBeenCalled()
expect(closeSpy).not.toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalledWith(
'Document "Doc 3" saved successfully.'
initNormally()
component.title = 'Foo Bar'
const closeSpy = jest.spyOn(component, 'close')
- const updateSpy = jest.spyOn(documentService, 'update')
+ const patchSpy = jest.spyOn(documentService, 'patch')
const toastSpy = jest.spyOn(toastService, 'showError')
const error = new Error('failed to save')
- updateSpy.mockImplementation(() => throwError(() => error))
+ patchSpy.mockImplementation(() => throwError(() => error))
component.save()
- expect(updateSpy).toHaveBeenCalled()
+ expect(patchSpy).toHaveBeenCalled()
expect(closeSpy).not.toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalledWith(
'Error saving document "Doc 3"',
initNormally()
component.title = 'Foo Bar'
const closeSpy = jest.spyOn(component, 'close')
- const updateSpy = jest.spyOn(documentService, 'update')
+ const patchSpy = jest.spyOn(documentService, 'patch')
const toastSpy = jest.spyOn(toastService, 'showInfo')
- updateSpy.mockImplementation(() =>
+ patchSpy.mockImplementation(() =>
throwError(() => new Error('failed to save'))
)
component.save(true)
- expect(updateSpy).toHaveBeenCalled()
+ expect(patchSpy).toHaveBeenCalled()
expect(closeSpy).toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalledWith(
'Document "Doc 3" saved successfully.'
initNormally()
const nextDocId = 100
component.title = 'Foo Bar'
- const updateSpy = jest.spyOn(documentService, 'update')
- updateSpy.mockReturnValue(of(doc))
+ const patchSpy = jest.spyOn(documentService, 'patch')
+ patchSpy.mockReturnValue(of(doc))
const nextSpy = jest.spyOn(documentListViewService, 'getNext')
nextSpy.mockReturnValue(of(nextDocId))
const closeSpy = jest.spyOn(openDocumentsService, 'closeDocument')
const navigateSpy = jest.spyOn(router, 'navigate')
component.saveEditNext()
- expect(updateSpy).toHaveBeenCalled()
+ expect(patchSpy).toHaveBeenCalled()
expect(navigateSpy).toHaveBeenCalledWith(['documents', nextDocId])
expect
})
initNormally()
component.title = 'Foo Bar'
const closeSpy = jest.spyOn(component, 'close')
- const updateSpy = jest.spyOn(documentService, 'update')
+ const patchSpy = jest.spyOn(documentService, 'patch')
const toastSpy = jest.spyOn(toastService, 'showError')
const error = new Error('failed to save')
- updateSpy.mockImplementation(() => throwError(() => error))
+ patchSpy.mockImplementation(() => throwError(() => error))
component.saveEditNext()
- expect(updateSpy).toHaveBeenCalled()
+ expect(patchSpy).toHaveBeenCalled()
expect(closeSpy).not.toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalledWith('Error saving document', error)
})
expect(fixture.debugElement.nativeElement.textContent).toContain(
customFields[1].name
)
- const updateSpy = jest.spyOn(documentService, 'update')
+ const patchSpy = jest.spyOn(documentService, 'patch')
component.save(true)
- expect(updateSpy.mock.lastCall[0].custom_fields).toHaveLength(2)
- expect(updateSpy.mock.lastCall[0].custom_fields[1]).toEqual({
+ expect(patchSpy.mock.lastCall[0].custom_fields).toHaveLength(2)
+ expect(patchSpy.mock.lastCall[0].custom_fields[1]).toEqual({
field: customFields[1].id,
value: null,
})
expect(
fixture.debugElement.query(By.css('form')).nativeElement.textContent
).not.toContain('Field 1')
- const updateSpy = jest.spyOn(documentService, 'update')
+ const patchSpy = jest.spyOn(documentService, 'patch')
component.save(true)
- expect(updateSpy.mock.lastCall[0].custom_fields).toHaveLength(
+ expect(patchSpy.mock.lastCall[0].custom_fields).toHaveLength(
initialLength - 1
)
})
this.title = doc.title
this.updateFormForCustomFields()
this.documentForm.patchValue(doc)
+ this.documentForm.markAsPristine()
this.openDocumentService.setDirty(doc, false)
},
error: () => {
})
}
+ 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) => {
this.networkActive = true
this.store.next(this.documentForm.value)
this.documentsService
- .update(this.document)
+ .patch(this.getChangedFields())
.pipe(
switchMap((updateResult) => {
return this.documentListViewService
created: new Date(),
})
this.updateFormForCustomFields(true)
+ this.documentForm.get('custom_fields').markAsDirty()
+ this.documentForm.updateValueAndValidity()
}
public removeField(fieldInstance: CustomFieldInstance) {
1
)
this.updateFormForCustomFields(true)
+ this.documentForm.get('custom_fields').markAsDirty()
this.documentForm.updateValueAndValidity()
}