mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-11 23:59:31 -06:00
Refresh versions after delete
This commit is contained in:
@@ -777,13 +777,35 @@ export class DocumentDetailComponent
|
|||||||
const wasSelected = this.selectedVersionId === versionId
|
const wasSelected = this.selectedVersionId === versionId
|
||||||
this.documentsService
|
this.documentsService
|
||||||
.deleteVersion(this.documentId, versionId)
|
.deleteVersion(this.documentId, versionId)
|
||||||
.pipe(first(), takeUntil(this.unsubscribeNotifier))
|
.pipe(
|
||||||
|
switchMap((result) =>
|
||||||
|
this.documentsService
|
||||||
|
.getVersions(this.documentId)
|
||||||
|
.pipe(map((doc) => ({ doc, result })))
|
||||||
|
),
|
||||||
|
first(),
|
||||||
|
takeUntil(this.unsubscribeNotifier)
|
||||||
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (result) => {
|
next: ({ doc, result }) => {
|
||||||
if (wasSelected && result?.current_version_id) {
|
if (doc?.versions) {
|
||||||
this.selectVersion(result.current_version_id)
|
this.document.versions = doc.versions
|
||||||
|
const openDoc = this.openDocumentService.getOpenDocument(
|
||||||
|
this.documentId
|
||||||
|
)
|
||||||
|
if (openDoc) {
|
||||||
|
openDoc.versions = doc.versions
|
||||||
|
this.openDocumentService.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasSelected) {
|
||||||
|
const fallbackId =
|
||||||
|
result?.current_version_id ??
|
||||||
|
doc?.versions?.[0]?.id ??
|
||||||
|
this.documentId
|
||||||
|
this.selectVersion(fallbackId)
|
||||||
}
|
}
|
||||||
this.openDocumentService.refreshDocument(this.documentId)
|
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.toastService.showError($localize`Error deleting version`, error)
|
this.toastService.showError($localize`Error deleting version`, error)
|
||||||
|
|||||||
@@ -197,13 +197,20 @@ export class DocumentService extends AbstractPaperlessService<Document> {
|
|||||||
if (label) {
|
if (label) {
|
||||||
formData.append('label', label)
|
formData.append('label', label)
|
||||||
}
|
}
|
||||||
return this.http.post(
|
return this.http.post<string>(
|
||||||
this.getResourceUrl(documentId, 'update_version'),
|
this.getResourceUrl(documentId, 'update_version'),
|
||||||
formData,
|
formData
|
||||||
{ reportProgress: true, observe: 'events' }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getVersions(documentId: number): Observable<Document> {
|
||||||
|
return this.http.get<Document>(this.getResourceUrl(documentId), {
|
||||||
|
params: {
|
||||||
|
fields: 'id,versions',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
deleteVersion(headDocumentId: number, versionId: number) {
|
deleteVersion(headDocumentId: number, versionId: number) {
|
||||||
return this.http.delete<{ result: string; current_version_id: number }>(
|
return this.http.delete<{ result: string; current_version_id: number }>(
|
||||||
this.getResourceUrl(headDocumentId, `versions/${versionId}`)
|
this.getResourceUrl(headDocumentId, `versions/${versionId}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user