Warn on closing edited doc due to max open docs

This commit is contained in:
Michael Shamoon
2022-05-15 22:55:25 -07:00
parent 0ddb073e9b
commit dc75035bdc
9 changed files with 79 additions and 20 deletions

View File

@@ -55,14 +55,24 @@ export class OpenDocumentsService {
return this.openDocuments.find((d) => d.id == id)
}
openDocument(doc: PaperlessDocument) {
openDocument(doc: PaperlessDocument): Observable<boolean> {
if (this.openDocuments.find((d) => d.id == doc.id) == null) {
this.openDocuments.unshift(doc)
if (this.openDocuments.length > this.MAX_OPEN_DOCUMENTS) {
this.openDocuments.pop()
if (this.openDocuments.length == this.MAX_OPEN_DOCUMENTS) {
const docToRemove = this.openDocuments[this.MAX_OPEN_DOCUMENTS - 1]
const closeObservable = this.closeDocument(docToRemove)
closeObservable.pipe(first()).subscribe((closed) => {
if (closed) {
this.openDocuments.unshift(doc)
this.save()
}
})
return closeObservable
} else {
this.openDocuments.unshift(doc)
this.save()
}
this.save()
}
return of(true)
}
setDirty(documentId: number, dirty: boolean) {
@@ -82,7 +92,11 @@ export class OpenDocumentsService {
backdrop: 'static',
})
modal.componentInstance.title = $localize`Unsaved Changes`
modal.componentInstance.messageBold = $localize`You have unsaved changes.`
modal.componentInstance.messageBold =
$localize`You have unsaved changes to the document` +
' "' +
doc.title +
'"'
modal.componentInstance.message = $localize`Are you sure you want to close this document?`
modal.componentInstance.btnClass = 'btn-warning'
modal.componentInstance.btnCaption = $localize`Close document`