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
|
||||
this.documentsService
|
||||
.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({
|
||||
next: (result) => {
|
||||
if (wasSelected && result?.current_version_id) {
|
||||
this.selectVersion(result.current_version_id)
|
||||
next: ({ doc, result }) => {
|
||||
if (doc?.versions) {
|
||||
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) => {
|
||||
this.toastService.showError($localize`Error deleting version`, error)
|
||||
|
||||
@@ -197,13 +197,20 @@ export class DocumentService extends AbstractPaperlessService<Document> {
|
||||
if (label) {
|
||||
formData.append('label', label)
|
||||
}
|
||||
return this.http.post(
|
||||
return this.http.post<string>(
|
||||
this.getResourceUrl(documentId, 'update_version'),
|
||||
formData,
|
||||
{ reportProgress: true, observe: 'events' }
|
||||
formData
|
||||
)
|
||||
}
|
||||
|
||||
getVersions(documentId: number): Observable<Document> {
|
||||
return this.http.get<Document>(this.getResourceUrl(documentId), {
|
||||
params: {
|
||||
fields: 'id,versions',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
deleteVersion(headDocumentId: number, versionId: number) {
|
||||
return this.http.delete<{ result: string; current_version_id: number }>(
|
||||
this.getResourceUrl(headDocumentId, `versions/${versionId}`)
|
||||
|
||||
Reference in New Issue
Block a user